0

I would like to know if there is a way to insert certain set of values replacing the older ones ie without creating duplicates

1

Sure. Use the UPDATE sql command, It'll take the form of "UPDATE table SET some value WHERE some_condition". Google sql update

For example:

UPDATE users SET firstname = "Fred", lastname = "Derf" WHERE userid = 3

Or

UPDATE holdings SET shares = shares + 100 WHERE userid = 2 AND symbol = "AAPL"

THis handles the update part. As for not creating duplicates, if you don't want to have duplicate rows at all, then you need to use some kind of primary or unique key. Now, if you're trying to do something like prevent duplicate rows based on the combination of two fields, like userid and symbol (but allow multiple rows for the same userid, or allow multiple IDs to have the same symbol), then you need a unique key based on the combination of two columns. Google it.

2
  • I added this line db.execute("ALTER TABLE tracker ADD CONSTRAINT test UNIQUE(id,name)"); but i get the error near constraint syntax error – Varun Beluguli Aug 25 '20 at 7:30
  • This will get complicated fast. How about opening a new question? Include the table structure, including any primary key or other pertinent info. Also, include the full and exact text of the command and the errors received. – Cliff B Aug 25 '20 at 7:56

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .