Wrox Home  
Search P2P Archive for: Go

  Return to Index  

sql_language thread: primary key / not null


Message #1 by "Bab Tools" <babtools@h...> on Thu, 26 Sep 2002 20:53:31
Hi,

You can't run both statements together like that (as you have found out).
You need to place the GO keyword between the statements. This ensures the 
first statement has finished executing before the second one begins. Like 
so:

ALTER TABLE Coaches ALTER COLUMN CoachID INT NOT NULL
GO
ALTER TABLE Coaches ADD CONSTRAINT con_CoachIDPK PRIMARY KEY (CoachID)

I'm sure if you try this it will work. Now as to why the other one worked 
without the GO keyword I don't really know, maybe it's due to the data 
types of each column you're making a primary key, one is INT and the 
other is CHAR. This is just a guess, I'm sure others on here will know 
the answer.

Mike

  Return to Index