473,387 Members | 1,290 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,387 software developers and data experts.

New to Triggers

I'm trying to get a grasp on triggers, and that brings me here. I
have a series of tables with a 'Modby' field and a 'ModDate' field.
In the Default Value Property I have the (suser_sname()) and
(GetDate()) functions. Is what I'm after is a trigger that will
update these fields, for a specific record, if/when the record has
been modified.

I appreciate your help, and Thanks in advance.
Jul 20 '05 #1
6 2071
If you already have defaults, there is no need for triggers. You can use the
DEFAULT keyword in your INSERT & UPDATE DMLs like:

INSERT tbl (..., Modby, ModDate) VALUES (..., DEFAULT, DEFAULT);

UPDATE tbl
SET ....
ModBy = DEFAULT,
ModDate = DEFAULT
WHERE ...;

--
-- Anith
( Please reply to newsgroups only )
Jul 20 '05 #2
First, thanks for your reply. Second, if I'm correct, the default
value only applies to new records should no value be pleased in that
field. Also, what differentiates one record from the whole table? I
need to only update the User and Date for the record that's been
updated.
"Anith Sen" <an***@bizdatasolutions.com> wrote in message news:<FN******************@newsread2.news.atl.eart hlink.net>...
If you already have defaults, there is no need for triggers. You can use the
DEFAULT keyword in your INSERT & UPDATE DMLs like:

INSERT tbl (..., Modby, ModDate) VALUES (..., DEFAULT, DEFAULT);

UPDATE tbl
SET ....
ModBy = DEFAULT,
ModDate = DEFAULT
WHERE ...;

Jul 20 '05 #3
>> Second, if I'm correct, the default value only applies to new records
should no value be pleased in that field. <<

No, you can use it in your UPDATE statement as I have shown in my post.
Also, what differentiates one record from the whole table? <<


You have to use a proper WHERE clause to identify the rows which are
affected by the UDPATE statement.

--
-- Anith
( Please reply to newsgroups only )
Jul 20 '05 #4
Anith,
I appreciate you working with me on this, but I need for you to dumb
it down a little further. If I'm trying to update a record that has
been changed, what kind of where condition would I be using? What
signifies that the record has changed?
"Anith Sen" <an***@bizdatasolutions.com> wrote in message news:<4T******************@newsread1.news.atl.eart hlink.net>...
Second, if I'm correct, the default value only applies to new records should no value be pleased in that field. <<

No, you can use it in your UPDATE statement as I have shown in my post.
Also, what differentiates one record from the whole table? <<


You have to use a proper WHERE clause to identify the rows which are
affected by the UDPATE statement.

Jul 20 '05 #5
Dave,

Actually I was suggesting you, NOT to use a trigger at all, instead use the
DEFAULT keyword in your INSERT & UPDATE statements directly. So when you do
your UDPATE, you simply do:

UPDATE tbl
SET ....
ModBy = DEFAULT,
ModDate = DEFAULT
WHERE ...;

If you have a WHERE clause it will limit the number of rows based on the
WHERE clause condition & the DEFAULT will be effective for those rows only.
If you do not use a WHERE clause, all rows are updated & the DEFAULT is
applicable for all the rows in the table. Is that making sense?

--
-- Anith
( Please reply to newsgroups only )
Jul 20 '05 #6
Anith,

1.) Will the statement that you've suggested work as is? In other
words, copy & paste?

2.) Does that update all records or just the one being edited?

NOTE TO AUTHORS: Someone needs to write a book..."Triggers for Geek
Wanna-be's"

Thanks for your help Anith.
"Anith Sen" <an***@bizdatasolutions.com> wrote in message news:<yO*******************@newsread2.news.atl.ear thlink.net>...
Dave,

Actually I was suggesting you, NOT to use a trigger at all, instead use the
DEFAULT keyword in your INSERT & UPDATE statements directly. So when you do
your UDPATE, you simply do:

UPDATE tbl
SET ....
ModBy = DEFAULT,
ModDate = DEFAULT
WHERE ...;

If you have a WHERE clause it will limit the number of rows based on the
WHERE clause condition & the DEFAULT will be effective for those rows only.
If you do not use a WHERE clause, all rows are updated & the DEFAULT is
applicable for all the rows in the table. Is that making sense?

Jul 20 '05 #7

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

Similar topics

11
by: raulgz | last post by:
I need audit triggers that change columns value in the same record that fire trigger. I need how to do.. Thanks..
1
by: jason_s_ford | last post by:
I have several sql server databases that were recently moved to a new server. In the process of migrating the databases, any triggers and constraints attached to tables were removed on accident. ...
4
by: Mark Flippin | last post by:
I'm just starting to use triggers in my databases and find the support in Enterpise Manager lacking. Using Enterprise Manager and Query Analyzer you can maintain the triggers, but it's...
1
by: tim.pascoe | last post by:
I'm trying to generate scrips for a database, and everything so far has worked fine, except for the triggers. When I try and script existing triggers, all I get is a blank file - no SQL script. I...
4
by: stacdab | last post by:
We have a partitioned view with 4 underlying tables. The view and each of the underlying tables are in seperate databases on the same server. Inserts and deletes on the view work fine. We then...
5
by: Bruce | last post by:
I have several user defined functions which are referenced in triggers and views. For software upgrades, I need to be able to drop the triggers and views which reference these user defined...
0
by: Bruno Lavoie | last post by:
Hello, i'm etablishing a naming convention for a new project under postgresql. For tables, sequences, views, that's ok! I used good naming conventions for this in the past and i'll keep these...
0
debasisdas
by: debasisdas | last post by:
trigger sample code Ex#10 ======================= INSTEAD OF TRIGGER ---------------------------------------- create or replace trigger mytrig instead of delete or insert or update on eview...
0
debasisdas
by: debasisdas | last post by:
This thread contains some useful tips/sample codes regarding TRIGGERS in oracle, that the forum members may find useful. TRIGGERS: =============== Database trigger is a PL/SQL block that is...
4
by: --CELKO-- | last post by:
I need to convert a bunch of DB2 triggers to Oracle. Is there any kind of tools for this?
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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,...
0
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 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.