0

I'm very new to using SQL, and I'm trying to figure out a way to store a bunch of data that will continually get updated. I know comcating all the data to the end of the current data is a HUGE nono, it takes the relational of of SQL.

I only have two columns, one is UID, and the other SID. The UID is a users ID, and the SID is their account. If they create another account, they will have the same UID. I want to add the SID to their UID, but not add it again if both of the columns are duplicates.

I'm guessing I have to just have a bunch of the same UID's in the DB, or is there a different way I can go about this?

Example:

What I would like:

|-----UID-----|--SID--|
|aa721910fe51 |6811112, 1111114|
|h678910fe761 |4444112|

What I think is the proper way, but not sure how to go about it?

|-----UID-----|--SID--|
|aa721910fe51 |6811112|
|aa721910fe51 |1111114|
|h678910fe761 |4444112|

If I do something like below, It only checks the UID if there is a duplicate, and ignores it. I would like to check the UID, if it exists, check and see if the SID exists, if it doesn't, add it.

INSERT IGNORE INTO users (UID, SID) VALUES ('aa721910fe51', '6811112')

Sorry if this is noobie stuff, i search and I couldn't fine anything.

Your Common Sense
  • 156,878
  • 40
  • 214
  • 345
12shadow12
  • 307
  • 2
  • 10
  • Another nono: storiing values in comma separated lists. See https://stackoverflow.com/questions/3653462/is-storing-a-delimited-list-in-a-database-column-really-that-bad – Nick Oct 04 '19 at 03:31
  • Assuming you store the data in the style of the second table in your question, you can just create a unique index over the `UID` and `SID` columns together e.g. `ALTER TABLE yourtable ADD UNIQUE INDEX (UID, SID)` – Nick Oct 04 '19 at 03:34
  • Instead of Unique, better option would to be to create a Primary Index on them – Madhur Bhaiya Oct 04 '19 at 04:19

0 Answers0