Thursday, March 29, 2012

Deleting Records From Sql Table

I AM TRYING TO DELETE RECORDS FROM THE SQL SERVER TABLE,

I AM USING THE COMMAND BELOW TO DELETE THOSE 71 RECORDS BUT MY WHOLE TABLE GOT DELETED AND HAD TO RECOVER FROM BACKUP..
SO WHAT IS WRONG WITH THE SYNTAX GIVEN BELOW

DELETE FROM dbo.Payment_Placement_AIMS
WHERE EXISTS
(select * from Payment_Placement_AIMS INNER JOIN
TESTING ON Payment_Placement_AIMS.JC_ID = TESTING.JC_ID
WHERE Payment_Placement_AIMS.Date_Stamp > '10/21/2007 12:00:00 AM') AND (Payment_Placement_AIMS.EMP_TYPE = 'First

employment'));since you are using exists in the where clause it is returning true value and the condition is satisfied in result the whole table is deleted (no specific record is mentioned)

following query will help you

DELETE FROM dbo.Payment_Placement_AIMS
WHERE Payment_Placement_AIMS.JC_ID in
(select Payment_Placement_AIMS.JC_ID from Payment_Placement_AIMS INNER JOIN
TESTING ON Payment_Placement_AIMS.JC_ID = TESTING.JC_ID
WHERE Payment_Placement_AIMS.Date_Stamp > '10/21/2007 12:00:00 AM') AND (Payment_Placement_AIMS.EMP_TYPE = 'First

employment'))sql

No comments:

Post a Comment