|
-
Nov 3rd, 2022, 01:32 PM
#1
Thread Starter
PowerPoster
[RESOLVED] SQL 2005 trigger glitch?
Hey, wondering if any fellow old-schoolers ran into this issue, and if this is a SQL 2005 glitch or whether I did something wrong.
This is really a "post-mortem", as I seem to have fixed the issue.
So I am maintaining a legacy app for one of my clients - VB6 with SQL 2005 backend.
A requested application update called for adding 4 new fields to a particular table.
Did the usual ALTER TABLE ADD ... and as expected, expanding the table's columns shows the 4 new fields at the end.
The code uses in-line SQL, and btw it uses this alternative INSERT/SELECT syntax: "INSERT tablename SELECT col1 = value, col2 = value, etc."
I happened to place the code for new fields above the last one, not at the very end - i.e.:
The existing code had:
INSERT tablename SELECT col1 = value, col2 = value, ... coln = value
My modification initially was:
INSERT tablename SELECT col1 = value, col2 = value, ... newcol1 = value, newcol2 = value, newcol3 = value, newcol4 = value, coln = value
Shouldn't matter, right?
Well, there is an insert trigger on this table that will prevent the insert if "coln" has a value it doesn't like.
And when the insert is attempted, the trigger throws an exception because it thinks coln has an invalid value.
Yet a Debug.Print of the SQL INSERT statement shows that the columns have the right values.
Head-scratcher...
So, just for kicks, I changed my SQL to:
INSERT tablename SELECT col1 = value, col2 = value, ... coln = value, newcol1 = value, newcol2 = value, newcol3 = value, newcol4 = value
And what do you know? - the trigger was happy and did not throw an exception, and all appeared well.
Any thoughts on this? Was there a glitch in SQL 2005 triggers that was corrected later?
Last edited by BruceG; Nov 5th, 2022 at 03:14 AM.
Reason: Resolved
"It's cold gin time again ..."
Check out my website here.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|