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:
1 2 3 4 5 |
-- You have a backup, right? If not, create one first! ALTER SCHEMA NewSchema TRANSFER [dbo].[myTable] GO |
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.