Friday, February 17, 2012

Copy Table

I have a DB which will have many tables that are the same only named
differently. Instead of recreating each one is there a way to "Copy Table" ?
Thanks in advanceIt is possible to "copy" a table via a SELECT statement
Lets say you have a table called foo and you want to copy it to a table =
named bar.
This will copy the structure and data:
SELECT * INTO bar FROM foo
This will copy the structure:
SELECT * INTO bar FROM foo WHERE 0=3D1
Note: you have to have the select into/bulkcopy dboption set to 'on' for =
this method to work.
--=20
Keith
"Jim Campau" <Jim_Campau@.bausch.com> wrote in message =
news:uA1kPus1DHA.1760@.TK2MSFTNGP10.phx.gbl...
quote:

> I have a DB which will have many tables that are the same only named
> differently. Instead of recreating each one is there a way to "Copy =

Table" ?
quote:

>=20
> Thanks in advance
>=20
>
|||Hi,
Use the command
select * into newtablename from tablename
The above command copy the table along with data
select * into newtablename from tablename where 1=2
The above command copy the table structure only.
Thanks
Hari
MCDBA
"Jim Campau" <Jim_Campau@.bausch.com> wrote in message
news:uA1kPus1DHA.1760@.TK2MSFTNGP10.phx.gbl...
quote:

> I have a DB which will have many tables that are the same only named
> differently. Instead of recreating each one is there a way to "Copy Table"

?
quote:

> Thanks in advance
>

No comments:

Post a Comment