t***@gmail.com
2007-03-30 22:21:08 UTC
Hi all,
This is what happened last week -
I tried to intentionally insert into a table with null values like
this
INSERT INTO Table1(ID, username) VALUES(xxx, '' )
while "username is the PK", ID is just a number with identity, and
both ID and username do not allow nulls.
Immediately I received an error message which is expected, but weird
things happened when I did this -
1. I inserted something dummy first in Table1
INSERT INTO Table1(ID, username) VALUES(xxx, yyy)
2. I tried to update Table1 with '' (two single quotes right next to
each other without spaces inside)
UPDATE Table1 set username='' where ID=xxx
3. retrieve this record by ID
SELECT * FROM Table1 WHERE ID=xxx
Something that doesn't make sense to me is that I can retrieve this
record and found this row with a blank PK. It doesn't show the NULL on
the username, but it does not store two single quote in the column
either. What's more surprising to me is that my SQL Server 2000
allowed me to do this update. I already set up "not allow nulls"
attributes for this table. Besides, the username column is the PK for
Table1. How can we update a record to null PK in the table?
The only one possible answer is the two nearby single-quote thing ''
means something in the system and therefore does not equal to the
NULL, but I am not quite sure since I've never found this when I used
Oracle (I'm more familiar with PL/SQL)
Anyone has ideas about why it's allowed is highly appreciated.
-Tanya
This is what happened last week -
I tried to intentionally insert into a table with null values like
this
INSERT INTO Table1(ID, username) VALUES(xxx, '' )
while "username is the PK", ID is just a number with identity, and
both ID and username do not allow nulls.
Immediately I received an error message which is expected, but weird
things happened when I did this -
1. I inserted something dummy first in Table1
INSERT INTO Table1(ID, username) VALUES(xxx, yyy)
2. I tried to update Table1 with '' (two single quotes right next to
each other without spaces inside)
UPDATE Table1 set username='' where ID=xxx
3. retrieve this record by ID
SELECT * FROM Table1 WHERE ID=xxx
Something that doesn't make sense to me is that I can retrieve this
record and found this row with a blank PK. It doesn't show the NULL on
the username, but it does not store two single quote in the column
either. What's more surprising to me is that my SQL Server 2000
allowed me to do this update. I already set up "not allow nulls"
attributes for this table. Besides, the username column is the PK for
Table1. How can we update a record to null PK in the table?
The only one possible answer is the two nearby single-quote thing ''
means something in the system and therefore does not equal to the
NULL, but I am not quite sure since I've never found this when I used
Oracle (I'm more familiar with PL/SQL)
Anyone has ideas about why it's allowed is highly appreciated.
-Tanya