469,645 Members | 1,941 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,645 developers. It's quick & easy.

ntext and update/insert triggers

SQL Server 2000 : I have a series of tables which all have the same
structure. When any of these tables are modified I need to syncrhonise
all of those modifications with one other table wich is a sort of merge
of the individual tables with one extra column.

For most of these tables this is not a problem. The problem arrives
when one of the tables has an ntext column which obviously can not be
used in an update or insert trigger.

Here's an example of one of them:

CREATE TABLE tblImages(
ID INT IDENTITY(1,1) PRIMARY KEY,
Inventory nvarchar(8) NOT NULL,
Coll nvarchar(8) NOT NULL,
ImageFile nvarchar(128) NOT NULL,
ImageNotes ntext NULL,
TS timestamp NULL
CONSTRAINT U_Images UNIQUE NONCLUSTERED (ItemCode, Inventory, Coll,
ImageFile)

I then had created an update trigger which looked like this:

CREATE TRIGGER COLLNAME_UTRIGGER ON COLLNAME_Images
FOR UPDATE
AS
BEGIN
UPDATE tblImages SET
Inventory = inserted.Inventory,
Coll = 'COLLNAME',
ImageFile = inserted.ImageFileName,
FROM inserted INNER JOIN tblImages ON inserted.ItemCode =
tblImages.ItemCode AND
inserted.Invventory = tblImages.Invventory AND tblImages.Coll =
'COLLNAME' AND
inserted.ImageFileName = tblImages.ImageFile

UPDATE tblImages
SET ImageNotes=inserted.Notes
FROM inserted INNER JOIN tblImages ON inserted.ItemCode =
tblImages.ItemCode AND
inserted.Inventory= tblImages.Inventory AND tblImages.Coll =
'COLLNAME' AND
inserted.ImageFileName = tblImages.ImageFile
END " & vbCrLf)

The first update in my trigger, be it an update or insert trigger,
works fine. It crashes with the "Cannot use text, ntext or image
columns in the 'inserted' or 'deleted' tables." error in the second
part.

I have read various messages through the Internet on this and several
of them reference using INSTEAD OF triggers and views. I have never
used those before as this is my first work with SQL 2000. None of the
examples of INSTEAD OF triggers I have seen yet use the actual inserted
tables and I haven't quite understood how to use them correctly.

Can someone help me with the basic syntax as this trigger is one of
several that I am going to have to get working.

Thank you in advance for any help, assistance, suggestions or
"direction pointing" you may provide.

Jul 23 '05 #1
1 6070
On 13 May 2005 06:17:29 -0700, Derek Erb wrote:

(snip)

Hi Derek,

I don't really understand your question. First, you write that the
tablles all have the same structure, then you indicate that one of the
tables has an ntext column. If they are all the same structure, wouldn't
they all have this ntext column?

Also, you are storing loads of redundant data. I suggest that you drop
all tables except the merge table (that holds all data from all other
tables plus the extra column). Then create views to mimic the old
tables. I guess that this would solve most if not all your problems!

Finally, to answer your question: ntext and image columns are not
available in the inserted pseudotable (except when you use an INSTEAD OF
trigger, but I wouldn't recommend them in your case). The workaround is
to fetch the ntext or image data from the base table by joining the
inserted pseudotable to the base table on all the key columns.

Best, Hugo
--

(Remove _NO_ and _SPAM_ to get my e-mail address)
Jul 23 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Bill | last post: by
18 posts views Thread by Bill Smith | last post: by
reply views Thread by gheharukoh7 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.