create database Test
use Test--使用Text库,作为当前查询的库
create table TbClass
(
clsId int primary key identity(1,1),--班级编号自增,主键,逗号后值为增量
clsName nvarchar(16) unique,--唯一性约束
clsTeacher nvarchar(4) null,--什么都不写,就是默认可以为null
clsNumber smallint check(clsNumber>=20 and clsNumber<=80)--check约束
)--最后一个字段可以不加逗号
--go不是SQL语句 ,它只是MS,SQL Server的一个命令,
--go可以把一个SQL脚本文件上的众多SQL语句,分为多个批次发送到
--数据库服务器引擎中去执行,这样可以让不能同时选中执行的SQL语句,
--能够一次全选中,点执行提交
create table Tbstudent
(
stuId int identity(1,1) primary key,--主键
stuName nvarchar(4) not null,--不为空
stuNumber char(9) unique,--学号唯一
stuGender bit default(1),--默认值约束()内内容
stuAddress nvarchar(32),
stuAge smallint,
stuPhone char(11),
stuClassId int foreign key references Tbclass(clsId)--外键约束
)
drop database Test--删除库