Re: Alter table column constraint

Поиск
Список
Период
Сортировка
Искать
От
Adrian Klaver
Тема
Re: Alter table column constraint
Дата
Msg-id
5dc1d1d7-9d60-4a51-d99d-168a0dd479e7@aklaver.com
Ответ на
Список
Дерево обсуждения
Alter table column constraint Rich Shepard <rshepard@appl-ecosys.com>
Re: Alter table column constraint Rich Shepard <rshepard@appl-ecosys.com>
Re: Alter table column constraint "Joshua D. Drake" <jd@commandprompt.com>
Re: Alter table column constraint Melvin Davidson <melvin6925@gmail.com>
Re: Alter table column constraint Rich Shepard <rshepard@appl-ecosys.com>
Re: Alter table column constraint Adrian Klaver <adrian.klaver@aklaver.com>
Re: Alter table column constraint "David G. Johnston" <david.g.johnston@gmail.com>
Re: Alter table column constraint Melvin Davidson <melvin6925@gmail.com>
Re: Alter table column constraint Melvin Davidson <melvin6925@gmail.com>
Re: Alter table column constraint Ron <ronljohnsonjr@gmail.com>
Re: Alter table column constraint [RESOLVED] Rich Shepard <rshepard@appl-ecosys.com>
On 12/17/18 12:20 PM, Rich Shepard wrote:
> On Mon, 17 Dec 2018, Melvin Davidson wrote:
> 
>> Yes, you must drop then add the revised constraint. However, from your
>> statement above, it sounds to me as if you would be better off using A
>> FOREIGN kEY CONSTRAINT. It makes things a lot simpler.
> 
> Melvin,
> 
>    I don't follow. Here's the DDL for that column:
> 
> industry varchar(24) NOT NULL
>      CONSTRAINT invalid_industry
>      CHECK (industry in ('Agriculture', 'Business, other', 'Chemicals',
>      'Energy', 'Law', 'Manufacturing', 'Mining', 'Municipalities',
>      'Ports/Marine Services', 'Transportation')),
> 
> and I want to remove Municipalities for the more general Government.

What Melvin suggested was to:

1) Move this ('Agriculture', 'Business, other', 'Chemicals', ..)
into its own table say something like:

CREATE TABLE industry(industry_code varchar PRIMARY KEY, industry_desc 
varchar)

2) Change the industry field in your existing table to:

industry varchar(24) NOT NULL REFERENCES industry(industry_code) ON 
UPDATE CASCADE.

Where this helps is that in the situation you describe in your original 
post you just change 'Municipalities' to 'Government' in the industry 
table and the referring table automatically gets the change via the ON 
UPDATE CASCADE.

> 
> Regards,
> 
> Rich
> 


-- 
Adrian Klaver
adrian.klaver@aklaver.com

В списке pgsql-general по дате отправления
От: Melvin Davidson
Дата:
От: David Rowley
Дата:
FAQ