Francesco
Francesco

Reputation: 25259

Can I input, or is it safe to input a user into a mysql table with no email value?

I'm building a management software where a company can input employees profiles with email, name, addresses etc. so either the company or the single employee can access the website using the email as the username to access it.

the problem:

the company may need to input the name of somebody who doesn't have an email (it's a rare case but it may happen) just for archival reason or as a draft.

in my MySQl the value user_email is a unique index

what should I do?

Should I allow the email to be NULL? Should I fill the email with a temporary code? Should I fill/reserve the email with a temporary email [email protected]?

Upvotes: 0

Views: 22

Answers (1)

Gordon Linoff
Gordon Linoff

Reputation: 1270431

You should allow the email to be NULL. That seems to be the business requirement. You can keep the unique index.

Unique indexes ignore NULL values. Another field -- preferably an auto-incremented column -- should be the primary key of the table.

Upvotes: 1

Related Questions