Thursday, July 23, 2009

Change schema on table and proc in SQL SERVER 2005

To change the schema table from one to another is by executing the query

select 'ALTER SCHEMA dbo TRANSFER ' + s.Name+ '.' + p.Name
FROM sys.tables p
inner join
sys.Schemas s on p.schema_id = s.schema_id


Result :
  • ALTER SCHEMA dbo TRANSFER aniSchema.video_master
  • ALTER SCHEMA dbo TRANSFER aniSchema.enquiry_master
  • ALTER SCHEMA dbo TRANSFER aniSchema.blog_master
Copy the result and execute the result in new query then the schema(aniSchema) is changed to dbo .

OR
For tables and views

SELECT 'ALTER SCHEMA dbo TRANSFER ' + TABLE_SCHEMA + '.' + TABLE_NAME FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA = 'aniSchema'

And do the above step after getting the result

0 comments:

 
Counter