Changing schema names on Sql Server 2005

Print Friendly

     I my database on Sql Server 2005, I have to change schema names from some username to dbo and I wrote the following sql statements which simply generates alter queries. All you have to do is to change ‘Username Here‘ to actual username, it will generates alter queries for you and then just copy and execute them in query window.

SELECT 'ALTER SCHEMA dbo TRANSFER' + s.Name + '.' + p.Name FROM sys.Procedures p INNER JOIN
sys.Schemas s on p.schema_id = s.schema_id WHERE s.Name = 'Username Here'
SELECT 'ALTER SCHEMA dbo TRANSFER' + s.Name + '.' + t.Name FROM sys.Tables t INNER JOIN
sys.Schemas s on t.schema_id = s.schema_id WHERE s.Name = 'Username Here'
SELECT 'ALTER SCHEMA dbo TRANSFER' + s.Name + '.' + v.Name FROM sys.Views v INNER JOIN
sys.Schemas s on v.schema_id = s.schema_id WHERE s.Name = 'Username Here'

Related posts:

  1. Changing Team Foundation Server SMTP Server and E-mail Notification Settings
  2. Unattended installation of Visual Studio 2005 Team Explorer
Twitter Digg Delicious Stumbleupon Technorati Facebook Email

No comments yet... Be the first to leave a reply!

Leave a Reply

 
QR Code Business Card