Skip to content

Instantly share code, notes, and snippets.

@adamantnz
Last active May 26, 2016 09:28
Show Gist options
  • Save adamantnz/39a14d02475baef358fc83dc152eba10 to your computer and use it in GitHub Desktop.
Save adamantnz/39a14d02475baef358fc83dc152eba10 to your computer and use it in GitHub Desktop.
SQL Server move object to schema
DECLARE
@SQL NVARCHAR(MAX) = NULL
,@DB NVARCHAR(50) = ''
,@newSchema NVARCHAR(50) = ''
,@objectName NVARCHAR(50) = '' /* include existing schema */
BEGIN
SET @SQL = 'USE '+@DB+' GO ALTER SCHEMA '+@newSchema+' TRANSFER '+@objectName+';'
PRINT @SQL
EXEC sp_executesql @SQL
END
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment