sql on insert function

Discussion in 'Databases' started by Silver89, Feb 6, 2010.

  1. #1
    Is there a way in SQL to perform a function when data is input into a table.

    So not calling a function but on new insert the input data is put through if and elses to change the data depending on the if else requirements?
     
    Silver89, Feb 6, 2010 IP
  2. koko5

    koko5 Active Member

    Messages:
    394
    Likes Received:
    14
    Best Answers:
    1
    Trophy Points:
    70
    #2
    Hi,

    You didn't mention which DB you're going to use but create trigger maybe helps.
    Regards,
    Nick
    p.p.: Before Insert event.
     
    koko5, Feb 7, 2010 IP
  3. anxggxun

    anxggxun Peon

    Messages:
    24
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #3
    well i think you can use the insert select statement, in mysql reference http://dev.mysql.com/doc/refman/4.1/en/insert-select.html

    try something like this

    INSERT INTO tbl_name (col_name1, col_name2)
    SELECT CASE WHEN (any condition) THEN (any statement) ELSE (other statement) END AS col_value1, col_value2
    
    Code (markup):
    note: you can use select statement without select any table for example
    SELECT 1
    Code (markup):
    , will return row set 1

    hope it works.
     
    anxggxun, Feb 7, 2010 IP
  4. sachindshah

    sachindshah Greenhorn

    Messages:
    23
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    13
    #4
    Trigger would be a better option. It will allow you to write a full procedural function.
     
    sachindshah, Feb 9, 2010 IP
  5. blacksheep666

    blacksheep666 Active Member

    Messages:
    68
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    93
    #5
    Use trigger
     
    blacksheep666, Feb 9, 2010 IP
  6. chengary

    chengary Banned

    Messages:
    88
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    16
    #6
    trigger is ok
     
    chengary, Feb 19, 2010 IP
  7. boi4

    boi4 Peon

    Messages:
    8
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #7
    use phpMyAdmin - it generates code in PHP
     
    boi4, Feb 20, 2010 IP
  8. lanlinh

    lanlinh Peon

    Messages:
    1
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #8
    You can creatte trigger for this problem
     
    lanlinh, Feb 26, 2010 IP
  9. mdvasanth86

    mdvasanth86 Notable Member

    Messages:
    3,869
    Likes Received:
    285
    Best Answers:
    0
    Trophy Points:
    230
    #9
    Yeah! Triggers would be perfectly apt for this ..
     
    mdvasanth86, Mar 2, 2010 IP
  10. beven

    beven Well-Known Member

    Messages:
    483
    Likes Received:
    1
    Best Answers:
    1
    Trophy Points:
    113
    #10
    trigger is used for that specific actions
     
    beven, Mar 2, 2010 IP
  11. app789

    app789 Peon

    Messages:
    330
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #11
    Use trigger in this issue, I think it will resolve the problem easily.
     
    app789, Mar 14, 2010 IP
  12. yogesh420

    yogesh420 Well-Known Member

    Messages:
    447
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    120
    #12
    Trigger! triger!! trigger!!! its only path for you to achieve your goal!!
     
    yogesh420, Mar 16, 2010 IP
  13. jakkevin4v

    jakkevin4v Peon

    Messages:
    13
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #13
    hi
    you can create the trigger and view in your database.
     
    jakkevin4v, Mar 18, 2010 IP