|
|
Question : SELECT INTO and Default Values
|
|
There are many times I simply want to create a copy of a table...either during development and I do not want to have to run a full restore. Or in some cases on live data, when running a full restore may not be an option(I run a full backup just in case...of course)
I'll do somthing like this
SELECT * INTO bak_MyTable FROM MyTable
But the problem is that the INTO Statement will copy the table structure...but it does not copy defaults.
Its not really a big problem, but there are plenty of times that I've forgotten to add newid() to the guid column and has caused minor headaches down the road.
Basically my question is : Is there a way to do a SELECT INTO and copy the table completly....or is there a SQL Server setting that enables this? Or am I just SOL.
|
Answer : SELECT INTO and Default Values
|
|
SELECT INTO does not copy the constraints, indices, or triggers that are associated with a table. It only copies the basic column schema and the data itself. If you want a better "copy" of the table then the easiest way is to pull the table DDL script into query analyzer, change the table name, and run the script. Then use select into or insert to move the data.
|
|
|
|
|