[thelist] [tip] duplicate a table structure

Ken Schaefer ken at adOpenStatic.com
Sun Oct 12 22:09:29 CDT 2003


~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
From: "Joshua Olson" <joshua at waetech.com>
Subject: [thelist] [tip] duplicate a table structure


: If you need a quick way to duplicate a table structure in
: SQL Server and can't get into EM, you can use the following
: SQL:
:
: SELECT TOP 1 *
: INTO newtable
: FROM oldtable
:
: TRUNCATE TABLE newtable
:
: It'll copy the column definitions.  If you want to set
: up the default values, indexes, etc, you'll need to
: set those up afterwards.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

If you have access to Query Analyser, you can use the object browser to do a
"Script create to new window", and just edit the table name. And then SQL to
create all your defaults, indexes and constraints will be in the script. You
can run the script straight away, or save the script to a .sql file in case
you need it later.

Cheers
Ken

Microsoft MVP - Windows Server (IIS)



More information about the thelist mailing list