REINDEX IN DYNAMICS AX D365 SCRIPT TO REINDEX TABLE ON DATABASE
DECLARE
@Database VARCHAR(255)
DECLARE @Table VARCHAR(255)
DECLARE @cmd NVARCHAR(500)
DECLARE @fillfactor INT
DECLARE @cmd NVARCHAR(500)
DECLARE @fillfactor INT
SET
@fillfactor = 90
DECLARE
DatabaseCursor CURSOR FOR
SELECT name FROM master.dbo.sysdatabases
WHERE name IN ('DATABASENAME') ///YOUR TABLE NAME HERE
ORDER BY 1
SELECT name FROM master.dbo.sysdatabases
WHERE name IN ('DATABASENAME') ///YOUR TABLE NAME HERE
ORDER BY 1
OPEN
DatabaseCursor
FETCH
NEXT FROM DatabaseCursor INTO @Database
WHILE @@FETCH_STATUS = 0
BEGIN
WHILE @@FETCH_STATUS = 0
BEGIN
SET
@cmd = 'DECLARE TableCursor CURSOR FOR SELECT ''['' + table_catalog + ''].['' +
table_schema + ''].['' +
table_name + '']'' as tableName FROM [' + @Database + '].INFORMATION_SCHEMA.TABLES
WHERE table_type = ''BASE TABLE'''
table_name + '']'' as tableName FROM [' + @Database + '].INFORMATION_SCHEMA.TABLES
WHERE table_type = ''BASE TABLE'''
--
create table cursor
EXEC (@cmd)
OPEN TableCursor
EXEC (@cmd)
OPEN TableCursor
FETCH
NEXT FROM TableCursor INTO @Table
WHILE @@FETCH_STATUS = 0
BEGIN
WHILE @@FETCH_STATUS = 0
BEGIN
Print ('ALTER INDEX ALL ON ' +
@Table)
SET @cmd = 'ALTER INDEX ALL ON ' + @Table + ' REBUILD WITH (FILLFACTOR = ' + CONVERT(VARCHAR(3),@fillfactor) + ')'
EXEC (@cmd)
SET @cmd = 'ALTER INDEX ALL ON ' + @Table + ' REBUILD WITH (FILLFACTOR = ' + CONVERT(VARCHAR(3),@fillfactor) + ')'
EXEC (@cmd)
FETCH
NEXT FROM TableCursor INTO @Table
END
END
CLOSE
TableCursor
DEALLOCATE TableCursor
DEALLOCATE TableCursor
FETCH
NEXT FROM DatabaseCursor INTO @Database
END
CLOSE DatabaseCursor
DEALLOCATE DatabaseCursor
END
CLOSE DatabaseCursor
DEALLOCATE DatabaseCursor
No comments:
Post a Comment