ASP Shopping CartForum & BBS
  - all for $20 from CodeToad Plus!
  Home || ASP | ASP.Net | C++/C# | DHTML | HTML | Java | Javascript | Perl | VB | XML || CodeToad Plus! || RAM 
Search Site:

Home » ASP » Article

Creating an SQL Trigger

Article by:  Jeff Anderson  ( 1362 ) (3/11/2003)
Bookmark us now! Add to Favourites
Email a friend!Tell a friend
Summary: A beginners guide to creating a Trigger in SQL Server
Viewed: 320372 times Rating (235 votes): 
 2.6 out of 5
 Rate this Article  Read Comments  Post Comments

Creating an SQL Trigger (SQL Server 7/2000)

So what exactly is a trigger? Well, it's a piece of sql that is activitied when a certain event happens. A common usage is when a new record is added to a database, this triggers an action - for example, a new order triggers an email to the supplier. It can be very useful.

To relative SQL newbies triggers and stored procedures can seem a bit daunted, but you'll quickly see there's really nothing to them.

To create a trigger, go to the Enterprise Manager, and your database. Select the table that causes the event to happen, right click > All Tasks > Manage Triggers and select new from the drop down box.

Here we're going insert a new record into the table directory_update whenever a record is inserted into the directory table.

Select All Code

What this particular code does is inserts the latest record id - max(directory_id) - from the directory, and the current date, into the table directory_update. It does this whenever a new record is inserted into the directory.

I used something similar to this to create 'last updated' flags within a directory structure - but that's another article. For now, I hope that's been a useful introduction for you into the world of Triggers.

Useful Links

CodeToad Experts

Can't find the answer?
Our Site experts are answering questions for free in the CodeToad forums
Rate this article:     Poor Excellent
View highlighted Comments
User Comments on 'Creating an SQL Trigger'
ASP FilesystemObject
by Jeff Anderson
An introduction to the Filesystemobject
ASP GetTempName
by Jeff Anderson
Use the GetTempName method to create a randomly generated temporary file on the server.
ASP Format Date and Time Script
by Jeff Anderson
An ASP script showing the variety of date and time formats possible using the FormatDateTime Function.
ASP OpenTextFile
by Jeff Anderson
An introduction to the OpenTextFile Method of the FileSystemObject
Email validation using Regular Expression
by Jeff Anderson
Using regular expression syntax is an exellent way to thoroughly validate an email. It's possible in ASP.
Add or Subtract Hours in SQL or ASP using DateAdd
by Jeff Anderson
A beginners guide to using the SQL DATEADD function to add or subtract hours. Particularly useful when setting the time displayed on the ASP page to a different time zone (eg when the server is in the US, and the site is for a UK audience).
The asp:radiobutton and asp:radiobuttonlist control
by David Sussman, et al
In HTML, radio buttons are used when we need to make multiple sets of choices available, but we want the user to select only one of them.
The asp:checkbox and asp:checkboxlist control
by David Sussman, et al
Checkboxes are similar to radio buttons, and in HTML, they were used to allow multiple choices from a group of buttons.
Concatenate strings in sql
by Jeff Anderson
A brief introduction to concatenating strings in an sql query (using SQL server or access databases).
ASP FileExists
by Jeff Anderson
An introduction to the FileExistsMethod of the FileSystemObject

Recent Forum Threads
• Run a program both on windows and linux
• VERO.SurfCAM.v2014
• Schlumberger.Petrel.V2013.2
• Petrel.V2013.2
• Altair.HyperWorks.v12
• VoluMill.v6.1
• VoluMill.NEXION.6
• VERO.SurfCAM.v2014
• Schlumberger.Petrel.V2013.2

Recent Articles
ASP GetTempName
Decode and Encode UTF-8
ASP GetFile
ASP FolderExists
ASP FileExists
ASP OpenTextFile
ASP FilesystemObject
ASP CreateFolder
ASP CreateTextFile
Javascript Get Selected Text

© Copyright 2001-2015