I have to insert the values in the table named “First”, but before inserting the value i have to check whether the row exists there or not with a following Registered “name”. If the row value is present there, then i have to remove that row and insert the values present in that row to different table named “second”. Then, i have to insert the my present value to the “first” table.
I am Using SQL server 2005
This seems to me as you are trying to create history table. It is usually done in trigger because it covers all possible scenarios.
Here is a stored procedure you might call from java to insert or update First:
And this is a trigger that saves old copies into second: