J Sam J Sam - 6 months ago 38
SQL Question

How to add extra constraint to table?

This my table:

customer_id
user_id
password
email
first_name
last_name


My primary key is
customer_id
which is generated by the system. How can I prevent a user form creating multiple accounts?

Should I put a constrain on another column?

Answer

Create a unique index or constraint on however you identify the user. I'm not sure which columns you have in mind, but this would be typical:

alter table mytable add constraint unq_table_email unique (email);

You can have more than one unique constraint on the table.