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 ?
Asked
Active
Viewed 71 times
-6
-
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 Answers
0
Maybe something like this ?
IF EXISTS (SELECT * FROM Table1 WHERE Column1=’SomeValue’)
UPDATE Table1 SET (…) WHERE Column1=’SomeValue’
ELSE
INSERT INTO Table1 VALUES (…)

George Kontonikolaou
- 109
- 4
- 15
-
-
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