-6

I am writing a java code which will check the Primary key value in my Database, if it already exists, the value will be overrided(clear corresponding row and update new value)..can some one suggest me the optimum approach ?

  • Possible duplicate of [Can we update primary key values of a table?](http://stackoverflow.com/questions/3838414/can-we-update-primary-key-values-of-a-table) – xenteros Sep 28 '16 at 09:20

1 Answers1

0

Maybe something like this ?

IF EXISTS (SELECT * FROM Table1 WHERE Column1=’SomeValue’)
    UPDATE Table1 SET (…) WHERE Column1=’SomeValue’
ELSE
    INSERT INTO Table1 VALUES (…)
  • will try that. Thanks ! – Gorthi Subramanyam Sep 29 '16 at 08:19
  • thats the query only for java you need to say. String query="IF EXISTS (SELECT * FROM Table1 WHERE Column1=’SomeValue’) UPDATE Table1 SET (…) WHERE Column1=’SomeValue’ ELSE INSERT INTO Table1VALUES(…)"; executeSQLQuery(query,"Inserted"); something like that – George Kontonikolaou Sep 29 '16 at 09:31