You must Sign In to post a response.
  • Category: SQL Server

    When i creating a trigger shows error

    The above one is doing in sql server 2008


    tblemployeedetailsas follows

    id int
    Name Varchar(50)
    Salary Varchar(50)
    Gender Varchar(50)
    Deptid int


    Tblaudit as follows

    id int
    Auditdata varchar(50)


    i am creating a trigger whenever record inserted in the tblemployeedetails, in tblaudit record will be inserted. for that i am creating a trigger as follows.


    create triggger tbl_insert_foremployee
    on tblemployeedetails
    for insert
    AS

    BEGIN
    declare @id int
    select @id = id from inserted
    insert into Tblauditdata
    values ('New employee with id = ' + cast(@id as varchar(5)) +
    'is added at ' + cast(Getdate() as nvarchar(20)))
    END
    GO


    when i execute the above trigger shows error as follows

    Unknown object type 'triggger' used in a CREATE, DROP, or ALTER statement.

    please help me what is the mistake i made.
  • #769064
    Hai Rao,
    The syntax of the trigger which you have mentioned is correct So I don't think that there is any issue with the trigger. The only thing I can think of for now is - as you said when I execute, means you don't need to execute, just compile it and it will be executed automatically when the insert operation will happen in the corresponding table.
    Hope it will be helpful to you.

    Regards,
    Pawan Awasthi(DNS MVM)
    +91 8123489140 (whatsApp), +60 14365 1476(Malaysia)
    pawansoftit@gmail.com

  • #769110
    Triggers are a special type of stored procedure which are executed automatically. You can use following systax to Creating and managing Triggers in SQL Server 2005/2008
    CREATE [ OR ALTER ] TRIGGER [ schema_name . ]trigger_name
    ON { table | view }
    [ WITH <dml_trigger_option> [ ,...n ] ]
    { FOR | AFTER | INSTEAD OF }
    { [ INSERT ] [ , ] [ UPDATE ] [ , ] [ DELETE ] }
    [ WITH APPEND ]
    [ NOT FOR REPLICATION ]
    AS { sql_statement [ ; ] [ ,...n ] | EXTERNAL NAME <method specifier [ ; ] > }
    <dml_trigger_option> ::=
    [ ENCRYPTION ]
    [ EXECUTE AS Clause ]
    <method_specifier> ::=
    assembly_name.class_name.method_name


Sign In to post your comments