dbTalk Databases Forums  

SSE 2008: Check Clause Question

comp.databases.ms-sqlserver comp.databases.ms-sqlserver


Discuss SSE 2008: Check Clause Question in the comp.databases.ms-sqlserver forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Gene Wirchenko
 
Posts: n/a

Default SSE 2008: Check Clause Question - 07-12-2011 , 03:12 PM






Dear SQL'ers:

Is there any way around the SQL glitch that a check condition
will always succeed when the table is empty?

I do not want to have the first row be automatically accepted.

Sincerely,

Gene Wirchenko

Reply With Quote
  #2  
Old   
Erland Sommarskog
 
Posts: n/a

Default Re: SSE 2008: Check Clause Question - 07-12-2011 , 04:56 PM






Gene Wirchenko (genew (AT) ocis (DOT) net) writes:
Quote:
Is there any way around the SQL glitch that a check condition
will always succeed when the table is empty?

I do not want to have the first row be automatically accepted.
Not sure what you mean. If the table is empty, there is nothing to enforce.
That does not mean if you add a row, that anything will be accepted.

Could you clarify?

--
Erland Sommarskog, SQL Server MVP, esquel (AT) sommarskog (DOT) se

Links for SQL Server Books Online:
SQL 2008: http://msdn.microsoft.com/en-us/sqlserver/cc514207.aspx
SQL 2005: http://msdn.microsoft.com/en-us/sqlserver/bb895970.aspx

Reply With Quote
  #3  
Old   
Gene Wirchenko
 
Posts: n/a

Default Re: SSE 2008: Check Clause Question - 07-12-2011 , 05:47 PM



On Tue, 12 Jul 2011 23:56:34 +0200, Erland Sommarskog
<esquel (AT) sommarskog (DOT) se> wrote:

Quote:
Gene Wirchenko (genew (AT) ocis (DOT) net) writes:
Is there any way around the SQL glitch that a check condition
will always succeed when the table is empty?

I do not want to have the first row be automatically accepted.

Not sure what you mean. If the table is empty, there is nothing to enforce.
That does not mean if you add a row, that anything will be accepted.

Could you clarify?
That is what I have read. There is even an example purporting to
show this
http://msdn.microsoft.com/en-us/library/ms188258.aspx
It appears to be a false alarm.

Sincerely,

Gene Wirchenko

Reply With Quote
  #4  
Old   
Erland Sommarskog
 
Posts: n/a

Default Re: SSE 2008: Check Clause Question - 07-13-2011 , 03:17 AM



Gene Wirchenko (genew (AT) ocis (DOT) net) writes:
Quote:
That is what I have read. There is even an example purporting to
show this
http://msdn.microsoft.com/en-us/library/ms188258.aspx
It appears to be a false alarm.
So it applies to that particular example, which I don't really like.
Particularly, I don't think it is a good idea to call UDFs from CHECK
constraints. I put all such checks in triggers.

--
Erland Sommarskog, SQL Server MVP, esquel (AT) sommarskog (DOT) se

Links for SQL Server Books Online:
SQL 2008: http://msdn.microsoft.com/en-us/sqlserver/cc514207.aspx
SQL 2005: http://msdn.microsoft.com/en-us/sqlserver/bb895970.aspx

Reply With Quote
  #5  
Old   
--CELKO--
 
Posts: n/a

Default Re: SSE 2008: Check Clause Question - 07-14-2011 , 09:06 AM



On Jul 12, 3:12*pm, Gene Wirchenko <ge... (AT) ocis (DOT) net> wrote:
Quote:
Dear SQL'ers:

* * *Is there any way around the SQL glitch that a check condition
will always succeed when the table is empty?

* * *I do not want to have the first row be automatically accepted.

Sincerely,

Gene Wirchenko

Reply With Quote
  #6  
Old   
--CELKO--
 
Posts: n/a

Default Re: SSE 2008: Check Clause Question - 07-14-2011 , 09:12 AM



On Jul 12, 3:12*pm, Gene Wirchenko <ge... (AT) ocis (DOT) net> wrote:
Quote:
Dear SQL'ers:

* * *Is there any way around the SQL glitch that a check condition
will always succeed when the table is empty?

* * *I do not want to have the first row be automatically accepted.

Sincerely,

Gene Wirchenko
Glitch? That is a law of logic; anything you say about non-existing
thigns is true. Look up "Existental import" in a text book on the
history of modern logic. And teh first row is not always accepted.

I have some situations with self-references to avoid gaps in the
dates of a history that I start with CHECK() constraints off, insert a
first row, turn teh DRI back on and proceed to insert as usual.

Reply With Quote
  #7  
Old   
Fred.
 
Posts: n/a

Default Re: SSE 2008: Check Clause Question - 07-14-2011 , 10:22 AM



On Jul 14, 10:12*am, --CELKO-- <jcelko... (AT) earthlink (DOT) net> wrote:
Quote:
On Jul 12, 3:12*pm, Gene Wirchenko <ge... (AT) ocis (DOT) net> wrote:

Dear SQL'ers:

* * *Is there any way around the SQL glitch that a check condition
will always succeed when the table is empty?

* * *I do not want to have the first row be automatically accepted.

Sincerely,

Gene Wirchenko

Glitch? That is a law of logic; anything you say about non-existing
thigns is true. Look up "Existental import" in a text book on the
history of modern logic. And teh first row is not always accepted.

*I have some situations with self-references to avoid gaps in the
dates of a history that I start with CHECK() constraints off, insert a
first row, turn teh DRI back on and proceed to insert as usual.
That is not quite accurate. In an empty universe all universally
quantified propositions are true. But, all existentially quantified
propositions are false.

The assetion thet the table t is not empty could be reporesnted as (Ex)
(x in t & x=x). However, constraints are always universally
quantified over the table. A constraint C(x) on the table t is
interpreted as (x) (If x in t then C(x)).

If we apply the non-empty assertion as a constraint it will be
interpreted as (y)(If y in t then (Ex)(x in t & x=x)), which is, of
course, true if the table is empty, even though the consequent we
thought we were testing, (Ex)(x in t & x=x) is false.

I believe that there is a glitch, but it is in the documentation which
fails to document the underlying logic of the SQL constructs, probably
on the conflicting grounds that it is (1) intuitively obvious, and (2)
confusing.

Fred.

Fred.

Reply With Quote
  #8  
Old   
Gene Wirchenko
 
Posts: n/a

Default Re: SSE 2008: Check Clause Question - 07-14-2011 , 05:26 PM



On Thu, 14 Jul 2011 07:12:12 -0700 (PDT), --CELKO--
<jcelko212 (AT) earthlink (DOT) net> wrote:

Quote:
On Jul 12, 3:12*pm, Gene Wirchenko <ge... (AT) ocis (DOT) net> wrote:
Dear SQL'ers:

* * *Is there any way around the SQL glitch that a check condition
will always succeed when the table is empty?

* * *I do not want to have the first row be automatically accepted.

Glitch? That is a law of logic; anything you say about non-existing
thigns is true. Look up "Existental import" in a text book on the
It would be a glitch if it turned out to be truth. A vacuous
truth is irrelevant.

Quote:
history of modern logic. And teh first row is not always accepted.
I have now read that it is in two places. Given the weirdnesses
and dysfunctionalities of SQL, it was not unbelieveable. I am glad it
is wrong.

Quote:
I have some situations with self-references to avoid gaps in the
dates of a history that I start with CHECK() constraints off, insert a
first row, turn teh DRI back on and proceed to insert as usual.
Please expand "DRI".

Sincerely,

Gene Wirchenko

Reply With Quote
  #9  
Old   
Erland Sommarskog
 
Posts: n/a

Default Re: SSE 2008: Check Clause Question - 07-15-2011 , 03:58 AM



Gene Wirchenko (genew (AT) ocis (DOT) net) writes:
Quote:
Please expand "DRI".
Declarative Referential Integrity. That is constraints: CHECK and FOREIGN
KEY constraints. And also PRIMARY KEY and UNIQUE constraints, although you
cannot turn them off in SQL Server.

In SQL Server DEFAULT is also termed as a constraint, but that is a bit
incorrect.

DRI should be seen in oppsition to RI checks implemented in triggrs.


--
Erland Sommarskog, SQL Server MVP, esquel (AT) sommarskog (DOT) se

Links for SQL Server Books Online:
SQL 2008: http://msdn.microsoft.com/en-us/sqlserver/cc514207.aspx
SQL 2005: http://msdn.microsoft.com/en-us/sqlserver/bb895970.aspx

Reply With Quote
  #10  
Old   
Gene Wirchenko
 
Posts: n/a

Default Re: SSE 2008: Check Clause Question - 07-15-2011 , 01:07 PM



On Fri, 15 Jul 2011 10:58:21 +0200, Erland Sommarskog
<esquel (AT) sommarskog (DOT) se> wrote:

Quote:
Gene Wirchenko (genew (AT) ocis (DOT) net) writes:
Please expand "DRI".

Declarative Referential Integrity. That is constraints: CHECK and FOREIGN
KEY constraints. And also PRIMARY KEY and UNIQUE constraints, although you
cannot turn them off in SQL Server.

In SQL Server DEFAULT is also termed as a constraint, but that is a bit
incorrect.

DRI should be seen in oppsition to RI checks implemented in triggrs.
Thank you for the well-written definition.

Sincerely,

Gene Wirchenko

Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.