473,785 Members | 2,396 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Please, a SQL trigger question!!

Hi! I have no experience at all using triggers, and I don't even know
very well SQL server. I hope someone can help me with the folling: I
need to know if it is possible to implement a trigger that monitors
the value of an specific field, and when it changes the value from 0
to 1 it should update the value of another field in another table but
after some arithmetic operations. The arithmetics operations involves
data within the same database.

Is this can be made using triggers and stored procedures?
Jul 20 '05 #1
3 6200
Of course it can!

Look for this key words in SQL BOL: triggers, after, 'if update', inserted tables, deleted tables.

--
Dean Savovic
www.teched.hr
"Alejandro" <al************ @yahoo.com.mx> wrote in message news:85******** *************** ***@posting.goo gle.com...
Hi! I have no experience at all using triggers, and I don't even know
very well SQL server. I hope someone can help me with the folling: I
need to know if it is possible to implement a trigger that monitors
the value of an specific field, and when it changes the value from 0
to 1 it should update the value of another field in another table but
after some arithmetic operations. The arithmetics operations involves
data within the same database.

Is this can be made using triggers and stored procedures?

Jul 20 '05 #2
Yes it can.

Personally Id recommend against it as I believe triggers to be the
very personal work of satan.

They can be quite slow - specially on heavy load tables, and have a
bad habit of hiding away and getting lost when you move the
database...

But yes - sure you can do that.

al************@ yahoo.com.mx (Alejandro) wrote in message news:<85******* *************** ****@posting.go ogle.com>...
Is this can be made using triggers and stored procedures?

Jul 20 '05 #3
Hi

SQL server does not have the ability to create a trigger on an
individual column
but you can check that a column has changed within a trigger but
either comparing the values for that column in the inserted and
deleted or possibly the COLUMNS_UPDATED clause (Although a column can
be updated it may not be to a different value!).

See the "CREATE TRIGGER" topic in Books Online or at:
http://msdn.microsoft.com/library/de...eate2_7eeq.asp

The examples given in this topic also who how to update other tables.

HTH

John

al************@ yahoo.com.mx (Alejandro) wrote in message news:<85******* *************** ****@posting.go ogle.com>...
Hi! I have no experience at all using triggers, and I don't even know
very well SQL server. I hope someone can help me with the folling: I
need to know if it is possible to implement a trigger that monitors
the value of an specific field, and when it changes the value from 0
to 1 it should update the value of another field in another table but
after some arithmetic operations. The arithmetics operations involves
data within the same database.

Is this can be made using triggers and stored procedures?

Jul 20 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
1167
by: MrMike | last post by:
I'm building this trigger and an error message is appearing which says: " Error 170: Incorrect Syntax: Line 6 near "=". Could someone please help me understand why this error is occuring? Thanks. Create Trigger AvailableLogFootage on tblLogs FOR UPDATE As Begin UPDATE UnDesignatedFootage = tblBundles.CurrentFootage
4
2136
by: Jules Alberts | last post by:
Hello everyone, I'm working on a tiny trigger function that needs to ensure that all values entered in a field are lowercase'd. I can't use pl/pgsql because I have a dozen different columns (with different names) that need a trigger that does this and pl'pgsql can't expand variable names to fieldnames. Writing a dozen functions (one per columnname) is /way/ too blunt so I tried pl/tcl (which I don't know): ...
1
4462
by: Barbara Lindsey | last post by:
I am a postgres newbie. I am trying to create a trigger that will put a copy of a record into a backup table before update or delete. As I understand it, in order to do this I must have a function created to do this task. The function I am trying to create is as follows: CREATE FUNCTION customer_bak_proc(integer) RETURNS boolean as 'INSERT INTO customer_bak (SELECT * from customer where id = $1 )' LANGUAGE 'SQL';
4
4184
by: Alexander Pope | last post by:
I am using db2 udb v8.2 AIX I have created trigger, however I am not confident it meets industry standards. If I make it fail, I cant tell from the message where it is failing. what can I add to trap the errors properly? CREATE TRIGGER myschema.t1_upd_t AFTER UPDATE OF dt ON myschema.t1 REFERENCING NEW AS N
3
4953
by: ChrisN | last post by:
Hello all, I have a quick question. I'm using a C# object to commit new rows to a database. In the database I have an INSERT Trigger watching values come in. If the record to be committed fails the trigger's test, the trigger rolls back the INSERT command and no changes are made to the database. As far as my object is concerned, the transaction went through either way (no matter what the trigger did). What I need is for the object...
1
1569
by: Daniel Schuchardt | last post by:
Hi list, i'm a bit confused. I have a table with a trigger after insert. It is possible that this trigger will do inserts in the same table, but is the after insert trigger fired again in this case? (I would need this) e.g. USER INSERT
1
1221
by: majastic | last post by:
Hello all, I have a database question for you. I have a table in SQL 2000 that I think I need a trigger for. I'm tring to get the trigger to take the last two numbers from one field and replace the number in another field on the same table, see my example that follows: Before Trigger Table: Job J_User1: 0122567801 J_JobType: 20
10
3574
by: JohnO | last post by:
Hi All, This question is related to iSeries V5R4 and db2. I want to implement an AFTER DELETE trigger to save the deleted rows to an archive table, I initially defined it as a FOR EACH STATEMENT trigger that would insert all the deleted rows in one operation like this: CREATE TRIGGER MyTable_TD
0
1878
by: David Robertson | last post by:
Hello, I have a request that I thought was straightforward and would be fairly simple. After many hours of research and trying various triggers, procedures and variables, I have not been able to find a solution. I need to evaluate a timestamp column to be in an acceptable range on insert/update of a table. If the value is out of the acceptable range, I need to update it to an acceptable value and then write a record into an audit table...
0
9645
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9481
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10341
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10155
jinu1996
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10095
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9954
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7502
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
2
3656
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2881
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.