CREATE SCHEMA sampleSchema
GO
Create a T-SQL
statement to transfer all tables to created schemaDECLARE @sql NVARCHAR(MAX) ;
DECLARE @LINEBREAK AS VARCHAR(2)
SET @LINEBREAK = CHAR(13) + CHAR(10)
SELECT @sql = COALESCE(@sql+ '; ' + @LINEBREAK , '') + 'ALTER SCHEMA [sampleSchema] TRANSFER '
+ QUOTENAME([TABLE_SCHEMA]) + '.' + QUOTENAME([TABLE_NAME])
FROM INFORMATION_SCHEMA.TABLES
PRINT @sql
EXECUTE sp_executesql @sql
Great stuff sir keep it up .. :)
ReplyDelete