Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In sql server 2005, how do I change the "schema" of a table without losing any data?

I have a table that got into the "db_owner" schema, and I need it in the "dbo" schema.

Is there a script or command to run to switch it over?

like image 555
DevelopingChris Avatar asked Sep 18 '08 02:09

DevelopingChris


People also ask

How do I change the schema of an existing table in SQL Server?

To change the schema of a table by using SQL Server Management Studio, in Object Explorer, right-click on the table and then click Design. Press F4 to open the Properties window. In the Schema box, select a new schema. ALTER SCHEMA uses a schema level lock.

How can I modify a table without dropping the table?

So to do that go to SQL Server and within Tools select Options. Now in the option window expand Designers and under that "Table and Database Designers" and uncheck the check box "Prevent saving changes that require table re-creation" then click OK.

How do you edit a table in a schema?

To edit the table schema from the table editor, right-click on the table you wish to edit in the left navigation pane and choose “Edit table...”, as shown below. This will open the schema editor. The schema editor is a powerful tool that you can use to configure your schema.

Can a database schema be changed?

A schema change is an alteration made to a collection of logical structures (or schema objects) in a database. Schema changes are generally made using structured query language (SQL) and are typically implemented during maintenance windows.


2 Answers

In SQL Server Management Studio:

  1. Right click the table and select modify (it's called "Design" now)
  2. On the properties panel choose the correct owning schema.
like image 76
Jason Punyon Avatar answered Sep 17 '22 16:09

Jason Punyon


ALTER SCHEMA [NewSchema] TRANSFER [OldSchema].[Table1] 
like image 30
Stephen Wrighton Avatar answered Sep 17 '22 16:09

Stephen Wrighton