October 19, 2009 at 1:44 am
DEAR ALL;
How can i use the Output class;
for Instance I want to Delete that on record these record are shown in Resultgrid;
pls help this;
Thanks Advance ;
A.faijurrahuman MCA
Coimbatore
October 29, 2009 at 4:10 pm
Hi
Could you be more specific, please?
Thanks
Flo
October 30, 2009 at 7:13 am
Hi Friends;
Like the table name studentmaster
regno studname mark
1 Foo 88
2 faijur 75
3 raja 78
Whether I want to Delete the regno=2
the deleted entry saved in another studentmasterbkup table
How can i write the script;
Thanks Advance;
A.Faijurrahuman MCA
Coimbatore
pls help me;
October 30, 2009 at 7:22 am
Hi
There are different approaches to handle this. I would suggest the OUTPUT clause on SQL Server 2005:
DECLARE @student TABLE
(
Id INT NOT NULL IDENTITY(1,1)
PRIMARY KEY CLUSTERED
,Name VARCHAR(100)
);
DECLARE @student_audit TABLE
(
StudentId INT NOT NULL
,DeleteDate DATETIME NOT NULL
,Name VARCHAR(100)
PRIMARY KEY (StudentId, DeleteDate)
);
INSERT INTO @student
SELECT 'foo'
UNION ALL SELECT 'bar';
-- delete student and move to audit-table
DELETE FROM @student
OUTPUT
deleted.Id
,GETDATE()
,deleted.Name
INTO @student_audit
WHERE Name = 'bar';
SELECT * FROM @student;
SELECT * FROM @student_audit;
Greets
Flo
October 30, 2009 at 7:31 am
Thanks for your quick response
But in case I have to solve the problem in Trigger ;
How can i Write the script;
Thanks &Advance;
A.Faijurrahuman17
October 30, 2009 at 7:36 am
Hi
Have a look at the CREATE TRIGGER description. You can use an "AFTER DELETE". Within this trigger you can access a virtual table called "deleted" which contains exactly all columns of your source table.
Greets
Flo
Viewing 6 posts - 1 through 5 (of 5 total)
You must be logged in to reply to this topic. Login to reply