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 2008 Forums
 Transact-SQL (2008)
 why i can not create trigger with VS 2010

Author  Topic 

dhay06
Starting Member

1 Post

Posted - 2011-05-23 : 06:37:26
Vous ne pouvez pas voter pour votre propre billet.
0
hey, I am developing an application with SQL Server Express in Visual Studio 2010 and I need a trigger, so I wanted to test with the creation of a simple trigger. Here is the code


CREATE TRIGGER trigg_test
ON table1
AFTER INSERT
AS
INSERT INTO table2(nom) SELECT nom FROM table1


the problem it gives me the following error The CREATE TRIGGER SQL construct or statement is not supported.

slimt_slimt
Aged Yak Warrior

746 Posts

Posted - 2011-05-23 : 15:27:36
hi,

i hope this will help you:

create table test1
(id int identity(1,1)
,some_text varchar(20)
,ts timestamp)

insert into test1 (some_text)
select 'text text';
go 10

select * from test1


create table test1_capturechange
(row_id int
,action_change varchar(10)
)



create trigger trg_test1_update
on dbo.test1
after update
as
insert into test1_capturechange
select id, 'UPDATE' from deleted
go


create trigger trg_test1_insert
on dbo.test1
after insert
as
insert into test1_capturechange
select id, 'INSERT' from inserted
go


create trigger trg_test1_delete
on dbo.test1
after delete
as
insert into test1_capturechange
select id, 'DELETE' from deleted
go



-- do some test actions
update test1
set some_text = 'la la'
where id = 12


insert into test1 (some_text)
select 'more text'

delete from test1 where id = 22


--check your results
select * from test1_capturechange
select * from test1
Go to Top of Page
   

- Advertisement -