我正在处理几个练习题,我遇到了这个问题,我在尝试执行程序时不断收到错误消息
消息 156,级别 15,状态 1,第 1 行
关键字“程序”附近的语法不正确。”
有人可以帮忙吗?
编写一个UpdateTitle
接受所有Title
表列并使用这些值更新标题的过程。引发以下错误消息: ISBN 不存在 类别和/或出版商代码无效。
Create PROCEDURE UpdateTitle (@ISBN char(10), @SuggestedPrice smallmoney,@NumberInStock smallint,@PublisherCode int,@CategoryCode int)
AS
BEGIN
IF @ISBN is null or @CategoryCode is null or @PublisherCode is null
BEGIN
RAISERROR ('ISBN,CategoryCode, or PublisherCode is not valid please enter valid data',16,1)
END
ELSE
BEGIN
IF (SELECT COUNT(*) FROM Title WHERE ISBN = @ISBN) = 0
BEGIN
RAISERROR ('ISBN does not exist.',16,1)
END
ELSE
BEGIN
SELECT 'Table Sucessfully Updated.';
UPDATE Title
SET SuggestedPrice = @SuggestedPrice
WHERE ISBN = @ISBN;
BEGIN
IF (SELECT COUNT(*) FROM Title WHERE ISBN = @ISBN) = 0
BEGIN
RAISERROR ('ISBN does not exist.',16,1)
END
ELSE
BEGIN
SELECT 'Table Sucessfully Updated.';
UPDATE Title
SET NumberInStock = @NumberInStock
WHERE ISBN = @ISBN;
END
BEGIN
IF (SELECT COUNT(*) FROM Title WHERE ISBN = @ISBN) = 0
BEGIN
RAISERROR ('ISBN does not exist.',16,1)
END
ELSE
BEGIN
SELECT 'Table Sucessfully Updated.';
UPDATE Title
SET PublisherCode = @PublisherCode
WHERE ISBN = @ISBN;
END
BEGIN
IF (SELECT COUNT(*) FROM Title WHERE ISBN = @ISBN) = 0
BEGIN
RAISERROR ('ISBN does not exist.',16,1)
END
ELSE
BEGIN
SELECT 'Table Sucessfully Updated.';
UPDATE Title
SET CategoryCode = @CategoryCode
WHERE ISBN = @ISBN;
END
END
END
END
END
END
END
GO
然后
Execute Procedure UpdateTitle @ISBN ='1021031040', @suggestedproce ='40' , @NumberInStock ='10', @PublisherCode = '200', @CategoryCode = '1'