我有以下查询:
DECLARE @TableName VARCHAR(MAX)
DECLARE @Script VARCHAR(MAX) = ''
DECLARE @sql NVARCHAR(MAX)
DECLARE @fillfactor INT
DECLARE TableCursor CURSOR FOR
SELECT '[' + OBJECT_SCHEMA_NAME([object_id]) + '].[' + name + ']' AS TableName
FROM sys.tables
OPEN TableCursor
FETCH NEXT FROM TableCursor INTO @TableName
WHILE @@FETCH_STATUS = 0
BEGIN
SET @sql = 'ALTER INDEX ALL ON ' + @TableName + ' REBUILD' + ')'
SELECT @Script = CAST(@Script + @sql AS VARCHAR(MAX))
FETCH NEXT FROM TableCursor INTO @TableName
END
CLOSE TableCursor
DEALLOCATE TableCursor
PRINT @Script
GO
SQL Server的新功能。现在限制为8000个字符,我想知道如何打印所有表中的@Script
,并且同时@sql
上的每一行都换成新行。