SQL Anywhere 12 CHECK constraint on column1 to not allow nulls on specific other columns
Newbie to SQL Anywhere
Table can multilple row types. How do I set a CHECK c开发者_StackOverflow社区onstraint for some columns to not be null based on value of row type column?
SQL Anywhere is strongly typed and I'm not sure it's generally a good idea to have typeless columns in your schema.
If you must you can create a pseudo-typeless column with a varchar
datatype, and add a constraint that will test the string input, like so:
ALTER TABLE "DBA"."myTable" ADD "myColumn " VARCHAR(100) NULL;
ALTER TABLE "DBA"."myTable" ADD CONSTRAINT "myConstraint"
check(
( ISNUMERIC( myColumn ) AND myColumn is not null )
OR ( ISDATE( myColumn ) AND myColumn is not null )
OR (...)
);
BTW, you may wish to ask the question at http://sqla.stackexchange.com/.
精彩评论