Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Drop table into??

Author  Topic 

Dwish1372
Starting Member

7 Posts

Posted - 2008-01-14 : 22:44:05
hi everyone,

I have a couple questions. I'm very new to SQL and I have this problem:
I need to be able to drop the contents of Existingtable_B into Newtable_A - I found this command (below) that will make a 'copy' but I don't want to keep the contents of Existingtable_B. Is it possible to drop them into Newtable_A instead of copy? Also, I want to do this for 5 tables on Sundays at midnight.. how could I schedule that? Finally, what happens if there is not enough space or some other critical error happens during this procedure? I don't want to lose the data.

Any help is greatly appreciated.

select * into Newtable_A from Existingtable_B

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2008-01-14 : 22:50:22
duplicate thread http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=95518


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

barny.spencer@openoffice.
Starting Member

3 Posts

Posted - 2008-01-14 : 22:52:39
Hi Dwish1372.
If the structure of the two tables is the same you can do a;
INSERT INTO Newtable_A
SELECT * FROM Existingtable_B
or specify field names if needed.

followed by;
DELETE Existingtable_B
to clear all existing data.
Wrap the whole lot up in a transaction within your stored procedure to avoid data loss if something nasty happens during processing.

To create a schedule you can place these statements in a stored procedure and then create a job to execute it on a schedule.
A job can be configured to email/log any errors that occur too.
Cheers.

Go to Top of Page
   

- Advertisement -