存储过程中出现的维护计划错误

时间:2013-06-26 18:13:56

标签: sql sql-server stored-procedures

尝试创建存储过程时出错。我试图搞清楚,但经过一段时间后,我决定问。

以下是我的SP的代码:

ALTER PROCEDURE [dbo].[sp_maintenance]

AS

begin

            dbcc checkdb('BD_Farmacia')

            GO
            ALTER INDEX ALL ON Artigo
            REBUILD
            GO

            GO
            ALTER INDEX ALL ON Categoria
            REBUILD
            GO

            GO
            ALTER INDEX ALL ON Composicao
            REBUILD
            GO

            GO
            ALTER INDEX ALL ON Iva
            REBUILD
            GO

            GO
            ALTER INDEX ALL ON Linha_venda
            REBUILD
            GO

            GO
            ALTER INDEX ALL ON Lote
            REBUILD
            GO

            GO
            ALTER INDEX ALL ON Utente
            REBUILD
            GO

            GO
            ALTER INDEX ALL ON Venda
            REBUILD
            GO


end
RETURN

以下是错误消息:

Msg 102, Level 15, State 1, Procedure sp_maintenance, Line 8
Incorrect syntax near ')'.
Msg 156, Level 15, State 1, Line 4
Incorrect syntax near the keyword 'RETURN'.

有人可以帮忙吗? 谢谢 Chiapa

1 个答案:

答案 0 :(得分:2)

您不能在存储过程中使用GO - 它用于分隔批量SQL。