Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 Null values

Author  Topic 

brlele
Starting Member

3 Posts

Posted - 2004-01-19 : 05:59:15
Hi All . I had a strange experience with composite primary key in table . In that I found if Type of the column is set to char then , it allows null values while updation; but it dosent alow it in case of inserts.I opened the data window in Enterprise manager where I discovered this . I am using sql7.0 Please comment

nr
SQLTeam MVY

12543 Posts

Posted - 2004-01-19 : 06:25:00
Are you sure? A PK can't be placed on a column which allows null.

create table #a(s char(10) not null, t char(10) null)
alter table #a add primary key (s,t)
-- gives error

drop table #a
create table #a(s char(10) not null, t char(10) not null)
alter table #a add primary key (s,t)

insert #a select 'qwe', 'qwe'
update #a set t = null
--error

create table #a(s char(10) not null, t char(10) not null)
alter table #a add primary key (s,t)
alter table #a alter column t char(10) null
--error


Check the structure of the table. Does the column allow nulls. Does it have a primary key rather than a unique index? Try sp_help to look at the table
A column which allows nulls should give an error when you try to add the PK.

If you still think there is a problem then post the rable structure and an example of updating the column to null.

==========================================
Cursors are useful if you don't know sql.
DTS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page

brlele
Starting Member

3 Posts

Posted - 2004-01-19 : 06:50:16
Hi nr
Try this out.
Create a table with some columns , a few of them with char as data type.
Choose any two columns and create a composite primary key.
Now add one record with all values filled up.
Then make one of the fields that make composite PK blank for the above newly added record. (Try for either of the fields).All this done through the Enterprise management console.
Please let me know what you get to see.
Go to Top of Page

nr
SQLTeam MVY

12543 Posts

Posted - 2004-01-19 : 07:23:31
Blank is not the same as null.
Blank is an empty string which is allowed in a PK, null is not.

==========================================
Cursors are useful if you don't know sql.
DTS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page
   

- Advertisement -