Wednesday, March 7, 2012

Identity columns and instead-of triggers

I am sure this has been dealt with many times by others, so I'm hoping
someone can provide a clue. Lets say I have a table (SQL 2000) with an
identity column. Then I create a view with an instead of trigger. Now I
try to insert into the view without specifying a value for the ID column.
This works fine if inserting into the table directly, but not inserting into
the view.
Thanks very much for any suggestions.
Neil
ps, if replying by email remove REMOVEYou have to be explicit.
e.g.
create table t(i int identity,j int)
go
create view _v
with schemabinding
as
select i,j
from dbo.t
go
create trigger _tr on t
instead of insert
as
insert t
select j from inserted
go
insert t(j) values(1)
go
insert _v(j) values(2)
go
select * from t
go
drop view _v
drop table t
go
-oj
"Neil W" <neilw@.REMOVEnetlib.com> wrote in message
news:XoA9e.15715$ZQ1.11651@.fe11.lga...
>I am sure this has been dealt with many times by others, so I'm hoping
> someone can provide a clue. Lets say I have a table (SQL 2000) with an
> identity column. Then I create a view with an instead of trigger. Now I
> try to insert into the view without specifying a value for the ID column.
> This works fine if inserting into the table directly, but not inserting
> into
> the view.
> Thanks very much for any suggestions.
> Neil
> ps, if replying by email remove REMOVE
>
>

No comments:

Post a Comment