Unfortunately, this is not so easy. But there is a way.
First create the new schema:
create schema {newschema};
go
Now you can use SCHEMA TRANSFER to transfer the tables from the old to the new schema.
DECLARE @sql NVARCHAR(MAX) = '';
SELECT @sql += 'ALTER SCHEMA {newschema} TRANSFER {oldschema}.' + name + ';'
FROM sys.tables
WHERE SCHEMA_NAME(schema_id) = '{oldschema}';
EXEC sp_executesql @sql;
Schreibe einen Kommentar