--创建一张表
create table test1
(testId int primary key identity(1,1),--主键不能重复,不能为null
testname varchar(30) not null,--不能为空
testpass varchar(30) not null,
testage int
)
insert into test1(testage)values(3)--不能插入
select*from test1
create table test2
(testId int primary key identity(1,1),
testname varchar(30) unique,--唯一不能重复,但能为null(但最多只能有一个null)
testpass varchar(30) ,
testage int
)
insert into test2 (testname,testpass,testage)values('aa','11',45)
--表可以有复合主键
create table test3
(testId int ,
testname varchar(30) ,
testpass varchar(30) ,
testage int,
primary key(testId,testname)--复合主键
)
--行级定义和表级定义
--foreign key外键,在主表和从表间起到连接作用
--check 范围约束
create table test4
(testId int ,
testname varchar(30) ,
testpass varchar(30) ,
sal int check(sal>=1000and sal<=2000),--规定sal的范围
)
insert into test4 values (4,'d','s',2200)
--default使用
create table mes
(
mesId int primary key identity(1,1),
mescon varchar(2000) not null,
mesDate datetime default getdate()
)
insert into mes (mescon,mesDate)values('sdsfs','2000-1-1')
insert into mes (mescon)values('sdsfs')
select*from mes ```
因篇幅问题不能全部显示,请点此查看更多更全内容