Jump to content

Creating Triggers with If Statements

- - - - -

  • Please log in to reply
5 replies to this topic

#1
docmonkey

docmonkey

    Newbie

  • Members
  • PipPip
  • 10 posts
I've tried to read about this, and I'm sorry I just can't find an answer.

I want to create a trigger that checks to see if a column is null AFTER an insert has been completed. At that point, if the column is null or empty, I would like to insert a INT value of 314. I just can't seem to get this syntax to work... Tried many tutorials.

I'd appreciate any help!

#2
WingedPanther

WingedPanther

    A spammer's worst nightmare

  • Moderators
  • 16,831 posts
  • Location:Upstate, South Carolina
  • Programming Language:C, C++, PL/SQL, Delphi/Object Pascal, Pascal, Transact-SQL, Others
  • Learning:Java, C#, PHP, JavaScript, Lisp, Fortran, Haskell, Others
It depends on the type of database, first of all. Which type of database are you talking about?
Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

#3
docmonkey

docmonkey

    Newbie

  • Members
  • PipPip
  • 10 posts

WingedPanther said:

It depends on the type of database, first of all. Which type of database are you talking about?

Sorry, totally blanked on that. It's a mysql database.

#4
WingedPanther

WingedPanther

    A spammer's worst nightmare

  • Moderators
  • 16,831 posts
  • Location:Upstate, South Carolina
  • Programming Language:C, C++, PL/SQL, Delphi/Object Pascal, Pascal, Transact-SQL, Others
  • Learning:Java, C#, PHP, JavaScript, Lisp, Fortran, Haskell, Others
Wouldn't it make more sense to set a default value of 314, rather than try to do this via a trigger? Also, why do you want to do this after insert rather than before insert?
Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

#5
docmonkey

docmonkey

    Newbie

  • Members
  • PipPip
  • 10 posts
If the user selects nothing, the default is 0 (which is controlled by the script dynamically...) so the only way to do it is through a trigger. I tried the default value, but no luck. It needs to be updated AFTER the row has been inserted. Help is appreciated!

Thanks

#6
WingedPanther

WingedPanther

    A spammer's worst nightmare

  • Moderators
  • 16,831 posts
  • Location:Upstate, South Carolina
  • Programming Language:C, C++, PL/SQL, Delphi/Object Pascal, Pascal, Transact-SQL, Others
  • Learning:Java, C#, PHP, JavaScript, Lisp, Fortran, Haskell, Others
Wait, what script is changing it to 0? Why not change the script? The issue you'll run into is it might not be possible to issue an update statement on the same record from within a trigger.
Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users