Hello everyone,
I have a small difficulty writing a constraint, for example if I had a row series and it had to be between s00 and s99, how do I do it? I use SQL developer. Thanks a lot!!!
Check constraint
Page 1 of 11 Replies - 369 Views - Last Post: 29 November 2011 - 08:03 AM
Topic Sponsor:
Replies To: Check constraint
#2
Re: Check constraint
Posted 29 November 2011 - 08:03 AM
I take it you are using Oracle then?
What exactly does the "s" in those values stand for? It's quite a bit easier to validate a number than it is to validate the format of a string. Especially when you don't just have to validate the string format, but also extract and validate a part of the string as a separate value.
I would suggested you remove the "s" and save the value as a number. Then you could restrict it using a very simple CHECK constraint.
If you need the value to read "sNN" on the way out, you can compile that string in your SQL queries using the number value stored in the table.
Check out "Check Constraints" in the page about constraints in the manual.
http://docs.oracle.c....htm#SQLRF52180
What exactly does the "s" in those values stand for? It's quite a bit easier to validate a number than it is to validate the format of a string. Especially when you don't just have to validate the string format, but also extract and validate a part of the string as a separate value.
I would suggested you remove the "s" and save the value as a number. Then you could restrict it using a very simple CHECK constraint.
CREATE TABLE example ( some_id NUMBER PRIMARY KEY, the_column NUMBER NOT NULL CONSTRAINT check_the_column CHECK (the_column BETWEEN 0 AND 99) );
If you need the value to read "sNN" on the way out, you can compile that string in your SQL queries using the number value stored in the table.
SELECT some_id, 's' || LPAD(the_column, 2, '0') FROM example;
Check out "Check Constraints" in the page about constraints in the manual.
http://docs.oracle.c....htm#SQLRF52180
Page 1 of 1
|
|

New Topic/Question
Reply



MultiQuote




|