Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Copying entire table to a new table?

Status
Not open for further replies.

Cineno

Programmer
Jul 24, 2006
142
US
I have two tables that are structured exactly the same. Is there an easy way to copy all of the data from one table into the second table?

I'm not sure if this an elementary thing to do, I'm new with SQL. So is there an easy SQL statement that will just make this second table identicle to the first table?

Thanks for any help!
 
[tt][blue]Insert Into EmptyTable Select * From ExistingTable[/blue][/tt]

Usually, you want to specify the fields, but if the table structures are identical (including the ordinal positions of the fields), then the above syntax should work.

If the table structures are different, or the ordinal positions are different, then the expanded format would be...

[tt][blue]
Insert Into EmptyTable(Field1, Field2, etc...)
Select Field1, Field2, etc...
From ExistingTable
[/blue][/tt]

-George

Strong and bitter words indicate a weak cause. - Fortune cookie wisdom
 
something like this:

Code:
select [ID], [TEST]
into tblName1
 from tblName

HTH,

Alex

Professor: But what about your superintelligence?
Gunther: When I had that there was too much pressure to use it. All I want out of life is to be a monkey of moderate intelligence who wears a suit. That's why I've decided to transfer to Business School.
Professor: NOOOOOOOOOOOO.
 
Select into will create a table, whereas insert into will add data to an existing table.

-George

Strong and bitter words indicate a weak cause. - Fortune cookie wisdom
 
It worked great, thanks for such quick help!
 
If you need to do this repeatedly, use

TRUNCATE TABLE target_table

before you run the query.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top