将数据表所属的架构变更为新的架构名
- DECLARE @name sysname;
- DECLARE @old_schema_name varchar(50)
- DECLARE @new_schema_name varchar(50)
- DECLARE @sql VARCHAR(255)
- SET @old_schema_name = 'kbdb99' --将老的架构名写引号中
- SET @new_schema_name = 'dbo' --将新的架构名写引号中
- DECLARE CSR CURSOR
- FOR SELECT t.[name] AS TableName FROM sys.tables AS t,sys.schemas AS s WHERE t.schema_id = s.schema_id AND s.[name] = @old_schema_name
- OPEN csr
- FETCH NEXT FROM csr INTO @name
- while (@@FETCH_STATUS=0)
- BEGIN
- SET @sql = 'ALTER SCHEMA' + @new_schema_name + 'TRANSFER ' + @old_schema_name + '.' + @name;
- --PRINT @sql;
- EXEC (@sql)
- FETCH NEXT FROM CSR INTO @name
- END
- CLOSE CSR
- DEALLOCATE CSR
复制代码
|
|
hessen