Wrox Programmer Forums
Go Back   Wrox Programmer Forums > SQL Server > SQL Server 2000 > SQL Server 2000
|
SQL Server 2000 General discussion of Microsoft SQL Server -- for topics that don't fit in one of the more specific SQL Server forums. version 2000 only. There's a new forum for SQL Server 2005.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the SQL Server 2000 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old November 12th, 2006, 11:33 AM
Registered User
 
Join Date: Nov 2006
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default Trigger question for columns with text in MS sql s

Trigger question for columns with text in MS sql server 2000

All,

I am adding audit trail to the database using sql server 2000.
I am being forced to use Instead of Insert trigger for tables that have text columns as sql server 2000 does not support for/after triggers for text,ntext and image columns in the table.

I want to insert the new row on the same table and then update the audit table with those values. It is just updating the audit table and the column containing the base table primary key is having the value 0. Also, It does not insert the row into the base table.
But it errors out with the message "Instead of trigger does not support direct recursion".

Example -- psuedocode
Table A (column1 int Identity(1,1) (primary key with identity), column2 varchar(10), column3 text)
Table Aaudit (to store the audit trail)
Create trigger trinsTable
instead of insert on Table A
as
begin transaction
Select into #inserted from inserted
Exec (Alter table #inserted add auditdate datetime, add audituser varchar(10))
Exec (insert TableA (column 2, column 3) Select column 2, column 3 from #inserted)
Exec (insert Table Aaudit select * from inserted)
.....
end

What is the workaround?

Also, I am considering only single row insert at the present time. There may be other tables that may have multiple row inserts. Do I have to use cursors or anything else for that?

I also tried using the for/after trigger with JOIN on the base table with the text column and that did not work.

I am running out of options and I am willing to try any suggestions!

Thanks in advance for your time

Rob
 
Old November 12th, 2006, 03:21 PM
Friend of Wrox
 
Join Date: Oct 2006
Posts: 475
Thanks: 0
Thanked 9 Times in 9 Posts
Default

Heh... that's why I never use Text, NText, or Image in SQL Server 2000...

Just a couple of suggestions that don't really fix your exact problem... sorry for the deviation...

My question would be, do you really need a text column? Do you have any text that is over 8000 characters? If not, convert the column to VARCHAR(8000) and store it in a sister table along with the primary key of the older sister.

Even if the text is over 8000, it could be "sliced" into multiple 8000 character slices and stored in a sister table, as well.

Another alternative is to store just a file name instead of text. The file name would point to the file containing the text.

Other than that, I appologize for being of no basic use to solve this problem... I just don't use the "forbidden 3" in my databases.

--Jeff Moden





Similar Threads
Thread Thread Starter Forum Replies Last Post
Create Trigger,Procedure, Function in MS-Access.? navneet_chauhan10 SQL Language 1 December 27th, 2007 09:33 AM
MS ACCESS 2003 FRONTEND AND MS SQL SERVER 2005 DB mohankumar0709 SQL Server 2005 3 March 23rd, 2007 12:48 AM
Question for Trigger sbank SQL Language 2 March 1st, 2007 06:45 AM
Block some columns from update in MS DataGrid zee_ahmed2002 Pro VB 6 1 October 13th, 2004 07:52 AM
Audit Trigger on Row with Text Column keithmdw SQL Language 5 June 28th, 2004 04:17 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.