Solved

deleting records in MS SQL

Posted on 2009-05-14
7
195 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
Backup Your Microsoft Windows Server®

Backup all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

 
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

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Question has a verified solution.

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

In this article I will describe the Copy Database Wizard method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
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…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

813 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