I'm a newbee to the community and to writing sql. I would like to write a new trigger for some fields in a table I created and was hoping someone could help me. I know how to start a new tigger through enterprise manager, but it's the syntax that I'm not familiar with at all. Basically, I have three number fields for each particular ID. I want to add all these three fields up into a "total field" I would like to have a trigger to do the calculation when at least one of the three number fields is populated. Any ideas? Your help is very greatly appreciated. Thanks so much.
newsqler
10 3677
For the MySQL trigger syntax, and creating and dropping triggers, see Chapter 19. Triggers . Be aware that this works on MySQL 5.1 and up only!
Ronald :cool:
Thanks, I'll check this out. I'm sorry, I should have mentioned that I'm using SQL 2000. Will that make a difference? Thanks for your help.
Then you have asked your question in the wrong forum. Therefore I have shown you the MySQL information.
For SQL Server 2000 you must look in the appropriate forum. I will transfer this question to that forum now.
Ronald :cool:
For your task calculated field is the best choice: - create table #a
-
(
-
id int identity(1, 1),
-
val1 int not null default (0),
-
val2 int not null default (0),
-
val3 int not null default (0),
-
total as (val1 + val2 + val3)
-
)
-
-
insert #a default values
-
insert #a default values
-
insert #a default values
-
insert #a default values
-
-
select * from #a
-
update #a set val2=id
-
select * from #a
-
This is great, thank you so much for your help. So, using your code, I already have a table called 'TABLE1' and three fields in that same table 'FIELD1', 'FIELD2', 'FIELD3' that I want to sum into 'FIELD4'. How would I use your code with this scenario? Thanks again so much.
You should create FIELD4 as a calculated field. For your scenario it will be: - alter table TABLE1 drop column FIELD4
-
alter table TABLE1 add FIELD4 as (FIELD1 + FIELD2 + FIELD3)
I tried this out and got an error message. Here is the code and the error message I received:
code:
CREATE TRIGGER [name_of_trigger] ON [dbo].[table1]
FOR UPDATE
AS
alter table table1 drop column field4
alter table table1 add field4 as (field1 + field2 + field3)
error message:
odbc--update on a linked table 'dbo_table1' failed.
[microsoft][odbc sql server driver][SQL server] alter table drop column failed because column 'field4' does not exist in table 'table1' (#4924)
Any ideas? Thanks so much.
it should not be a trigger, just execute it once and that's all
However, I need it as a trigger because records will be changing all the time. the trigger would help us calculate the total of the three fields every time any of the fields change.
However, I need it as a trigger because records will be changing all the time. the trigger would help us calculate the total of the three fields every time any of the fields change.
A calculated field's value is dynamic and saves the overhead of rewriting the record every time. The calculated field will update itself as the values are added.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Fernand St-Georges |
last post by:
Hi,
can someone tell how to write a Trigger; I am familiar with Sybase Sql
Anywhere trigger syntax.
Actually I have three tables MEMBER, CONTRACT and PAYMENT
I need to update the MEMBER.BALANCE...
|
by: William F. O'Neill |
last post by:
Am using SQL Server 2000 on WINXP Pro. Have a requirement to change some
Oracle triggers to SQL 2000. I have modied this one Insert Trigger, but get
an error when I attempt to compile:
CREATE...
|
by: nosbtr1 |
last post by:
When a row gets modified and it invokes a trigger, we would like to be
able to update the row that was modified inside the trigger. This is
(basically) how we are doing it now:
CREATE TRIGGER...
|
by: coosa |
last post by:
I have a table:
----------------------------------------------------
CREATE TABLE CATEGORY (
CATEGORY_ID INTEGER IDENTITY(1,1) NOT NULL,
CATEGORY_NAME VARCHAR(40) NOT NULL,...
|
by: Bob Stearns |
last post by:
I am trying to create a duplicate prevention trigger:
CREATE TRIGGER is3.ard_u_unique
BEFORE UPDATE OF act_recov_date ON is3.flushes
REFERENCING NEW AS N
FOR EACH ROW MODE DB2SQL
WHEN...
|
by: Bob Stearns |
last post by:
I have two (actually many) dates in a table I want to validate on
insertion. The following works in the case of only one WHEN clause but
fails with two (or more), with the (improper?...
|
by: Axel |
last post by:
Hello,
I have detail sections in several subforms that are used to fill daily
order data per product. Each row contains textboxes for the weekdays
and a locked textbox (txtTotal) for the week's...
|
by: deepdata |
last post by:
Hi,
I am creating a trigger in DB2 express version.
When i use the following syntax to create trigger
CREATE TRIGGER USER_PK_TRIGGER
BEFORE INSERT On users
REFERENCING NEW As N
FOR EACH...
|
by: zachster17 |
last post by:
Hello all,
I have 2 tables (tblAddProviderProfessional and tblAddProvider). There are other tables such as tblAddProviderFacility and so forth. tblAddProvider is a table that has similar data...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
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...
| |