473,386 Members | 1,886 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

After Insert trigger not running

Seth Schrock
2,965 Expert 2GB
I have a SQL Server database that has two tables with INSERT triggers. My front end is an MS Access database connecting via ODBC. The one trigger works fine, but the other one doesn't run at all. What can I do to troubleshoot this problem?

I forgot to mention, if I run an INSERT query from SSMS, then both triggers work.
Feb 5 '16 #1
3 4228
Rabbit
12,516 Expert Mod 8TB
What's the code for the insert trigger?

One thing you can do to track is to turn on SQL Trace mode on ODBC connections so you can see the exact SQL it is sending to the server.

Something else you can do is modify the trigger to insert into an audit table so you know which parts of the trigger is run.
Feb 5 '16 #2
Seth Schrock
2,965 Expert 2GB
I actually just figured it out. Here is what I had:
Expand|Select|Wrap|Line Numbers
  1. ALTER TRIGGER [Customer].[AddPersonServicesList] 
  2.    ON  [Customer].[AuthorizedPeople]
  3.    AFTER INSERT
  4. AS 
  5.  
  6. DECLARE @PersonID int
  7. DECLARE @CustID int
  8.  
  9. BEGIN
  10.     -- SET NOCOUNT ON added to prevent extra result sets from
  11.     -- interfering with SELECT statements.
  12.     SET NOCOUNT ON;
  13.  
  14.     -- Insert statements for trigger here
  15.  
  16.     --Get inserted Customer ID
  17.     SELECT @PersonID = AuthPersonID_pk, @CustID = CustomerID_fk FROM inserted
  18.  
  19.     --Add related records to Customer Services
  20.     INSERT INTO Customer.PersonServices (AuthPersonID_fk, ServiceID_fk, Allowed)
  21.     SELECT @PersonID, ServiceID_fk, 0 FROM Customer.CustomerServices
  22.     WHERE CustID_fk = @CustID And Used = 1
  23.  
  24. END
The problem was when I was inserting the new record, CustomerID_fk was null and then I would use an UPDATE query to insert it later (long story). I have since fixed it so that I'm using a default value so that the customerID is there when the record is inserted and now the trigger runs perfectly.

Is there a way to see in SQL Profiler what values are being used in the variables? I'm able to see each statement of the trigger being ran, but the @CustID and @PersonID variables just show the names and not the values.
Feb 5 '16 #3
Rabbit
12,516 Expert Mod 8TB
Sorry, I'm not sure about SQL profiler, I haven't used it before though I think our DBA's use it.
Feb 6 '16 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Ford Desperado | last post by:
I've been reading the docs and playing around, but I'm still not getting the difference. For instance, create table a(i int check(i>0)) create table a_src(i int) go create unique index ai on...
0
by: Bill Smith | last post by:
I am looking for an example 'after insert' trigger that performs an update to a column in the master table. For example, I have an 'orders' table that contains a 'PartNum' column. I would like to...
1
by: ibrettferguson | last post by:
Nothing fancy; just a trigger on a sharepoint table that supposed to write a record to another SQL table. set ANSI_NULLS ON set QUOTED_IDENTIFIER ON go ALTER TRIGGER ON .
2
by: mayankaswal | last post by:
I am trying to create a AFTER INSERT Trigger. I created it and it worked for one record. But when I am trying to input multiple inserts it gives me error even on my insert statement. I am sure the...
2
by: wugon.net | last post by:
Problem: after inser trigger encounter error sql0348 Env:db2 v8 + fp 13 + win xp Description: we build two after insert triggers DB2.TRG1, DB2.TRG2 on base table DB2.TEST1, insert data into...
1
by: Stout | last post by:
Is it possible to create a trigger in one database, that after an insert, will update a database on a different server? If so, how would I do this? Thanks. Bill
2
by: gimme_this_gimme_that | last post by:
I'm using DB2 8.1. Suppose table foo has columns name and lname: create table foo (name as varchar(200), lname as varchar(200)); Write a trigger that inserts the lower case value of name...
1
by: ravishna | last post by:
My question is After inserting a row,I need to update some of the columns.How can I do with the after insert trigger. See the codings below . CREATE OR REPLACE TRIGGER order_id_trg_upd after...
1
by: Sitakanta Raula | last post by:
I have two tables reservation and flightdetails i want to create a after insert trigger show that when i will insert a seatno in reservation table it should show the updated seatno in flight detail...
1
by: hima parekh | last post by:
i have already insert data and delete manualy but whenever i insert new data at that time i want arrange data in sequence as per id number,but now if insert data that data append at last but i want...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.