Reputation: 89
suppose if i create a table with primary key I can't insert null and duplicate values. But i can insert white spaces.
eg: insert into table_name values(' ');
then what is the difference between null and white space how does primary key works??
Upvotes: 1
Views: 7855
Reputation: 166
Primary Key : It is a constraint which means null values aren't allowed and repeated values are also not allowed in that column.
White space is considered as character, So white space is char like others a,b etc. so that's why it allows to enter it. Where NULL is actual nothing.
table if you want to
Upvotes: 0
Reputation: 69
White spaces are string like enter, tab etc. But Null is like blank. Text Nulll is also white space.
Upvotes: 1
Reputation: 1639
White spaces are strings, and you will not be able to insert two rows with primary keys having the same number of whites spaces.
A field with a NULL value is a field with no value. It is very important to understand that a NULL value is different than a zero value or a field that contains spaces, spaces are considered as values because they are strings (and sql can't tell what the value of a string means to the user per se), but a NULL signifies a missing value, and hence has no value associated with it.
If you find yourself having to insert white spaces, reconsider your database schema design.
More about primary keys
Upvotes: 3