0

I have a Table called users which structure looks like this:

user_id
google_id
google_name
google_email

When I try to insert a record to this table I need to check both user_id and google_id for duplicate data. When we take one by one these two columns I should be able to insert data with out an issue. I mean that a record can contain the same value in one of user_id or google_id already in the table. But not in both. I tried many things an still could not make this work. Can some one guide me? I am using Phpmyadmin to mange DB

1 Answer 1

1

Create a unique index on the two columns:

create unique index users_ids on users(user_id,google_id)

If someone tries to insert another row with the same user_id and google_id, the unique index will cause an error.

Sign up to request clarification or add additional context in comments.

1 Comment

do I have to make both user_id and google_id to primary keys?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.