Re: CHECK constraint on multiple tables
| От | Tom Lane | 
|---|---|
| Тема | Re: CHECK constraint on multiple tables | 
| Дата | |
| Msg-id | 15921.1252937895@sss.pgh.pa.us обсуждение исходный текст | 
| Ответ на | CHECK constraint on multiple tables (Mario Splivalo <mario.splivalo@megafon.hr>) | 
| Ответы | Re: CHECK constraint on multiple tables | 
| Список | pgsql-sql | 
Mario Splivalo <mario.splivalo@megafon.hr> writes:
> I have two tables, tableA and tableB:
> CREATE TABLE tableA (idA integer primary key, email character varying
> unique);
> CREATE TABLE tableB (idB integer primary key, email character varying
> unique);
> Now, I want to create check constraint in both tables that would
> disallow records to either table where email is 'mentioned' in other table.
Have you considered refactoring so there's only one table?
Cross-table constraints are a really bad idea unless you can express
them as foreign keys.  There's a lot of "secret sauce" in the FK
mechanism that isn't available to user-written constraints.
        regards, tom lane
		
	В списке pgsql-sql по дате отправления: