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
 SQL Server Administration (2005)
 Drop table into??

Author  Topic 

Dwish1372
Starting Member

7 Posts

Posted - 2008-01-14 : 22:39:09
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.

Dwish1372
Starting Member

7 Posts

Posted - 2008-01-14 : 22:42:32
select * into Newtable_A from Existingtable_B
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2008-01-14 : 22:52:01

insert into Newtable_A ( column list )
select <columns>
from Existingtable_B


you might also want to check for existing of Existingtable_B record in Newtable_A


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

Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2008-01-14 : 22:55:04
Note : SELECT INTO will create the target table if will fail if the target table existed


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

Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2008-01-16 : 03:20:16
insert into Newtable_A ( column list )
select <columns>
from Existingtable_B
where some_condition

Delete from Existingtable_B
where some_condition

Schedule it as a job

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -