0

I have a database table that saved users profile information. Sometimes when users register, they get duplicated with an extra column with same records, sometimes not.

So, I wonder if I put Unique on the column Email to make sure the user don't dup when register.

I think it should be something like this:

ALTER TABLE users ADD UNIQUE idx_row_unique(email); 

But in case the Unique give error, how do I undo it?

Just scare that after I change it, I don't know how to undo it.

2 Answers 2

2

If there are duplicate emails, the alter table should fail. So you're safe with that!

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

3 Comments

Even like the function force the database to create 2 column identical?
Because I don't why sometimes, my function register saved with the user 2 times identical. So, I want to check it, and Keep one and remove the other.
So, if now you have 2 times the same mail in your field, the alter table statement will fail. For the future, if you have a function that saves the data in the database, you need to change that to consider the new conditions.
0

I'd export the table structure and data first. That way if you need to put it back, you have the SQL right there.

2 Comments

is there a way to export it? I didn't create the database
If you have access to phpMyAdmin for the database there is an export feature. There is no way that I know of to do it through code.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.