Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 Text ( BLOB ) Trigger

Author  Topic 

qwer
Starting Member

1 Post

Posted - 2005-01-11 : 02:46:15
Hi

I want to create a trigger that copies a text column datatype from one database to another database in a specific text column.

to be more precise I use a trigger in one database , and when an insert happens I want to copy the text column in the other database

How I do it ?

amachanic
SQL Server MVP

169 Posts

Posted - 2005-01-11 : 13:43:57
Something like this, perhaps:


CREATE TRIGGER tg_MoveText
ON YourTable
FOR INSERT
AS
BEGIN
IF @@ROWCOUNT = 0
RETURN

INSERT YourOtherDB..YourOtherTable (YourTextCol, YourPK)
SELECT YourTextCol, YourPK
FROM INSERTED
END
Go to Top of Page

Kristen
Test

22859 Posts

Posted - 2005-01-11 : 13:57:48
I forget the circumstances, but I don't think a text column is available, for this type of job, from INSERTED unless you do an INSTEAD OF TRIGGER is it?

But there again I may just be barking ....

Kristen
Go to Top of Page

amachanic
SQL Server MVP

169 Posts

Posted - 2005-01-11 : 15:01:48
Nope, I just tested and you're completely correct...

However, this does work:


use tempdb
go

create table blah (blah1 text, pk int)
go

create trigger tg_blah
on blah
for insert as
begin
select blah1
from blah
where pk in
(select pk
from inserted)
end
go

insert blah values ('blah', 1)
go

drop trigger tg_blah
drop table blah
go
Go to Top of Page
   

- Advertisement -