p***@gmail.com
2007-08-07 07:47:37 UTC
Hi!
I have a table (called TEST) which is a dictionary
NAME (VARCHAR) - VALUE (VARCHAR)
VALUE can be in practice of any type stored as a VARCHAR (I know it's not elegant but it's a kind of a DB equivalent of a system.properties file so I need to keep different types).
For NAME = 'A' VALUE is an SMALLINT.
And here's my problem:
When NAME='B', I want VALUE to be always greater than the VALUE for 'A'.
I tried creating such a constraint:
alter table TEST add constraint TEST_CK
check ( NAME <> 'B' OR (NAME = 'B' AND SMALLINT(VALUE) > (SELECT SMALLINT(VALUE) FROM TEST WHERE NAME='A')) );
but it turns out I cannot have subqueries inside constraints.
How to solve this?
Best regards,
Peter
I have a table (called TEST) which is a dictionary
NAME (VARCHAR) - VALUE (VARCHAR)
VALUE can be in practice of any type stored as a VARCHAR (I know it's not elegant but it's a kind of a DB equivalent of a system.properties file so I need to keep different types).
For NAME = 'A' VALUE is an SMALLINT.
And here's my problem:
When NAME='B', I want VALUE to be always greater than the VALUE for 'A'.
I tried creating such a constraint:
alter table TEST add constraint TEST_CK
check ( NAME <> 'B' OR (NAME = 'B' AND SMALLINT(VALUE) > (SELECT SMALLINT(VALUE) FROM TEST WHERE NAME='A')) );
but it turns out I cannot have subqueries inside constraints.
How to solve this?
Best regards,
Peter