We help IT Professionals succeed at work.

SQL Server - create a field

Hi experts,

I'm creating a table like this:

CREATE TABLE tblA
      (fieldA varchar(7) null, fieldb datetime null)

Why do we put the "null" word after the data type?

Thanks so much.  

Comment
Watch Question

SQL Server Data Dude
Most Valuable Expert 2013
Author of the Year 2015
Commented:
>Why do we put the "null" word after the data type?
That explicitly allows NULL values to be entered into the column.

Author

Commented:
Cool - and what happens when you try to run a script that inserts null values into a column that is not allowed for nulls?
Qlemo"Batchelor", Developer and EE Topic Advisor
Top Expert 2015
Commented:
You will get an error message saying you cannot insert the value 'NULL' into a non-null column.
Jim HornSQL Server Data Dude
Most Valuable Expert 2013
Author of the Year 2015

Commented:
You'll get the same error message if you try to do an INSERT that does not include that column.
Jim HornSQL Server Data Dude
Most Valuable Expert 2013
Author of the Year 2015

Commented:
Thanks for the split. Good luck with your project.  -Jim

Author

Commented:
Thanks!!! take care!!!