473,769 Members | 5,885 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 1418
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****@sommarsk og.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
6634
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
2539
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 cumbersome. Are there better tools for creating and managing triggers? Mark Flippin
4
2718
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 add insert and delete triggers to each of the underlying tables. The triggers modify a different set of tables in the same database as the view (different than the underlying table). The problem is those triggers aren't fired when inserting or...
5
2453
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 functions, then drop and recreate the user defined functions, then recreate all the views and triggers. I don't imiagine I'm the first person who needed to do this, and I don't have a lot of db2 experience, so I wanted to see if there is a common or...
0
4944
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 rules for the new project. but, i plan to use a lot of triggers and functions in this project, but I'm confused! I know that triggers call already created functions. But for tracking i must be able to associate these 2 different object
2
2425
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" runat="server" /> <br/> <atlas:UpdatePanel ID="panel1" runat="server" UpdateMode="Conditional" > <ContentTemplate>
0
8330
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 declare a number(2); begin
0
4497
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 executed on an event in the database. The event is related to a particular data manipulation of a table such as inserting, deleting or updating a row of a table. Triggers may be used : 1.To implement complex business rule, which cannot be...
4
5746
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
9423
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
10211
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
9863
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...
0
8872
agi2029
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5299
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5447
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3959
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 we have to send another system
2
3562
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2815
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.