Insert data and if already inserted then update in sql

后端 未结 7 2973
眼角桃花
眼角桃花 2021-02-20 13:18

I simply want to insert the data to a SQL database table and if there is some data inserted already then I want to update that data. How can I do this using Java. Kindly help me

7条回答
  •  醉话见心
    2021-02-20 13:55

    You could use the EXISTS keyword to check for the existance of rows:

    IF EXISTS (SELECT TOP 1 * FROM...)
    BEGIN
        UPDATE....
    END
    ELSE
    BEGIN
       INSERT...
    END
    

提交回复
热议问题