この構文エラーをなくす方法はありますか?それは全体の手順の最後のparanthesisにあります。何が欠けているのかわからないようです。実行しようとしても他のエラーは発生しません。
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
)