473,513 Members | 2,275 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Create triggers for one table to update audit table with date and time and name

14 New Member
I have one table Products with 10 columns on which need create trigger(s) to update changes in data in another table Products_audit which has 10 same columns plus two additional columns "Date" и "User" where need to insert date and name of user who made changes.
Mar 25 '13 #1
6 1884
Escargot18
3 New Member
The way I do it is to create a form and open the table in datasheet view in the form. It sill looks like the table to users, but you can add an after update event to move the data along with the data and user infor into the new table. I'm sure there are better ways to do this, but this way works.
John
Mar 25 '13 #2
Rabbit
12,516 Recognized Expert Moderator MVP
And what trouble are you having creating your trigger?
Mar 25 '13 #3
gelezniyden
14 New Member
I've tried somthing like following:

Expand|Select|Wrap|Line Numbers
  1. CREATE TRIGGER Super 
  2.  
  3. ON Products 
  4.  
  5. AFTER INSERT, UPDATE
  6.  
  7. AS
  8.  
  9. UPDATE Product_audit (Column1,Column2, Column3, ... )
  10.  
  11. SELECT (Column1,Column2,Column3,...)
  12.  
  13. FROM Products
Receiving following: Server: Msg 170, Level 15, State 31, Procedure Super, Line 20
Line 20: Incorrect syntax near '('.
Server: Msg 170, Level 15, State 1, Procedure Super, Line 24
Line 24: Incorrect syntax near ','.

I'm not so strong else in triggers creation could you please correct me I'd like to know where was I wrong ?
Mar 26 '13 #4
Rabbit
12,516 Recognized Expert Moderator MVP
You have no line 20 and no line 24 in the code you posted. Unless you post your actual code, there's no way to tell you where the code went wrong.
Mar 26 '13 #5
gelezniyden
14 New Member
Created following trigger:

Expand|Select|Wrap|Line Numbers
  1. CREATE TRIGGER Super1
  2.  
  3.     ON Products
  4.  
  5.     AFTER Update
  6.  
  7.     AS
  8.  
  9.     BEGIN
  10.  
  11.     DECLARE @ProductID int,
  12.              @ProductName nvarchar,
  13.             @SupplierID varchar,
  14.             @CategoryID int,
  15.             @QuantityPerUnit int,
  16.             @UnitPrice money,
  17.             @UnitsInStock smallint,
  18.             @UnitsOnOrder smallint,
  19.             @ReorderLevel smallint,
  20.             @Discontinued bit
  21.  
  22.  
  23.     SELECT @ProductID=ProductID,
  24.            @ProductName=ProductName, 
  25.            @SupplierID=SupplierID,
  26.            @CategoryID=CategoryID,
  27.            @QuantityPerUnit=QuantityPerUnit, 
  28.            @UnitPrice=UnitPrice,
  29.            @UnitsInStock=UnitsInStock, 
  30.            @UnitsOnOrder=UnitsOnOrder, 
  31.            @ReorderLevel=ReorderLevel, 
  32.            @Discontinued=Discontinued  
  33.  
  34.    FROM Products
  35.  
  36.  
  37.  
  38.    UPDATE Products_audit  
  39.  
  40.    SET     ProductID=@ProductID,
  41.            ProductName=@ProductName, 
  42.            SupplierID=@SupplierID,
  43.            CategoryID=@CategoryID,
  44.            QuantityPerUnit=@QuantityPerUnit, 
  45.            UnitPrice=@UnitPrice,
  46.            UnitsInStock=@UnitsInStock, 
  47.            UnitsOnOrder=@UnitsOnOrder, 
  48.            ReorderLevel=@ReorderLevel, 
  49.            Discontinued=@Discontinued
  50.  
  51.  
  52.     END
  53.  
Could anybody take a look at that and correct me if I was wrong anywhere ?
Mar 27 '13 #6
Rabbit
12,516 Recognized Expert Moderator MVP
This code can't be the exact code that created those error messages you posted earlier. There's no parentheses anywhere and your error message said there was an error by a parentheses.

At this point, you have to redescribe your problem because it's no longer the same problem you wanted help with.

One thing that is wrong that I noticed right off the bat is that you're setting your values using every row in the table. And you're updating every row in your audit table. Pretty sure you didn't mean to do that.
Mar 27 '13 #7

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

Similar topics

0
6935
by: Katuil Katuil | last post by:
Hello All: Have a problem that I have never seen before and have not found anything on technet on how to resolve it. I have a SQL Server 2000 server that I have created a new database. I then...
17
25875
by: Lapchien | last post by:
My table has a record called date/time - filled (not surprisingly) with a date and time. I can format the date in one query field, also the time, using format in an expression. My user wants me...
0
1881
by: EKL | last post by:
Hi, I'm making a sort of Customer and Orders database in MS Access 2003. My problem is that I wish to update the table "tblTransaction" based on changes made in the table "tblOrderDetails"....
2
4403
by: Cheekie | last post by:
I have an Access table that has a Date/Time stamp. I am only looking for records that are either before 8am or after 10pm....is there anyway to query or break this data out?
2
6072
by: john | last post by:
From an Excel-import I have an access table with a datetime field of wich both date and time are entered. I've set the field's notation properties to Short Date. When I view the table in tableview...
3
6260
by: MarcJoseph | last post by:
I have a database that is shared my multiple users who enter and update records on a weekly basis. Is there a way I can add a field to my main data table that will automatically generate the...
0
1472
by: rdraider | last post by:
I have an audit table that tracks changes to inventory items. I am trying to find the first change in avg_cost per item. The table will contain 1 row for the before record and another row for the...
2
2229
by: tomash | last post by:
Hi! I ve got two tables in Access 2007. I want to update a field of DataTable from another table, DataSumTable when two of their fields equals. ( the fields : Name and Period) I tried this...
3
7548
by: tennytitansgeek | last post by:
I am working on an update trigger that updates certain columns in table two when table one is updated. Example If Column a, b, or c is updated in table 1, I need those to be updated in table 2-...
9
5257
by: JeremyI | last post by:
I am writing code to import assessment information about a building from an Excel file (populated by a mobile interviewer on a laptop) into an Access database. With much trial and error, I've hit...
0
7265
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
7171
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
7541
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5693
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5098
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3240
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1607
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
807
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
461
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.