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)
 making a column nullable using a constraint

Author  Topic 

heze
Posting Yak Master

192 Posts

Posted - 2007-02-28 : 17:37:09
Hi
My table is

myTable(year,Id,gender)

I want to add a primary key using
alter table myTable
add constraint hz_Constraint
primary key (year,Id)

But i receive the folowing from SQL Server:
-------------------------
Server: Msg 8111, Level 16, State 1, Line 1
Cannot define PRIMARY KEY constraint on nullable column in table 'CB1'.
Server: Msg 1750, Level 16, State 1, Line 1
Could not create constraint. See previous errors.
-------------------------

So I then try the folloiwng succesfully:
alter table myTable
add constraint hz_erase2
check (not pidm is null)

alter table myTable
add constraint hz_erase1
check (not Term is null)

But this dod not change the actual property;
my question is:
How do you change the nullable property to not nullable in the year,Id fields?

Thank you

snSQL
Master Smack Fu Yak Hacker

1837 Posts

Posted - 2007-02-28 : 17:49:08
Use ALTER COLUMN with ALTER TABLE, nullability is not a constraint, its a property of the column. The data type is required even though you won't be changing it, just make it whatever it is now, I used int in this example. You'll need two separate ALTER TABLE statements.
alter table myTable
alter column year int not null
alter table myTable
alter column Id int not null


Go to Top of Page

adsingh82
Starting Member

20 Posts

Posted - 2014-05-20 : 01:52:49
below url would shed some light on how to resolve this error

[url]http://dotnetbites.com/cannot-define-primary-key-constraint-on-nullable-column-in-table[/url]
Go to Top of Page
   

- Advertisement -