Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How to insert if not exists in Mysql

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 693
    Comment on it

    If you want to enter a new records that is not exits then you can use Mysql two methods

    Method 1 'REPLACE' :-

    REPLACE INTO `users`
    SET `userid` = 65,
    `username` = 'abc',
    `useremail` = 'abc@gmail.com';
    

    In this case if record exists, the query will overwrite the entry with values but if it does not exist with userid, it will enter a new entry.

    Method 2 ' INSERT IGNORE' :-

    INSERT IGNORE INTO `users`
    SET `userid` = 65,
    `username` = 'abc',
    `useremail` = 'abc@gmail.com';
    

    Now in the case above if the userid exits with 65 then query will skip this entry and continue proceed. Benefit of using this query is it not modify you entry.

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: