Unix Technical Forum

removing data

This is a discussion on removing data within the SQL Server forums, part of the Microsoft SQL Server category; --> I have a table that I need to delete some data from and put the deleted data into a ...


Go Back   Unix Technical Forum > Database Server Software > Microsoft SQL Server > SQL Server

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 02-29-2008, 08:26 AM
chudson007@hotmail.com
 
Posts: n/a
Default removing data

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

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 02-29-2008, 08:26 AM
Madhivanan
 
Posts: n/a
Default Re: removing data


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

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 02-29-2008, 08:27 AM
chudson007@hotmail.com
 
Posts: n/a
Default Re: removing data


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.

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 02-29-2008, 08:27 AM
teddysnips@hotmail.com
 
Posts: n/a
Default Re: removing data


chudson...@hotmail.com wrote:
> 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

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 02-29-2008, 08:27 AM
Malcolm
 
Posts: n/a
Default Re: removing data

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

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #6 (permalink)  
Old 02-29-2008, 08:28 AM
andy.morin@gmail.com
 
Posts: n/a
Default Re: removing data

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

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
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
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 02:36 PM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0
www.UnixAdminTalk.com