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!

deleting data from a table ...? using SQL

Status
Not open for further replies.

myheadsashed

Technical User
Mar 20, 2002
3
GB
How do I delete selective data from a table using a Sql Script...?

There is a lot of false data in the table that requires purging/deleting...? This is due to testing of the System over a period of months.!

Is there an easy way of deleting data as I cannot drop the table and recreate it as there is valid data within the table I need..?
 
Multiple ways:

1. SQL DELETE Query -
DELETE *
FROM MyTable
WHERE (Qualify bad records here)

2. Make a copy of the table, copy good data into copy, truncate old table, copy records back into old table.

How can you tell good data from bad data? Terry
**************************
* General Disclaimor - Please read *
**************************
Please make sure your post is in the CORRECT forum, has a descriptive title, gives as much detail to the problem as possible, and has examples of expected results. This will enable me and others to help you faster...
 
Thanks Terry,

The data which I require to Keep is Prefixed C1B% or C2B% or C3B% the other data is Prefixed M123% or S123%. This can be selected as these are the taskname..!

So i Take it I could use

delete * from HISTORY.data
where taskname like 'M123%';

 
DELETE FROM HISTORY.data
WHERE TaskName like 'M123%' OR
TaskName like 'S123%';

Before doing it, I would change it to a select to verify...

SELECT *
FROM HISTORY.data
WHERE TaskName like 'M123%' OR
TaskName like 'S123%';
Terry
**************************
* General Disclaimor - Please read *
**************************
Please make sure your post is in the CORRECT forum, has a descriptive title, gives as much detail to the problem as possible, and has examples of expected results. This will enable me and others to help you faster...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top