0

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 fisrt.last@company.com?

Francesco
  • 24,839
  • 29
  • 105
  • 152
  • _In my opinion_ you can put email null. Unless you use this field for credentials purpose. – bcesars Mar 10 '15 at 20:18
  • you could consider "username" and "email" as 2 fields even if 99% of the time they are the same –  Mar 10 '15 at 20:21

1 Answers1

1

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.

Gordon Linoff
  • 1,242,037
  • 58
  • 646
  • 786
  • +1 and some more information here: http://stackoverflow.com/questions/3712222/does-mysql-ignore-null-values-on-unique-constraints – steven Mar 10 '15 at 20:23