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

Our new SQL Server Forums are live! Come on over! We've restricted the ability to create new threads on these forums.

SQL Server Forums
Profile | Active Topics | Members | Search | Forum FAQ
Register Now and get your question answered!
Save Password
Forgot your Password?

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 making a column nullable using a constraint
 Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Posting Yak Master

192 Posts

Posted - 02/28/2007 :  17:37:09  Show Profile  Reply with Quote
My table is


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

Flowing Fount of Yak Knowledge

1837 Posts

Posted - 02/28/2007 :  17:49:08  Show Profile  Reply with Quote
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

Starting Member

20 Posts

Posted - 05/20/2014 :  01:52:49  Show Profile  Reply with Quote
below url would shed some light on how to resolve this error
Go to Top of Page
  Previous Topic Topic Next Topic  
 Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.06 seconds. Powered By: Snitz Forums 2000