Subject | Check constraint self referencing table name |
---|---|
Author | firebirdsql |
Post date | 2011-09-23T00:05:21Z |
I have the following check constraint for table1:
EXISTS
(
SELECT * FROM table1 AS a WHERE a.type = type;
);
The problem with this is that the right side of the assignment operator, type, refers to a.type instead of the new record's type. Sometimes it refers to the record's type, sometimes it refers to a.type and it depends on the table.
To fix it, I have to do WHERE a.type = table1.type.
Is there a better way? (this is just an example btw)
EXISTS
(
SELECT * FROM table1 AS a WHERE a.type = type;
);
The problem with this is that the right side of the assignment operator, type, refers to a.type instead of the new record's type. Sometimes it refers to the record's type, sometimes it refers to a.type and it depends on the table.
To fix it, I have to do WHERE a.type = table1.type.
Is there a better way? (this is just an example btw)