How to insert dbnull in SQL Server?

How to insert dbnull in SQL Server?


Hello

First point that you need to keep in mind before you insert any null value in a SQL Server Table column is that you need to make the column to accept nulls by default which can be mentioned while creation of the Table by using the create table command as follows:

Example:

CREATE TABLE dbo.Students(Id INT IDENTITY(1,1) PRIMARY KEY, age INT default null, gender CHAR(1))
GO


Or if the table is created then Go-to the Database->TableName->Design->Column->Properties and set the default value as null-able.

Now if you send only those values that are to be inserted & has some value then those columns which has values will be inserted & the columns for which no values have been passed so by default NULL value will be inserted for those columns which are made null-able by default.

Hence, there is no need to pass null value from a front-end application to SQL Server it will automatically handle it at its end only pass the columns that have some value. 



You may also like

No comments:

If you have any queries regarding the article or in performing something in Microsoft SQL Server then please let me know.