【发布时间】:2025-12-04 05:30:01
【问题描述】:
我知道这不是什么大问题,但无论如何它都会让我发痒。
- 我有一个 SQL Server 2005 脚本来创建新的数据表、约束、更改某些表以添加列、更改程序以考虑表更改等。
- 在脚本遇到我的 ALTER PROCEDURE 语句之前一切正常。
- 报错信息如下:
“消息 156,级别 15,状态 1,程序 cpromo_Get_ConsultDetails_PromotionBan, 第 59 行 关键字“程序”。
这是我的脚本示例:
ALTER PROCEDURE [dbo].[cpromo_Get_ConsultDetails_PromotionBan]
(
@idPromoBan int,
@uid int
)
AS
begin
set nocount on;
/* 1- detail de la promo */
SELECT p.[nopromo], p.[StartDate], p.[EndDate], p.[DateText]
FROM [cpromo_PromotionBanniere] as pb
INNER JOIN [cpromo_Promotions] as p ON p.[idPromo] = pb.[idPromo]
WHERE (pb.[idPromoBan] = @idPromoBan)
/* 2 - cartes de la promo */
SELECT pis.[idCardText], ct.[nom], ct.[descr], ct.[prix], ct.[prixCoupon], ct.[qtyItem], i.[Impact]
FROM [cpromo_PromotionsItems] as pis
INNER JOIN [cpromo_Impacts] as i ON i.[idImpact] = pis.[idImpact]
INNER JOIN [cpromo_CardText] as ct ON ct.[idCardText] = pis.[idCardText]
WHERE (pis.[idPromoBan] = @idPromoBan)
ORDER BY i.[iorder], ct.[nom];
/* 3 - pvedettes opti */
SELECT m.[idCardText], m.[qtyCardL], m.[qtyCardM], m.[qtyCardMG], m.[qtyCardS],
ISNULL(m.[qtyCardMini], 0) as qtyCardMini,
ISNULL(m.[qtyCardMiniPTJ], 0) as qtyCardMiniPTJ
FROM [cpromo_MEMCards] as m
INNER JOIN [cpromo_CardText] as ct ON ct.[idCardText] = m.[idCardText]
WHERE (m.[idPromoBan] = @idPromoBan)
ORDER BY ct.[nom];
/* 4 - cart */
SELECT [idCartEl], [idCardText], [qtyL], [qtyM], [qtyMG], [qtyS],
ISNULL([qtyMini], 0) as qtyMini,
ISNULL([qtyMiniPTJ], 0) as qtyMiniPTJ
FROM [cpromo_UserCarts]
WHERE ([uid] = @uid AND [idPromoBan] = @idPromoBan);
end
ALTER PROCEDURE [dbo].[cpromo_Get_CartItems_ByPromotionBan]
(
@uid int,
@idPromoBan int
)
AS
begin
set nocount on;
SELECT ct.nom, ct.descr, p.DateText, ct.prix, ct.prixCoupon, ct.qtyItem,
uc.qtyL, uc.qtyM, uc.qtyMG, uc.qtyS,
isnull(uc.qtyMini, 0) as qtyMini,
isnull(uc.qtyMiniPTJ, 0) as qtyMiniPTJ, 3 as qteLimite
FROM cpromo_UserCarts as uc
INNER JOIN cpromo_CardText as ct ON ct.idCardText = uc.idCardText
INNER JOIN cpromo_PromotionBanniere as pb ON pb.idPromoBan = uc.idPromoBan
INNER JOIN cpromo_Promotions as p ON p.idPromo = pb.idPromo
WHERE (uc.uid = @uid) AND (uc.idPromoBan = @idPromoBan);
end
错误指向双击时遇到的第一个“end”关键字。我根本没有得到的是当一个又一个选择一个 ALTER 语句时,它运行得很好而且很流畅!当我尝试通过按 [F5] 而不进行选择来运行它们时,它给了我错误。
我尝试将 ALTER 语句嵌入到另一个 BEGIN...END 中,但没有成功,它说关键字 ALTER...附近存在语法错误...
编辑:可能是因为我注释了在开始语句之后执行的修改吗?
ALTER PROCEDURE [dbo].[cpromo_Get_ConsultDetails_PromotionBan]
(
@idPromoBan int,
@uid int
)
AS
begin
------------------
-- Added column to take table changes into account blah blah blah...
------------------
set nocount on;
/* 1- detail de la promo */
SELECT p.[nopromo], p.[StartDate], p.[EndDate], p.[DateText]
FROM [cpromo_PromotionBanniere] as pb
INNER JOIN [cpromo_Promotions] as p ON p.[idPromo] = pb.[idPromo]
WHERE (pb.[idPromoBan] = @idPromoBan)
/* 2 - cartes de la promo */
SELECT pis.[idCardText], ct.[nom], ct.[descr], ct.[prix], ct.[prixCoupon], ct.[qtyItem], i.[Impact]
FROM [cpromo_PromotionsItems] as pis
INNER JOIN [cpromo_Impacts] as i ON i.[idImpact] = pis.[idImpact]
INNER JOIN [cpromo_CardText] as ct ON ct.[idCardText] = pis.[idCardText]
WHERE (pis.[idPromoBan] = @idPromoBan)
ORDER BY i.[iorder], ct.[nom];
/* 3 - pvedettes opti */
SELECT m.[idCardText], m.[qtyCardL], m.[qtyCardM], m.[qtyCardMG], m.[qtyCardS],
ISNULL(m.[qtyCardMini], 0) as qtyCardMini,
ISNULL(m.[qtyCardMiniPTJ], 0) as qtyCardMiniPTJ
FROM [cpromo_MEMCards] as m
INNER JOIN [cpromo_CardText] as ct ON ct.[idCardText] = m.[idCardText]
WHERE (m.[idPromoBan] = @idPromoBan)
ORDER BY ct.[nom];
/* 4 - cart */
SELECT [idCartEl], [idCardText], [qtyL], [qtyM], [qtyMG], [qtyS],
ISNULL([qtyMini], 0) as qtyMini,
ISNULL([qtyMiniPTJ], 0) as qtyMiniPTJ
FROM [cpromo_UserCarts]
WHERE ([uid] = @uid AND [idPromoBan] = @idPromoBan);
end
感谢任何帮助或任何提示。
【问题讨论】:
-
按照建议,我在每个 ALTER PROCEDURE 开始...结束后插入“GO”,然后它在“ALTER”附近显示另一个语法错误。
-
我确实尝试按照此处另一位程序员的建议删除所有参数括号(我很遗憾没有时间记住他的名字),但仍然有错误消息 Msg 156, Level 15 ,状态 1,过程 cpromo_Get_ConsultDetails_PromotionBan,第 59 行 关键字“ALTER”附近的语法不正确。当我双击它时,它会将我指向第一个“end”关键字。
-
我是否应该考虑说我所做的是复制并粘贴为每个过程生成的 ALTER PROCEDURE 脚本?
-
我知道它很长而且读起来不太有趣。对不起。这个项目位于一个客户站点,我没有得到内部编程团队的太多支持。
-
好吧,我成功解决了我的语法错误。我要感谢大家的答案,我将设置为正确的解决方案。这都是你的答案。
标签: sql-server-2005 alter-table alter sql-scripts