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 |
|
Dev Null
Starting Member
39 Posts |
Posted - 2005-05-17 : 21:56:38
|
I have to write a stored procedure which, among other things, creates a primary key constraint on a table.I know; thats weird. (If you care, its because the table schema is built - and occasionally re-built - by an external application which I can't control.)I can create my primary key with the statements:ALTER TABLE AVAILABILITY ALTER COLUMN TIMESTAMP DATETIME NOT NULLGOALTER TABLE AVAILABILITY ADD CONSTRAINT AVAILABILITY_PK PRIMARY KEY CLUSTERED ( TIMESTAMP )GO but if I drop that into a stored procedure, I have to remove the "GO"s, and the add constraint line then complains that it can't create a primary key on a nullable column; presumably because the addition of the NOT NULL constraint hasn't yet taken effect. Is there a way to force it to? I've tried variations on using EXEC and transactions, but to no avail...Thanks for any advice, - rob. |
|
|
mr_mist
Grunnio
1870 Posts |
Posted - 2005-05-18 : 05:30:08
|
| You'd need to do the ALTERs in seperate procedures and execute them serially from another procedure.-------Moo. :) |
 |
|
|
nr
SQLTeam MVY
12543 Posts |
|
|
|
|
|