login about faq

Why can I insert into a column that is defined as not null

asked Oct 29 '09 at 01:01

Mike%203's gravatar image

Mike 3
1

edited Oct 29 '09 at 13:10

Kristen's gravatar image

Kristen ♦
184339

What is the column type or table definition? What is the insert statement you are using?

(Oct 29 '09 at 02:34) Benjamin

Column is defined as: LastName(nvarchar(15), not null)

(Oct 29 '09 at 03:58) Mike 3

you mean you can insert a NULL value into the Lastname column ?

(Oct 29 '09 at 06:06) Squirrel

Post the code you used

(Oct 29 '09 at 07:21) Madhivanan

try these . . .

create table t
(
    col1    int,
    col2    int not null
)

insert into t (col1, col2) select NULL, 2
/*
(1 row(s) affected)
*/

insert into t (col1, col2) select 1, NULL
/*
Server: Msg 515, Level 16, State 2, Line 1
Cannot insert the value NULL into column 'col2', table 'test.dbo.t'; column does not allow nulls. INSERT fails.
The statement has been terminated.
*/

drop table t

answered Oct 29 '09 at 06:08

Squirrel's gravatar image

Squirrel
142317

Your answer
toggle preview

powered by OSQA