Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Naming of boolean column in database table

I have 'Service' table and the following column description as below

  1. Is User Verification Required for service ?
  2. Is User's Email Activation Required for the service ?
  3. Is User's Mobile Activation required for the service ?

I Hesitate in naming these columns as below

IsVerificationRequired IsEmailActivationRequired IsMobileActivationRequired 

or

RequireVerification RequireEmailActivation RequireMobileActivation 

I can't determined which way is the best .So, Is one of the above suggested name is the best or is there other better ones ?

like image 202
Amr Badawy Avatar asked Jun 14 '10 12:06

Amr Badawy


People also ask

How do you name a column in a database?

Database object names, particularly column names, should be a noun describing the field or object. Avoid using words that are just data types such as text or timestamp . The latter is particularly bad as it provides zero context. Underscores separate words.

How do you represent a boolean in a database?

Use the BIT datatype to represent boolean data. A BIT field's value is either 1,0 or NULL.

How do you create a boolean column in SQL?

In SQL Server, a Boolean Datatype can be created by means of keeping BIT datatype. Though it is a numeric datatype, it can accept either 0 or 1 or NULL values only. Hence easily we can assign FALSE values to 0 and TRUE values to 1. This will provide the boolean nature for a data type.


2 Answers

I would (and do) use "IsVerificationRequired"

I try to add some meaning to my column names so it's obvious (ValueDate, InsertedDateTime, IsActive, HazCheezBurger, ProductName etc). "Isxxxx" implies yes/no for example without thinking and you only have 2 states unlike "ProductName".

like image 55
gbn Avatar answered Sep 18 '22 22:09

gbn


Run with the Is variants, or at the very least swap the Require to Requires. Booleans should be phrased as questions. Is, Can, Has, Should, they're all good prefixes for Boolean functions/columns. See 1370840 for more arguments on this

like image 23
Dan F Avatar answered Sep 20 '22 22:09

Dan F