Skip to content

Instantly share code, notes, and snippets.

@jbubriski
Last active December 18, 2015 15:58
Show Gist options
  • Save jbubriski/5807915 to your computer and use it in GitHub Desktop.
Save jbubriski/5807915 to your computer and use it in GitHub Desktop.
Transfer SQL Server Objects to another schema.
SELECT 'ALTER SCHEMA dbo TRANSFER ' + s.Name + '.' + o.Name
FROM sys.Objects o
INNER JOIN sys.Schemas s on o.schema_id = s.schema_id
WHERE s.Name = 'your_schema_name'
And (o.Type = 'U' Or o.Type = 'P' Or o.Type = 'V')
EXEC sp_MSforeachtable "ALTER SCHEMA dbo TRANSFER ? PRINT '? modified' "
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment