Showing posts with label inserted. Show all posts
Showing posts with label inserted. Show all posts

Tuesday, March 27, 2012

Changing column values on table insert trigger

Hello,

i have a table and if a record is inserted i will test a numeric value
in this table. If the this value is greather as 1 million, than an
status column should be changed from 'A' to 'B'.

Yes and sorry, this is a newbie question.

On Oracle this work simple:

create trigger myTrigger on tableX
as
begin
if :old.x 100000 then
:new.y:='B'
end if;
end;

Thanks
MaikYou can look up SQL Server Books Online to learn how to write a trigger in
t-SQL. You'll need to utilize the inserted/deleted virtual tables to
accomodate multi-row inserts. The update statement will be something along
the lines of:

UPDATE tableX
SET y = B
WHERE EXISTS ( SELECT *
FROM inserted i
WHERE i.key_col = tableX.key_col
AND inserted.x 1000000 ) ;

Here key_col is any column or set of columns that can uniquely identify a
row in tableX.

--
Anith|||Hi,

Quote:

Originally Posted by

i have a table and if a record is inserted i will test a numeric value
in this table. If the this value is greather as 1 million, than an
status column should be changed from 'A' to 'B'.
>
Yes and sorry, this is a newbie question.
>
On Oracle this work simple:
>
create trigger myTrigger on tableX
as
begin
if :old.x 100000 then
:new.y:='B'
end if;
end;


MS SQL Server doesn't have "before action" triggers, so you
have to update the table and use the INSERTED virtual table
to know what records were inserted into the table.

--
Martijn Tonies
Database Workbench - tool for InterBase, Firebird, MySQL, NexusDB, Oracle &
MS SQL Server
Upscene Productions
http://www.upscene.com
My thoughts:
http://blog.upscene.com/martijn/
Database development questions? Check the forum!
http://www.databasedevelopmentforum.comsql

Sunday, March 11, 2012

Changed (or inserted) data not transferring

We've had replication running for a while. We had some hardware
failures last week and had to restore an old database from before the
failure. Now we have some tables that are replicating correctly but
others aren't (using merge replication). We've made changes to the
data, seen the data get added or updated in msmerge_contents but when
the merge agent runs it shows no data needed to be merged.
For one table I tried sp_addtabletocontents also just to see and it
still had the same issue. We do have some row filtering on some tables
but on others we don't.
I can't say 100% yet, but for the most part it seems to be that data
from the remote server wont' replicate down to us but in some cases it
will replicate our changes up to them.
Any ideas or tips on what else to look at would be greatly appreciated.
Thanks.
Update the problem tables setting a columns' value to itself. See if this
fixes the problem.
Hilary Cotter
Looking for a SQL Server replication book?
http://www.nwsu.com/0974973602.html
Looking for a FAQ on Indexing Services/SQL FTS
http://www.indexserverfaq.com
"Don" <google@.thecoles.org> wrote in message
news:1124223959.170691.79230@.o13g2000cwo.googlegro ups.com...
> We've had replication running for a while. We had some hardware
> failures last week and had to restore an old database from before the
> failure. Now we have some tables that are replicating correctly but
> others aren't (using merge replication). We've made changes to the
> data, seen the data get added or updated in msmerge_contents but when
> the merge agent runs it shows no data needed to be merged.
> For one table I tried sp_addtabletocontents also just to see and it
> still had the same issue. We do have some row filtering on some tables
> but on others we don't.
> I can't say 100% yet, but for the most part it seems to be that data
> from the remote server wont' replicate down to us but in some cases it
> will replicate our changes up to them.
> Any ideas or tips on what else to look at would be greatly appreciated.
> Thanks.
>
|||Actually we tried that earlier to no avail (that's how we did get a
couple of the tables to update but the others still didn't). We're
trying out one program so we can find the data to manually transfer and
will probably end up removing replication and starting over again. But
we're still game to any ideas for now or in the future.
Thanks.
Hilary Cotter wrote:
> Update the problem tables setting a columns' value to itself. See if this
> fixes the problem.
> --