checking data integrity in a recursive table
| От | Luke Pascoe |
|---|---|
| Тема | checking data integrity in a recursive table |
| Дата | |
| Msg-id | 019801c2c31c$c8d63fa0$3200000a@K2 обсуждение исходный текст |
| Ответы |
Re: checking data integrity in a recursive table
|
| Список | pgsql-sql |
Hi, I have a table that references itself to create a tree-like structure, eg: CREATE TABLE tree ( id SERIAL NOT NULL, name VARCHAR(255) NOT NULL, parent INT NULL, customer IN NOT NULL, CONSTRAINT parent_key... CONSTRAINT customer_fk FOREIGN KEY (customer) REFERENCES customer ); ALTER TABLE tree ADD CONSTRAINT FOREIGN KEY (parent) REFERENCES tree; As you can see tree also references the customer table. What I need is a CHECK that will ensuer that any given "tree" row has the same customer as its parent. Remember that "parent" can also be NULL. Or would this be better done as a trigger? TIA! ======================================== Luke Pascoe KMG (NZ) Limited. http://www.kmg.co.nz Mobile: (021) 303019 Email: luke.p@kmg.co.nz ========================================
В списке pgsql-sql по дате отправления: