October 16, 2011 at 7:08 am
Thanks, good question.
M&M
October 17, 2011 at 12:02 am
Cool!!!
October 17, 2011 at 1:45 am
Thanks, a very good question!
October 17, 2011 at 1:49 am
Very good question
I shouldn't try to think this early!
Tom
October 17, 2011 at 2:51 am
Thought this was straightforward but sadly not
Surprised that the NULL was not caught in the check constraint...
More coffee required.
---
Note to developers:Want to get the best help? Click here https://www.sqlservercentral.com/articles/forum-etiquette-how-to-post-datacode-on-a-forum-to-get-the-best-help (Jeff Moden)
My blog: http://uksqldba.blogspot.com
Visit http://www.DerekColley.co.uk to find out more about me.
October 17, 2011 at 3:31 am
Had already had first coffee before attempting to answer this. 😀
Good question, thanks
October 17, 2011 at 4:36 am
good and easy question!!!
thanks!
October 17, 2011 at 5:44 am
Thanks for the question. I was pretty sure the check constraint would allow the NULL value.
http://brittcluff.blogspot.com/
October 17, 2011 at 5:48 am
From http://msdn.microsoft.com/en-us/library/ms188258.aspx:
CHECK constraints reject values that evaluate to FALSE. Because null values evaluate to UNKNOWN, their presence in expressions may override a constraint. For example, suppose you place a constraint on an int column MyColumn specifying that MyColumn can contain only the value 10 (MyColumn = 10). If you insert the value NULL into MyColumn, the Database Engine inserts NULL and does not return an error.
October 17, 2011 at 6:03 am
Good and easy Question !!!
Thx
Thanks
Vinay Kumar
-----------------------------------------------------------------
Keep Learning - Keep Growing !!!
October 17, 2011 at 6:30 am
Great question. I got it right, but only because I have encountered this behavior before, and committed it to memory.
Thanks,
Matt
October 17, 2011 at 6:55 am
Thanks for a good question. I got it right, but I thought that perhaps only one such NULL INSERT would be allowed. After reading the BOL entry and trying it out, I see that you can INSERT many such rows.
Odd behavior, at least to me, as it seems the "correct" interpretation of this should be "only permit the INSERT if the constraint condition evaluates to TRUE."
Anyone here know if this is an ANSI-compliant implementation? Is this how constraints work in MySQL, Oracle, DB2? Just curious....
Learned something new and got my point!
Rich
October 17, 2011 at 7:07 am
I guess the answer is wrong
It should be 1 and 2 only
beacuse only the constraint is violated,
the sql statement is terminated.
it doesn't look for other statements...
just goes out of loop.
Just wat i think this, bcoz i encountered this before..
Regards,
Sushant
Regards
Sushant Kumar
October 17, 2011 at 7:20 am
rmechaber (10/17/2011)
Odd behavior, at least to me, as it seems the "correct" interpretation of this should be "only permit the INSERT if the constraint condition evaluates to TRUE."Anyone here know if this is an ANSI-compliant implementation? Is this how constraints work in MySQL, Oracle, DB2? Just curious....
Learned something new and got my point!
Rich
It seems that Oracle, at least, works the same way. From http://download.oracle.com/docs/cd/B19306_01/server.102/b14200/clauses002.htm: (bold added)
A check constraint lets you specify a condition that each row in the table must satisfy. To satisfy the constraint, each row in the table must make the condition either TRUE or unknown (due to a null). When Oracle evaluates a check constraint condition for a particular row, any column names in the condition refer to the column values in that row.
October 17, 2011 at 7:24 am
Good question and actually makes sense if you think about it. The check constraint is checking for values. From BOL
CHECK constraints enforce domain integrity by limiting the values that are accepted by a column.
The logic here is that the check constraint is flexible enough to allow for nulls (which the column does allow). All the check constraint evaluates is that IF there is a value it should comply to the rules established in the check constraint.
_______________________________________________________________
Need help? Help us help you.
Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.
Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.
Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/
Viewing 15 posts - 1 through 15 (of 32 total)
You must be logged in to reply to this topic. Login to reply