Results 1 to 6 of 6

Thread: Triggers

  1. #1
    Junior Member
    Join Date
    Apr 2008
    Answers
    15

    Triggers

    How to wite Tiggers in sql?
    Give me the example......


  2. #2
    Junior Member
    Join Date
    Apr 2007
    Answers
    2

    Re: Triggers

    Lets say you want to create trigger on table1 having columns id and name.

    The syntax would be

    create trigger insert on my_table as
    begin
    insert into my_table values (0,"new NAME inserted")
    end

    for any insert into your my_table object as below:

    insert into my_table values (1,"name1")

    O/P will be:

    id name
    -- ------
    1 name1
    0 new NAME inserted

    The above is an example for insert trigger.

    Similarly you can create update and delete triggers.

    Last edited by keerthv; 04-23-2008 at 05:58 AM.

  3. #3
    Moderator
    Join Date
    Jun 2007
    Answers
    2,074

    Re: Triggers

    By SQL if you mean SQL Server then please find a related discussion here.


  4. #4
    Junior Member
    Join Date
    Jul 2009
    Answers
    5

    Re: Triggers

    Hi usha, here is an example.. Example to create table level or statement triggers create or replace trigger secure_emp before insert on emp begin if to_char(sysdate,’dy’) in(‘sat’,’sun’) or to_char(sysdate,’hh24:mi’) not between ’08:00’ and ’18:00’ then raise_application_error(-20001,’you may insert into emp table only during business hours..’); end if; end; / here is the output.. testing secure_emp insert into emp (empno, ename) values (101,’ravi’); error at line 1 ora-20001 you may insert into emp table only during business hours ora-06512 at plsql secure_emp, line 4 ora-04088 error during execution of trigger “plsql secure_emp” regards, e.sagar.


  5. #5
    Contributing Member
    Join Date
    Jun 2009
    Answers
    76

    Re: Triggers

    Please mention the server name.


  6. #6

    Re: Triggers

    Quote Originally Posted by ushalakshmi View Post
    How to wite Tiggers in sql?
    Give me the example......
    DML triggers syntax

    create or replace trigger Before/After insert/update/delete on
    inserting .....
    or
    updating.....
    or
    deleting .....
    end

    Instead of trigger syntax
    create or replace trigger < trigger name> Instead of insert/update/delete on

    end

    DDL trigger syntax

    create or replace trigger logon on



    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •  
    About us
    Applying for a job can be a stressful and frustrating experience, especially for someone who has never done it before. Considering that you are competing for the position with a at least a dozen other applicants, it is imperative that you thoroughly prepare for the job interview, in order to stand a good chance of getting hired. That's where GeekInterview can help.
    Interact