简体   繁体   中英

Check before to insert record into Database Table

I have a problem with inserting data into the database table using CRON script that is executing every day.

So, I am using that script to insert orders into order tables that have Order ID and Order number as keys.
But in the code, I am generating ID of order dynamically and article number is for each order incrementing for one.
But, with this solution, I cannot add check in my SQL query ( IF NOT EXIST... ), so orders will be duplicated all the time...And I don't have an idea at the moment for some smart solution...

Could someone provide me any suggestion for the problem? Thank you.

I think you can use INSERT ... ON DUPLICATE KEY UPDATE Syntax.
Here you can find more information on how to use it.
Hope this will help you

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM