tsql - SQL Transact - Trigger on an INSERT into a specific table -


i need write sql transact trigger execute simple task if insert called if insert modify table t (so if insert t (...) values (...).

i'm using if (update[col]) trigger performing task obliviously, isn't calls when row created , need manage case too.

i've seen event_date , after insert don't know how perform if insert operates specific table t.

can have example how this?

this pseudo-code:

if (new row insert on t) or (t.c updated) {  task } 

from manual https://msdn.microsoft.com/en-gb/library/ms189799.aspx

-- sql server syntax  trigger on insert, update, or delete statement table or view (dml trigger)  create trigger [ schema_name . ]trigger_name  on { table | view }  [ <dml_trigger_option> [ ,...n ] ] { | after | instead of }  { [ insert ] [ , ] [ update ] [ , ] [ delete ] }  [ append ] [ not replication ]  { sql_statement  [ ; ] [ ,...n ] | external name <method specifier [ ; ] > } 

so need

create trigger mytrigger  on mytable insert, update     // stuff 

or if want write update , insert seperately

create trigger mytrigger_update on mytable update     // stuff update   create trigger mytrigger_insert on mytable insert     // stuff insert 

Comments

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -