Solved

deleting records in MS SQL

Posted on 2009-05-14
7
194 Views
Last Modified: 2012-05-07
Hi,

I've never worked with MS SQL before, but I now have it installed on my web server with the clients data successfully migrated.

My question is, if the client wants a single record deleted and we don't have a poage coded to help with this, is there any way on my server to directly delete a record? Clearly it's not as simple as Access, but perhaps a CMD script or something I'm missing from the SQL Server Configuration UI?

Can't seem to find this information anywhere.

Thanks

Bill
0
Comment
Question by:billium99
7 Comments
 
LVL 75

Accepted Solution

by:
Aneesh Retnakaran earned 250 total points
ID: 24384326
Hello billium99,

u need to write a query for this

in a new query window first run this

SELECT * FROM urTable WHERE theConditionToIdentifyTheRecord

if that retunrns the proper record

u can replace the 'SELECT * FROM ' with a 'DELETE ' in the above statement

DELETE urTable WHERE theConditionToIdentifyTheRecord



Regards,

Aneesh
0
 
LVL 16

Expert Comment

by:Auric1983
ID: 24384334
Well - If you are just deleting a single record out of a table.

in SQL Management Studio

Delete from [tablename] where [uniqueidentifier]=X

You want to be sure to have a where clause on the delete statement otherwise it will turf the whole table.

A really good website for SQL tutorials is http://www.w3schools.com/sql/default.asp 

They have a handy cheatsheet you can print off that gives you the basic syntax
0
 
LVL 59

Expert Comment

by:Kevin Cross
ID: 24384335
Do you have an ID to identify the record with?  You would do this using SQL Management Studio.

-- select record where id is 12345 to verify only selecting the one you want
SELECT *
FROM your_table_name
WHERE id_column = 12345

-- delete the record
DELETE
FROM your_table_name
WHERE id_column = 12345


0
Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

 
LVL 75

Expert Comment

by:Aneesh Retnakaran
ID: 24384338
make sure that you delete the appropriate record, once the record is deleted it will be really hard for you to "undo" it in case u want to undo
0
 
LVL 57

Expert Comment

by:Raja Jegan R
ID: 24384341
From the SQL Server Management Studio, you can issue this command

DELETE FROM schemaname.tablename
WHERE PK = ?

where pk = ? represents the condition to identify that particular single record.
0
 
LVL 59

Assisted Solution

by:Kevin Cross
Kevin Cross earned 250 total points
ID: 24384398
I would agree with Aneesh's advise.  A lot of times, I would use the SELECT and DELETE statements we provided you in conjunction with each other to do archiving.
-- insert record into archive table

INSERT INTO your_archive_table

SELECT *

FROM your_table_name

WHERE id_column = 12345
 

-- delete the record only if in archive table

DELETE

FROM your_table_name t1

WHERE EXISTS (SELECT null FROM your_archive_table t2 WHERE t2.id_column = t1.id_column)

Open in new window

0
 
LVL 1

Author Closing Comment

by:billium99
ID: 31581427
Thanks for the help guys!
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

There have been several questions about Large Transaction Log Files in SQL Server 2008, and how to get rid of them when disk space has become critical. This article will explain how to disable full recovery and implement simple recovery that carries…
Occasionally there is a need to clean table columns, especially if you have inherited legacy data. There are obviously many ways to accomplish that, including elaborate UPDATE queries with anywhere from one to numerous REPLACE functions (even within…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

920 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now