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.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Jignesh TrivediRank #16 · 50.3K reputationPosted May 30, 2012, 8:14 PM EDT
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.