SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 DUPLICATE DATA through INSERT TRIGGER
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

daipayan
Posting Yak Master

India
181 Posts

Posted - 08/14/2009 :  09:33:08  Show Profile  Visit daipayan's Homepage  Send daipayan a Yahoo! Message  Reply with Quote
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
Flowing Fount of Yak Knowledge

USA
1836 Posts

Posted - 08/14/2009 :  10:00:40  Show Profile  Reply with Quote
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

India
181 Posts

Posted - 08/21/2009 :  09:33:25  Show Profile  Visit daipayan's Homepage  Send daipayan a Yahoo! Message  Reply with Quote
No this INSERTED modification is not giving me the right solution

Daipayan
Go to Top of Page

Shaj
Starting Member

3 Posts

Posted - 08/21/2009 :  16:08:04  Show Profile  Reply with Quote
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

Edited by - Shaj on 08/21/2009 16:35:16
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.04 seconds. Powered By: Snitz Forums 2000