0

知道如何让这个语法错误消失吗?它位于整个过程的最后一个括号中。我似乎无法弄清楚我错过了什么。当我尝试运行它时没有发生其他错误。

CREATE PROCEDURE pRebuildOrReorg
(
    @db VARCHAR(50) =  'AdventureWorksLT2012',
    @table VARCHAR(50) = 'SalesLT.Customer',
    @indexName VARCHAR(50) = 'IX_Customer_EmailAddress'
)
AS 
DECLARE @objID INT
DECLARE @dbID SMALLINT
DECLARE @indexID SMALLINT
DECLARE @avgFrag INT
DECLARE @cmd VARCHAR(100)
DECLARE @message VARCHAR(100)

-- 1. find the object id of the desired table
SET @objID = OBJECT_ID(@table)
SET @dbID = DB_ID(@db)
SET @IndexID = (SELECT index_id FROM sys.indexes WHERE name = @indexName)
-- 2. View the statistics for all indexes of the table
SELECT @avgFrag = avg_fragmentation_in_percent
FROM sys.dm_db_index_physical_stats(DB_ID('AdventureWorksLT2012'),
  OBJECT_ID('SalesLT.Customer'),
 @IndexID, NULL , 'DETAILED')

if @avgFrag >= 30
BEGIN SET @cmd = 'ALTER INDEX ' + @indexName + ' ON ' + @table + ' STATISTICS_NORECOMPUTE = OFF)' 
EXEC (@cmd) 
SET @message = 'Reorganized Index ' + @indexName
ALTER INDEX PK_StoreContact_CustomerID_ContactID
  ON AdventureWorks.Sales.StoreContact
REORGANIZE 
END

else if @avgFrag < 30
BEGIN SET @cmd = 'ALTER INDEX ' + @indexName + ' ON ' + @table + ' STATISTICS_NORECOMPUTE = OFF)' 
EXEC (@cmd) 
SET @message = 'Rebuilt Index ' + @indexName
ALTER INDEX IX_StoreContact_ContactID
  ON AdventureWorks.Sales.StoreContact
REBUILD WITH(
fillfactor = 70,
online = ON
)
4

1 回答 1

2

欢迎使用您的个人语法检查和调试服务。

请在最后一行之后在新行上添加一个END 。

您是否下载了具有改进的智能感知和错误检测功能的 SQL Server Management Studio 2012?

于 2012-10-09T02:10:11.320 回答