34,593
社区成员
发帖
与我相关
我的任务
分享
if object_id('tb') IS NOT NULL
drop table tb
create table tb(id int, name varchar(20) NOT NULL default (''))
insert into tb(id)
select 2
select * from tb
/*
id name
----------- --------------------
2
(1 行受影响)
*/
--非空 + default空值(矛盾?)
if object_id('tb') IS NOT NULL
drop table tb
create table tb(id int, name varchar(20) NOT NULL default (NULL))
insert into tb(id)
select 2
/*
消息 515,级别 16,状态 2,第 3 行
不能将值 NULL 插入列 'name',表 'ymw_test.dbo.tb';列不允许有空值。INSERT 失败。
*/
if object_id('tb') IS NOT NULL
drop table tb
create table tb(id int, name varchar(20) default (NULL))
insert into tb(id)
select 2
select * from tb
/*
id name
----------- --------------------
2 NULL
(1 行受影响)
*/
if object_id('tb') IS NOT NULL
drop table tb
create table tb(id int, name varchar(20) default ('YYY'))
insert into tb(id)
select 2
select * from tb
/*
id name
----------- --------------------
2 YYY
(1 行受影响)
*/
insert into tb(a,b,c) values('a','b',default)