必须声明标量变量 "@table_name"
时间: 2023-07-30 07:10:30 浏览: 141
非常抱歉,我再次犯了同样的错误。这里是修复后的脚本```sql
DECLARE @BeginMonth NVARCHAR(6) = '202207'
DECLARE @EndMonth NVARCHAR(6) = '202212'
DECLARE @DataPartName NVARCHAR(100) = 'GTA_SEL2_TAQ_%'
SET @alter_table_script = ''
DECLARE @table_name NVARCHAR(100)
DECLARE database_cursor CURSOR FOR
SELECT name
FROM sys.databases
WHERE name LIKE @database_prefix + '%_' + @BeginMonth
OPEN database_cursor
FETCH NEXT FROM database_cursor INTO @table_name
WHILE @@FETCH_STATUS = 0
BEGIN
DECLARE @field_to_delete NVARCHAR(100) = 'field_to_delete'
SET @alter_table_script = @alter_table_script + 'ALTER TABLE ' + QUOTENAME(@table_name) + ' DROP COLUMN ' + QUOTENAME(@field_to_delete) + ';' + CHAR(13)
FETCH NEXT FROM database_cursor INTO @table_name
END
CLOSE database_cursor
DEALLOCATE database_cursor
PRINT @alter_table_script
```
现在,`@table_name` 变量已经在脚本中进行了声明。请记得在使用之前根据你的需求修改 `@BeginMonth`、`@EndMonth` 和 `@DataPartName` 参数,并仔细检查和测试脚本。非常抱歉给你带来的困扰。
阅读全文