Go 是SQL Server的批处理命令,只有代码编辑器才能识别并处理,编辑其他应用程序不能使用该命令
由于每个批处理之间是独立的,因此,在一个批处理出现错误时,并不会影响其他批处理中SQL代码的运行。
4)代码
--创建学员信息数据表use StudentManageDB1
go
--判断数据表是不是存在ifexists(select*from sysobjects where name ='Students')droptable Students
go
--创建数据表createtable Students
(
StudentsId intidentity(10000,1),--学号,从10000开始,每次递增1;标识列不可为空
StudentName varchar(20)notnull,--姓名
Gender char(2)notnull,--性别
Birthday datetimenotnull,--出生日期
StudentIdNo numeric(18,0)notnull,--身份证号
Age intnotnull,--年龄
PhoneNumber varchar(50),
StudentAdress varchar(500),
ClassId intnotnull--班级外键)
go
--创建班级表ifexists(select*from sysobjects where name ='StudentClass')droptable StudentClass
go
createtable StudentClass
(
ClassId intprimarykey,--定义主键(一个表必须含有主键)
ClassName varchar(20)notnull,)
go
--创建成绩表ifexists(select*from sysobjects where name ='ScoreList')droptable ScoreList
go
createtable ScoreList
(
Id intidentity(1,1)primarykey,
StudentId intnotnull,--学号外键
CSharp intnull,
SQLServer intnull,
UpdateTime datetimenotnull--更新时间)
go
--创建管理员表ifexists(select*from sysobjects where name ='Admins')droptable Admins
go
createtable Admins
(
LoginId intidentity(1000,1)primarykey,
LoginPwd varchar(20)notnull,--登录密码
AdminName varchar(20)notnull)
go
select*from Students