Re: Quicked way to create a copy of a table with all default values in
- From: "Bob Barrows" <reb01501@xxxxxxxxxxxxxxx>
- Date: Fri, 13 Nov 2009 12:51:29 -0500
Toby wrote:
I know that using something like this is the quickest way to create aI'm not really sure that is the quicest method ... maybe for the
table: SELECT * INTO newtablename FROM oldtablename WHERE 1>2
However I need for the new table to have all the default values that
have been declared in the old table and the select statement above
does not do that. How can I keep the default values without having
to run an alter statement that adds them back in.
developer, but probably not for the database engine.
The reason this might be the "quickest" is because there is no attempt
made to determine and duplicate the constraints, indexes and defaults in
the source table.
You need to use ALTER TABLE to add constraints and indexes to the new
table. There is no getting around that.
The good news is that you can use SSMS to generate the script needed to
create a table and all its constraints. So do that, change the table and
associated object names to avoid duplication, and you're good to go. If
you need to figure out how to generate this script programmatically,
turn on SQL Profiler while SSMS generates the script to see what you
have to do in your program code.
--
HTH,
Bob Barrows
.
- Follow-Ups:
- References:
- Prev by Date: Re: WHERE IN (SELECT) with multiple columns
- Next by Date: Re: Quicked way to create a copy of a table with all default values in
- Previous by thread: Re: Quicked way to create a copy of a table with all default values in
- Next by thread: Re: Quicked way to create a copy of a table with all default value
- Index(es):
Relevant Pages
|