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.
Author |
Topic |
heze
Posting Yak Master
192 Posts |
Posted - 2007-02-28 : 17:37:09
|
Hi My table ismyTable(year,Id,gender)I want to add a primary key usingalter table myTableadd constraint hz_Constraintprimary key (year,Id)But i receive the folowing from SQL Server:-------------------------Server: Msg 8111, Level 16, State 1, Line 1Cannot define PRIMARY KEY constraint on nullable column in table 'CB1'.Server: Msg 1750, Level 16, State 1, Line 1Could not create constraint. See previous errors.-------------------------So I then try the folloiwng succesfully:alter table myTableadd constraint hz_erase2check (not pidm is null)alter table myTableadd constraint hz_erase1check (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 myTablealter column year int not nullalter table myTablealter column Id int not null |
|
|
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] |
|
|
|
|
|
|
|