Solved

deleting records in MS SQL

Posted on 2009-05-14
7
193 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Control application downtime with dependency maps

Visualize the interdependencies between application components better with Applications Manager's automated application discovery and dependency mapping feature. Resolve performance issues faster by quickly isolating problematic components.

 
LVL 75

Expert Comment

by:Aneesh Retnakaran
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
Thanks for the help guys!
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

In SQL Server, when rows are selected from a table, does it retrieve data in the order in which it is inserted?  Many believe this is the case. Let us try to examine for ourselves with an example. To get started, use the following script, wh…
Data architecture is an important aspect in Software as a Service (SaaS) delivery model. This article is a study on the database of a single-tenant application that could be extended to support multiple tenants. The application is web-based develope…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

771 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

11 Experts available now in Live!

Get 1:1 Help Now