Last active
          May 26, 2016 09:28 
        
      - 
      
 - 
        
Save adamantnz/39a14d02475baef358fc83dc152eba10 to your computer and use it in GitHub Desktop.  
    SQL Server move object to schema
  
        
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | 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