Re: Referential Integrity and Indexes
- From: Tim Ferguson <FergusonTG@xxxxxxxxxxxx>
- Date: Wed, 27 Jul 2005 12:06:49 -0700
peregenem@xxxxxxxxxxxx wrote in news:1122456543.559916.44550
@g14g2000cwa.googlegroups.com:
>> SELECT AField IS NULL FROM Something WHERE AKey = 1
>>
>> returns true regardless of what you try to do.
>
> For the latter I get an error, "Incorrect syntax near the
> keyword 'IS'".
>
>
Okay... I have re-researched this and I was wrong anyway. Here is an
actual example:
1> update bases set fullname=null where baseid=9
2> select baseid, isnull(fullname,'empty') as result
3> from bases
4> where baseid=9
5> go
(1 row affected)
baseid result
----------- --------------------------------------------------
9 empty
(1 row affected)
1> update bases set fullname='' where baseid=9
2> select baseid, isnull(fullname,'empty') as result
3> from bases
4> where baseid=9
5> go
(1 row affected)
baseid result
----------- --------------------------------------------------
9
(1 row affected)
.... so SQL Server seems quite happy to store zero length strings
distinctly from nulls. This is what one would expect although whenever I
tried it before I thought it failed. It is also true that the software
gets in the way -- in Access you have to try very hard to put a zero
length string in a text box.
Still, going back to the OPs original request for DDL equivalent to
"Allow Zero Length Strings" then, as seen above, it's on by default. In
order to refuse zero length strings he'd have to add a check constraint
like
1> alter table bases
2> add constraint NoNullNames
3> check (len(fullname)>0)
4> go
1> insert bases(fullname) values('')
2> go
Msg 547, Level 16, State 1, Server RUBENS, Procedure , Line 1
[Microsoft][ODBC SQL Server Driver][SQL Server]INSERT statement
conflicted with
COLUMN CHECK constraint 'NoNullNames'. The conflict occurred in database
'NewTestSQL', table 'Bases', column 'FullName'.
The statement has been terminated.
I think that's got it sorted out.
Tim F
.
- Follow-Ups:
- Re: Referential Integrity and Indexes
- From: peregenem
- Re: Referential Integrity and Indexes
- References:
- Referential Integrity and Indexes
- From: Jonathan Scott via AccessMonster.com
- Re: Referential Integrity and Indexes
- From: Tim Ferguson
- Re: Referential Integrity and Indexes
- From: Jonathan Scott via AccessMonster.com
- Re: Referential Integrity and Indexes
- From: Tim Ferguson
- Re: Referential Integrity and Indexes
- From: peregenem
- Referential Integrity and Indexes
- Prev by Date: RE: How do I create a pivot table ???
- Next by Date: Re: DATA TYPE ERROR PLEASE HELP
- Previous by thread: Re: Referential Integrity and Indexes
- Next by thread: Re: Referential Integrity and Indexes
- Index(es):
Relevant Pages
|