Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 DUPLICATE DATA through INSERT TRIGGER

Author  Topic 

daipayan
Posting Yak Master

181 Posts

Posted - 2009-08-14 : 09:33:08
Respected Coders,
I have the following after insert trigger in attendence_date table:
CREATE TRIGGER Students_date
ON dbo.attendence_date
AFTER INSERT
AS
SET NOCOUNT ON
INSERT INTO mark_absent (attendence_ID, student_ID, mark_absent)
SELECT ad.attendence_ID, sc.student_ID, '0'
FROM dbo.attendence_date ad INNER JOIN
dbo.section_course sc ON ad.course_code = sc.course_code AND
ad.college = sc.college AND ad.section_name = sc.section_name AND
ad.routine_batch = sc.batchcode


Whenever I am firing the following TRIGGER, new data as well as the old data is again being inserted in the attendence_date table.
Can you tell me, how to avoid inserting duplicate data in the attendence_date by firing the following TRIGGER!
Please am in great need..PLEASE HELP!!

Daipayan

vijayisonly
Master Smack Fu Yak Hacker

1836 Posts

Posted - 2009-08-14 : 10:00:40
Maybe you need this?

CREATE TRIGGER Students_date
ON dbo.attendence_date
AFTER INSERT
AS
SET NOCOUNT ON
INSERT INTO mark_absent (attendence_ID, student_ID, mark_absent)
SELECT ad.attendence_ID, sc.student_ID, '0'
FROM Inserted ad INNER JOIN
dbo.section_course sc ON ad.course_code = sc.course_code AND
ad.college = sc.college AND ad.section_name = sc.section_name AND
ad.routine_batch = sc.batchcode
Go to Top of Page

daipayan
Posting Yak Master

181 Posts

Posted - 2009-08-21 : 09:33:25
No this INSERTED modification is not giving me the right solution

Daipayan
Go to Top of Page

Shaj
Starting Member

3 Posts

Posted - 2009-08-21 : 16:08:04
Hi,

I am not sure how you are saying old and new data, when it is an INSERT trigger. It should always be new data correct.

You are running the The SELECT - inner join generically, vijayisonly's query looks for only INSERTED records..mostly that should work
Go to Top of Page
   

- Advertisement -