Database Research & Development

  • Home
  • NoSQL
    • NoSQL
    • Cassandra
  • Databases
    • Database Theory
    • Database Designing
    • SQL Server Coding Standards
    • SQL Server
    • PostgreSQL
    • MySQL
    • Greenplum
    • Linux
  • Interviews
    • SQL Server Interviews
    • MySQL Interviews
    • SQL Puzzles
  • DBA Scripts
    • SQL Server DBA Scripts
    • PostgreSQL DBA Scripts
    • MySQL DBA Scripts
    • Greenplum DBA Scripts
  • Home
  • Blog Archives !
  • (: Laugh@dbrnd :)
  • Contact Me !
sqlserverinterviews
Home 2016 January Database Design: Should we allow NULL or We should apply NOT NULL ?

Database Design: Should we allow NULL or We should apply NOT NULL ?

This article is half-done without your Comment! *** Please share your thoughts via Comment ***

Should we allow NULL or We should apply NOT NULL ?

As a Database Architect, I would also like to express my opinions and views on this topic.

First single line statement, Should NULL or Should NOT NULL is depending on the situation and importance of data.

NULL means the pointer set to 0x00 in the row header that means no data to access.
Any search query or engine can easily identify a data which has a NULL.

As per ANSI Standard NULL means UNKNOWN value whatever data-type like, integer, varchar or datetime.

I read many articles and found that many database professionals are suggesting that never go with NULL.
Means, you have to enter a value in each column or else they will allow (”) empty string as NULL values.
e.g. In SQL Server if you enter an empty string in datetime column, it inserts the default value like ‘1900-01-01 00:00:00.000’. – Which is wrong.
In this type of column NOT NULL will not work and we should allow NULL.

Another example is, CHAR data-type column. If we apply NOT NULL and someone enters empty string because of NOT NULL, it occupies the same size of bytes like other rows and which is wrong.

We have to identify all columns and take decisions that in which columns we should allow NULL and in which columns we should apply NOT NULL.

The Next is about performance,
IS NULL or IS NOT NULL condition is always faster than any other string operation.

We should also apply NOT NULL constraint on a required column like Password column, but it doesn’t mean that user can enter (”) empty string again.

Many programming languages don’t recognize a NULL value so for that reason, many Database Professionals applied NOT NULL constraint and putting (”)Empty string as a NULL value.
But this is not an enough reason to avoid a NULL because NULL is created for a purpose to express the unknown data which can be valid.

Don’t make all columns nullable, and Don’t make them all NOT NULL. Use NULL only when necessary where the unknown is a valid condition. Everywhere else, use NOT NULL.

Jan 26, 2016Anvesh Patel
SQL Server 2012: Introduced dm_db_log_space_usage to find a Log sizeSQL Server 2012: Error Msg 3729 Cannot DROP SEQUENCE because it is being referenced by Object
Comments: 1
  1. kiran
    January 23, 2019 at 3:05 pm

    if the column is null and i will set as “Is Sparse”, Kindly explain is that effected on NULL value.
    “Is Sparse” is good or bad if column set as NULL in MS SQL

Anvesh Patel
Anvesh Patel

Database Engineer

January 26, 2016 Database DesigningAnvesh Patel, database, database concept, database research and development, database standards, Database Theory, database topic, dbrnd, NOT NULL, NULL, RDBMS
About Me!

I'm Anvesh Patel, a Database Engineer certified by Oracle and IBM. I'm working as a Database Architect, Database Optimizer, Database Administrator, Database Developer. Providing the best articles and solutions for different problems in the best manner through my blogs is my passion. I have more than six years of experience with various RDBMS products like MSSQL Server, PostgreSQL, MySQL, Greenplum and currently learning and doing research on BIGData and NoSQL technology. -- Hyderabad, India.

About DBRND !

dbrnd

This is a personal blog (www.dbrnd.com).

Any views or opinions represented in this blog are personal and belong solely to the blog owner and do not represent those of people, institutions or organizations that the owner may or may not be associated with in professional or personal capacity, unless explicitly stated.

Feel free to challenge me, disagree with me, or tell me I’m completely nuts in the comments section of each blog entry, but I reserve the right to delete any comment for any reason whatsoever (abusive, profane, rude, or anonymous comments) - so keep it polite.

The content of this website is protected by copyright. No portion of this website may be copied or replicated in any form without the written consent of the website owner.

Recent Comments !
  • Anvesh Patel { Sure will do... } – May 27, 12:43 PM
  • Anvesh Patel { Great... } – May 27, 12:41 PM
  • Anvesh Patel { Great... } – May 27, 12:39 PM
  • Anvesh Patel { Great... } – May 27, 12:36 PM
  • Anvesh Patel { Great... } – May 27, 12:28 PM
  • Anvesh Patel { Great... } – May 27, 12:27 PM
  • Anvesh Patel { Great... } – May 27, 12:16 PM
  • Older »
Follow Me !
  • facebook
  • linkedin
  • twitter
  • youtube
  • google
  • flickr
© 2015 – 2019 All rights reserved. Database Research & Development (dbrnd.com)
Posting....