• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 204
  • Last Modified:

deleting records in MS SQL

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
billium99
Asked:
billium99
2 Solutions
 
Aneesh RetnakaranDatabase AdministratorCommented:
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
 
Auric1983Commented:
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
 
Kevin CrossChief Technology OfficerCommented:
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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
Aneesh RetnakaranDatabase AdministratorCommented:
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
 
Raja Jegan RSQL Server DBA & ArchitectCommented:
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
 
Kevin CrossChief Technology OfficerCommented:
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
 
billium99Author Commented:
Thanks for the help guys!
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now