0

I am trying to update multiple rows from node js to sql server database with no unique column.

enter image description here

now, I am trying to update 2 records at the same time,that is one property has two different owners.

UPDATE tbl_PropertyOwnerShip SET  OwnerName = 'ross' , SinceFrom = '2012-12-12' where PropertyId = '59';
UPDATE tbl_PropertyOwnerShip SET  OwnerName = 'mike' , SinceFrom = '2012-12-12' where PropertyId = '59';

enter image description here

Can anyone help me to sequencially update rows in sql server to get desired output?

ariana
  • 11
  • 2
  • is the `SinceFrom` same for both the rows? – Mr. Alien Oct 13 '20 at 10:31
  • Yes May be, and I am getting only PropertyID as JSON in POSTMAN CALL. – ariana Oct 13 '20 at 10:35
  • You can make use of `top` and then update specific row – Mr. Alien Oct 13 '20 at 10:51
  • How can i do this? – ariana Oct 13 '20 at 11:01
  • You're stuck with the table structure it's safe to assume? This is why a "table" must contain a primary key. I'm afraid the only way I see to make this work would be to delete a certain number of dupes and replace them with what you want. It would probably be a few statements so it would be better as a proc. This is what you want? – SteveC Oct 13 '20 at 12:24
  • Yup, Actually this is reference table and PropertyID is foreign key.As u suggested I deleted records and added updated one into the table....finding no other way...!!! – ariana Oct 13 '20 at 18:27

1 Answers1

0

You must have a unique ID or at least a different value in your rows. When you update the table with this WHERE clause: where PropertyId = '59', each time, it updates all the rows that have propertyId of 59.

Maybe you need to add a new table, then add all the rows in this table to the new table beside an unique ID there. or maybe, this answer helps you:

SQL Server how to update only one row in database?

ImanGM
  • 89
  • 8