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.
6 1884
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
Rabbit 12,516
Recognized Expert Moderator MVP
And what trouble are you having creating your trigger?
I've tried somthing like following: - CREATE TRIGGER Super
-
-
ON Products
-
-
AFTER INSERT, UPDATE
-
-
AS
-
-
UPDATE Product_audit (Column1,Column2, Column3, ... )
-
-
SELECT (Column1,Column2,Column3,...)
-
-
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 ?
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.
Created following trigger: - CREATE TRIGGER Super1
-
-
ON Products
-
-
AFTER Update
-
-
AS
-
-
BEGIN
-
-
DECLARE @ProductID int,
-
@ProductName nvarchar,
-
@SupplierID varchar,
-
@CategoryID int,
-
@QuantityPerUnit int,
-
@UnitPrice money,
-
@UnitsInStock smallint,
-
@UnitsOnOrder smallint,
-
@ReorderLevel smallint,
-
@Discontinued bit
-
-
-
SELECT @ProductID=ProductID,
-
@ProductName=ProductName,
-
@SupplierID=SupplierID,
-
@CategoryID=CategoryID,
-
@QuantityPerUnit=QuantityPerUnit,
-
@UnitPrice=UnitPrice,
-
@UnitsInStock=UnitsInStock,
-
@UnitsOnOrder=UnitsOnOrder,
-
@ReorderLevel=ReorderLevel,
-
@Discontinued=Discontinued
-
-
FROM Products
-
-
-
-
UPDATE Products_audit
-
-
SET ProductID=@ProductID,
-
ProductName=@ProductName,
-
SupplierID=@SupplierID,
-
CategoryID=@CategoryID,
-
QuantityPerUnit=@QuantityPerUnit,
-
UnitPrice=@UnitPrice,
-
UnitsInStock=@UnitsInStock,
-
UnitsOnOrder=@UnitsOnOrder,
-
ReorderLevel=@ReorderLevel,
-
Discontinued=@Discontinued
-
-
-
END
-
Could anybody take a look at that and correct me if I was wrong anywhere ?
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.
Sign in to post your reply or Sign up for a free account.
Similar topics |
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...
|
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...
|
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"....
|
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?
|
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...
| |
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...
|
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...
|
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...
|
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-...
|
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...
|
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,...
| |
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...
|
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...
|
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,...
|
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...
|
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...
|
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 ...
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
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...
| |