Solved

deleting records in MS SQL

Posted on 2009-05-14
7
197 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 60

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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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 60

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

The Ultimate Checklist to Optimize Your Website

Websites are getting bigger and complicated by the day. Video, images, custom fonts are all great for showcasing your product/service. But the price to pay in terms of reduced page load times and ultimately, decreased sales, can lead to some difficult decisions about what to cut.

Question has a verified solution.

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

This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…

691 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