dbTalk Databases Forums  

removing data

comp.databases.ms-sqlserver comp.databases.ms-sqlserver


Discuss removing data in the comp.databases.ms-sqlserver forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
chudson007@hotmail.com
 
Posts: n/a

Default removing data - 05-11-2005 , 05:13 AM






I have a table that I need to delete some data from and put the deleted
data into a different table.

How do I script the following.

If Field1 in Table1 is null, remove that row from Table1 and put it in
a new table called Table2

Regards,
Ciarán


Reply With Quote
  #2  
Old   
Madhivanan
 
Posts: n/a

Default Re: removing data - 05-11-2005 , 06:16 AM







Create a newTable having the structure of Oldtable and write a query

Insert into newTable select * from OldTable where Field1 is null
delete from OldTable where Field1 is null

You can also use Trigger

Madhivanan


Reply With Quote
  #3  
Old   
chudson007@hotmail.com
 
Posts: n/a

Default Re: removing data - 05-12-2005 , 03:25 AM




Madhivanan wrote:
Quote:
Create a newTable having the structure of Oldtable and write a query
What is the quickest way to create a newtable with the structure of the
Oldtable? The Oldtable has over 50 fields, of many different types.



Reply With Quote
  #4  
Old   
teddysnips@hotmail.com
 
Posts: n/a

Default Re: removing data - 05-12-2005 , 06:08 AM




chudson... (AT) hotmail (DOT) com wrote:
Quote:
Madhivanan wrote:
Create a newTable having the structure of Oldtable and write a
query

What is the quickest way to create a newtable with the structure of
the
Oldtable? The Oldtable has over 50 fields, of many different types.
Look in BOL under "generating scripts"

Edward
--
The reading group's reading group:
http://www.bookgroup.org.uk



Reply With Quote
  #5  
Old   
Malcolm
 
Posts: n/a

Default Re: removing data - 05-13-2005 , 02:55 AM



The most performant (as it hardly touches the transaction log) and
easiest way to copy the data into a new table is to use the SELECT INTO
command. Loom in Books Online for more detailed information on this
command and why it is best for this kind of operation.

This will dynamically create a new table for you with all of the
required columns and their basic attributes.

You can then delete the copied records from the source table.

Regards,

Malcolm
www.dbghost.com


Reply With Quote
  #6  
Old   
andy.morin@gmail.com
 
Posts: n/a

Default Re: removing data - 05-13-2005 , 11:42 AM



The quickest way is to highlight the table in Query Analyzer and right
click create script.


Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.