0

So I am checking a friend's project. I got a table where every field is defined will NOT NULL constraint but I am still finding so many fields are NULL. I cannot understand what might be the reason to happen this kind of phenomenon?

Because as I have understanding if you pass NULL value in a field which is defined as NOT NULL than it does not let you submit that entry.

See the table defined with Not Null values Look the table contains some empty values too

Thank you.

P.S. This is a very big, perfectly working pharmacy management system.

2
  • 5
    I don't see NULL, I see what could be an empty string. Please clarify your question to make sure it's actually NULL
    – Tom V
    Feb 10, 2017 at 19:57
  • 1
    What GUI tool are you using? Feb 10, 2017 at 20:40

1 Answer 1

4

Are you sure those "empty" cells are set to NULL?

It could be that they have inserted empty strings to get past the Not Null restriction. Code like this will bypass a Not Null setting:

INSERT INTO <table> (Pat_LNAME, Pat FmName, Pat_email) values ('', ' ', '  ');

Notice, in the LNAME field, I pass an empty string '' (two single quote marks). In the second, I pass in a space, ' '. In the third I pass two spaces ' '. All three will get past a NOT NULL rule.

But this code WOULD fail:

INSERT INTO <table> (Pat_LNAME, Pat FmName, Pat_email) values (null, ' ', '  ');

Or any insert that didn't have a Pat_lname field included.

In SQL Server Management Studio, your view would show you Null columns like this:

NULL columns

Note the yellow background and the word NULL to show there's no data.

Remember, NULL does not equal empty string.

Not the answer you're looking for? Browse other questions tagged or ask your own question.