468,505 Members | 1,545 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,505 developers. It's quick & easy.

MSSQL: ALTER TABLE in PROCEDURE

temat
5
Hi i got a problem when i try to Alter Table in the procedure. I have red that i need to place keyword IMMIDIATE but it dont work in mssql.

I need thede procedure to drop FOREIGN KEY, TRUNCATE and add FOREIGN KEY
[PHP]
-- PUBLISHERS
ALTER PROCEDURE clearPublishers
AS
BEGIN TRANSACTION
ALTER TABLE dbo.Books
DROP CONSTRAINT FK_Publishers_Books

TRUNCATE TABLE dbo.Publishers

ALTER TABLE dbo.Books
ADD CONSTRAINT FK_Publishers_Books
FOREIGN KEY (pId)
REFERENCES dbo.Publishers (pId)
ON UPDATE CASCADE
COMMIT TRANSACTION
GO
[/PHP]

I got an Error :
[PHP]
Server: Msg 547, Level 16, State 1, Line 1
ALTER TABLE statement conflicted with COLUMN FOREIGN KEY constraint 'FK_Publishers_Books'. The conflict occurred in database '20.4.2007', table 'Publishers', column 'pId'.
[/PHP]

PLEASE HELP.
Apr 21 '07 #1
0 3427

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

3 posts views Thread by M Simpson | last post: by
2 posts views Thread by me | last post: by
5 posts views Thread by Bradley.. .. . . .. .. | last post: by
2 posts views Thread by tojigneshshah | last post: by
7 posts views Thread by Serge Rielau | last post: by
3 posts views Thread by Shawn Beasley | last post: by
reply views Thread by Gosth in the shell | last post: by
3 posts views Thread by gieforce | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.