When you think ASP, think...
Recent Articles
All Articles
ASP.NET Articles [1.x] [2.0]
ASPFAQs.com
Message Board
Related Web Technologies
User Tips!
Coding Tips
Search

Sections:
Book Reviews
Sample Chapters
Commonly Asked Message Board Questions
Headlines from ASPWire.com
JavaScript Tutorials
MSDN Communities Hub
Official Docs
Security
Stump the SQL Guru!
Web Hosts
XML Info
Information:
Advertise
Feedback
Author an Article
Technology Jobs

















internet.com
IT
Developer
Internet News
Small Business
Personal Technology
International

Search internet.com
Advertise
Corporate Info
Newsletters
Tech Jobs
E-mail Offers
ASP ASP.NET ASP FAQs Message Board Feedback ASP Jobs
Print this page.

Windows Systems Administrator
Jupitermedia
US-CT-Darien

Justtechjobs.com Post A Job | Post A Resume

The SQL Guru Answers your Questions...


I heard a rumor that I'm supposed to send you weird sql questions in order to make your brain explode so here goes.

After poking around with foreign key and primary key constraints, a trigger I had wouldn't work properly. Here's the basic structure... In sql server 6.5 and ASP:

I had a main table, let's call it computers, which contained a unique id (serial number) as primary key.

I had a related table, let's call it oldNames, which contained a listing of old "servernames" for servers, the structure being ID (serial number in computers) and oldName.

I made a trigger so that any time the Name field of computers was changed, it would insert a row into oldNames with the old name.

This is all fine and dandy, but here's the real stinker. In building the command to update a record in computers on my ASP page, I had inadvertently included serialnumber as a field to update (I was iterating through the fieldnames so I didn't have to type in update computers set field1=Request(field1)) for each of the 50 or so fields. So the query was updating the serialNumber to it's current value, kind of useless but oh well.

Ok so what? well here's the weird thing: the sql command would run without an error, but the trigger I had created would not be called even though I had changed the name field! I took out the serialnumber=x portion of the query/command and suddenly the trigger is fired.

I could plug in some code here, but to make a long story short I ended up just excluding serial number, and everything is fine. My question is, why the heck wasn't the trigger firing when I included the serial number? It had referential integrity enforced by way of a foreign key, so if there was a problem there, you would think it would spit an error. Very odd!

This is certainly a weird one. Any time you encounter something like this, it is usually best to make sure you're using the latest service pack.

There are a fair number of problems using triggers, especially using triggers with DRI constraints. Without looking at your code, it's hard to tell what the problem might be. However, you may want to check out knowledge base article Q138763. If you use the UPDATE() function in your trigger, it may not fire.

Also, remember that constraints are handled before triggers, so a trigger won't fire if a referential integrity constraint (or any other constraint, for that matter) is violated.

Hope this helps!

Sean


Read Other SQL Guru Questions


Windows Internet Technology | ASP.NET [1.x] [2.0] | ASPMessageboard.com | ASPFAQs.com | Advertise | Feedback | Author an Article



JupiterOnlineMedia

internet.comearthweb.comDevx.commediabistro.comGraphics.com

Search:

Jupitermedia Corporation has two divisions: Jupiterimages and JupiterOnlineMedia

Jupitermedia Corporate Info


Legal Notices, Licensing, Reprints, & Permissions, Privacy Policy.

Advertise | Newsletters | Tech Jobs | Shopping | E-mail Offers

Solutions
Whitepapers and eBooks
Microsoft Article: HyperV-The Killer Feature in WinServer ‘08
Avaya Article: How to Feed Data into the Avaya Event Processor
Microsoft Article: Install What You Need with Win Server ‘08
HP eBook: Putting the Green into IT
Whitepaper: HP Integrated Citrix XenServer for HP ProLiant Servers
Intel Go Parallel Portal: Interview with C++ Guru Herb Sutter, Part 1
Intel Go Parallel Portal: Interview with C++ Guru Herb Sutter, Part 2--The Future of Concurrency
Avaya Article: Setting Up a SIP A/S Development Environment
IBM Article: How Cool Is Your Data Center?
Microsoft Article: Managing Virtual Machines with Microsoft System Center
HP eBook: Storage Networking , Part 1
Microsoft Article: Solving Data Center Complexity with Microsoft System Center Configuration Manager 2007
MORE WHITEPAPERS, EBOOKS, AND ARTICLES
Webcasts
Intel Video: Are Multi-core Processors Here to Stay?
On-Demand Webcast: Five Virtualization Trends to Watch
HP Video: Page Cost Calculator
Intel Video: APIs for Parallel Programming
HP Webcast: Storage Is Changing Fast - Be Ready or Be Left Behind
Microsoft Silverlight Video: Creating Fading Controls with Expression Design and Expression Blend 2
MORE WEBCASTS, PODCASTS, AND VIDEOS
Downloads and eKits
Sun Download: Solaris 8 Migration Assistant
Sybase Download: SQL Anywhere Developer Edition
Red Gate Download: SQL Backup Pro and free DBA Best Practices eBook
Red Gate Download: SQL Compare Pro 6
Iron Speed Designer Application Generator
MORE DOWNLOADS, EKITS, AND FREE TRIALS
Tutorials and Demos
How-to-Article: Preparing for Hyper-Threading Technology and Dual Core Technology
eTouch PDF: Conquering the Tyranny of E-Mail and Word Processors
IBM Article: Collaborating in the High-Performance Workplace
HP Demo: StorageWorks EVA4400
Intel Featured Algorhythm: Intel Threading Building Blocks--The Pipeline Class
Microsoft How-to Article: Get Going with Silverlight and Windows Live
MORE TUTORIALS, DEMOS AND STEP-BY-STEP GUIDES