Little SQL Server Tricks: Move a Table into another Schema

Not every design decision for your database will pass the test of time. Better names pop up or sometimes you just created a table in the wrong place. You could throw everything away and start from scratch, but a much better approach is just to fix what is wrong. If you want to move a table to another schema, you can use this SQL Server command:

Replace the name of NewSchema with your already created schema and change the name of myTable to the table you want to move. Your foreign keys will be updated accordingly and no data is lost.

Refactoring your database can be so easy – try it the next time you find a better place for your table.

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.