January 26, 2022 at 10:44 am
Hello Everyone,
I have below query to delete record from ' ExamSet '. but based on the ' ExamSet ' table ' Setid ' column value i need to remove all reacords in ' ExamLog ' table. here i need to select old Setids from ExamSet table CreatedDate (older records based on @day parameter)
I need to delete all records (associated to Setid coming from ExamSet table) from ExamLog table only not from ExamSet table
CREATE PROCEDURE sp_deleteLog(@day Int)
AS
BEGIN
DELETE [dbo].[ExamSet] Where CreatedDate<DATEADD(dd, -@day, GETDATE());
END
Please help me
Thanks
January 26, 2022 at 2:20 pm
If I understand what you're asking for, I think the OUTPUT clause is what you're looking for. That will allow you to know exactly which records were deleted from the first table, and use that to delete in the second table.
"The credit belongs to the man who is actually in the arena, whose face is marred by dust and sweat and blood"
- Theodore Roosevelt
Author of:
SQL Server Execution Plans
SQL Server Query Performance Tuning
January 26, 2022 at 2:21 pm
I gave you an example of how to do exactly this in your previous post
You just need to change the table names
January 26, 2022 at 2:33 pm
Hi,
It was my mistake here. I need to delete all records associated to Setid in ExamLog table only, not from ExamSet table. ExamSet is only for fetching old Setid records based on CreatedDate.
Viewing 4 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply