34,576
社区成员
发帖
与我相关
我的任务
分享
--3约束
create table CheckTest(
id int check(id in(1,2,3)
)
go
insert into CheckTest
select 1 union all
select 2 union all
select 3 union all
select NULL
select * from CheckTest
/*
--结果
id
-----------
1
2
3
1
2
3
NULL
(7 行受影响)
*/
create table my_table
(
name varchar(10) NOT NULL,--不能为空
age int NULL --可以为空
)
insert into my_table values('your_name',NULL)--插入了一条记录,name 为'your_name',age 为空的
create table newTable
(
ID int identity(0,1),--从0开始,一次增加1
name varchar(10),
age int
)
--插入数据时,不需要理会自增列,直接插入即可
insert into newTable values('your_name',NULL)