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

Trying to understand triggers

JA
Hi,

Newbie here. I have a mailing list program that I really like. I also have a
new membership program. The membership program has mailing list signups
built-in, but it isn't nearly as robust as the stand-alone mail program.

If someone signs up for a newsletter when they register (membership
program), can a "trigger" in SQL Server put the same information into the
stand-alone program's tables? And when they remove or update their
lists/info? And vice-versa?

Is this what a "trigger" would do? And is it efficient?

Thanks,

JA

Jul 23 '05 #1
2 1400
JA (ja*****@kc.rr.com) writes:
Newbie here. I have a mailing list program that I really like. I also
have a new membership program. The membership program has mailing list
signups built-in, but it isn't nearly as robust as the stand-alone mail
program.

If someone signs up for a newsletter when they register (membership
program), can a "trigger" in SQL Server put the same information into the
stand-alone program's tables? And when they remove or update their
lists/info? And vice-versa?

Is this what a "trigger" would do? And is it efficient?


It isn't clear to me whether both these programs use SQL Server databases
or not. If they are, it could possibly be a simple affair. If only the
program that inserts is, it could still be doable, but be less simple and
less efficient.

A trigger is a piece of codes that executes once per *statement*. So
if you insert 20 rows, the trigger fires once, and in the virtual
table "inserted" you have a copy of the 20 inserted rows with that
you can handle just like any other rows. (Well, you can change them.)
For an UPDATE and DELETE statement, you also have a similar table
"deleted" which holds the deleted rows, or before-image in case of an
UPDATE.
--
Erland Sommarskog, SQL Server MVP, es****@sommarskog.se

Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techinf...2000/books.asp
Jul 23 '05 #2
The purpose of a trigger is to perform some action when a table is updated
with an INSERT, DELETE or UPDATE statement. Triggers are very powerful and
efficient but need to be used prudently. I've seen all sorts of weird,
complex and burdensome logic hiding away in triggers - stuff that has no
business being inflicted on the poor user every time he wants make an
update. Best keep triggers to fundamental business rules and basic data
manipulation that's essential for every transaction. If you don't need it to
happen within a transaction then it's probably best kept out of a trigger
unless the level of updates is quite small.

You also need to consider the implications for support and future
development. Suppose the DBA needs to update a table to perform an upgrade
or fix some problem. If the trigger is just used to implement an invariable
business rule then no harm is done. However, the more complex and involved
the trigger code the more likely it is to do something that might be
obstructive to fixing some special exceptional case or adding some new
functionality in the future. Selectively disabling a trigger is hard to do
in an operational system. Changing a trigger may mean changing lots of other
code that references that table.

Only you can decide if a trigger is appropriate for your needs but make sure
you study the docs first and understand the merits and demerits of using a
trigger versus alternative methods of copying data and implementing business
rules (procs, views, constraints, scheduled jobs, etc)

--
David Portas
SQL Server MVP
--
Jul 23 '05 #3

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..
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...
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...
2
by: Rahul | last post by:
I am trying the following thing in AJAX <atlas:ScriptManager ID="scriptmanager1" runat="Server" EnablePartialRendering="true" /> <asp:DropDownList ID="cmbBranchname" cssclass="Combostyle"...
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:
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
BarryA
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...
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
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
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
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...
0
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...

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.