Results 1 to 3 of 3
  1. #1
    Join Date
    Apr 2006
    Posts
    4

    Unanswered: database trigger help

    hello, can someone help me...

    i have a table called ' book' with the following columns

    book_hire_id
    Book_Id
    Customer_Id
    Start_date
    End_date
    Book_Hired_Days

    I have been trying to create a trigger so that no row within this table can be deleted if the start_date is equal to or less than the current date. I tried this:

    CREATE or REPLACE TRIGGER triggerC
    BEFORE DELETE on book_hire
    for each row
    BEGIN
    update book_hire
    where start_date > sysdate
    end;
    /

    but this jus doesnt allow any deletion of rows from the table. any ideas?

  2. #2
    Join Date
    Jan 2004
    Location
    Croatia, Europe
    Posts
    4,094
    Provided Answers: 4
    If you don't want to allow users to delete records, why are you trying to perform UPDATE? Trigger which *might* do what you'd like to could be like this:
    Code:
    CREATE OR REPLACE TRIGGER triggerC
    BEFORE DELETE ON book_hire
    FOR EACH ROW
    BEGIN
      IF :old.start_date <= SYSDATE THEN
         raise_application_error(-20000, 'You can not delete this record');
      END IF;
    END;

  3. #3
    Join Date
    Apr 2006
    Posts
    4
    yeh works perfectly, cheers m8 i appreciate it

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •