About
Pricing
Community
Teams
Start Free Trial
Log in
Zack
asked on
4/6/2017
Changing the Schema for all Tables in a Tables - MS SQL Server 2008 R2.
Hi EE,
I know to change the schema name of table you the following command:
ALTER SCHEMA MySchema TRANSFER dbo.MyTable
My query are there any scripts out there that do this to all the tables in a database as this database has hundreds of tables?
Any assistance is appreciated.
Thank you.
Microsoft SQL Server
SQL
3
1
Last Comment
Zack
8/22/2022 - Mon
Kelvin Sparks
4/6/2017
I'd create a loop based on the tables names returned from something like SELECT Name from sys.Tables and then generate dynamic sql like
'ALTER SCHEMA myschema TRANSFER ' + dbo.Mytable
then execute it.
Sorry, not at a computer to code it exactly.
Kelvin
ASKER CERTIFIED SOLUTION
JesterToo
4/6/2017
THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Zack
4/6/2017
ASKER
Thank you very much for the link.
Experts Exchange has (a) saved my job multiple times, (b) saved me hours, days, and even weeks of work, and often (c) makes me look like a superhero! This place is MAGIC!
Walt Forbes
'ALTER SCHEMA myschema TRANSFER ' + dbo.Mytable
then execute it.
Sorry, not at a computer to code it exactly.
Kelvin