How to Insert Null Values in SQL Server DB table column whose datatype is Int?
Thanks
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Jignesh TrivediPosted May 31, 2012, 12:14 AM
If you column of table in data base is set to allow null than it is possible to insert null value.
Example:
CREATE TABLE [dbo].[TestTable](
[SessionId] [nvarchar](88) NOT NULL,
[Created] [datetime] NOT NULL,
[Expires] [datetime] NOT NULL,
[Flags] [int] NULL,
PRIMARY KEY CLUSTERED
(
[SessionId] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
You can also set from designer.
Insert into TestTable (SessionId,Created,Expires,Flags)
values('test guid',getdate(),getdate(),null)
Hope this will help you.