--指向当前要使用的数据库use master
go
--判断当前数据库是否存在ifexists(select*from sysdatabases where name='StudentManageDB')dropdatabase StudentManageDB--删除数据库
go
--创建数据库createdatabase StudentManageDB
onprimary(--数据库文件的逻辑名
name='StudentManageDB_data',--数据库物理文件名(绝对路径)
filename='D:\DB\StudentManageDB_data.mdf',--数据库文件初始大小
size=10MB,--数据文件增长量
filegrowth=1MB
)--创建日志文件
log on(
name='StudentManageDB_log',
filename='D:\DB\StudentManageDB_log.ldf',
size=2MB,
filegrowth=1MB
)
go
--创建学员信息数据表use StudentManageDB
go
ifexists(select*from sysobjects where name='Students')droptable Students
go
createtable Students
(
StudentId intidentity(100000,1),
StudentName varchar(20)notnull,
Gender char(2)notnull,
Birthday datetimenotnull,
StudentIdNo numeric(18,0)notnull,--身份证号
Age intnotnull,
PhoneNumber varchar(50),
StudentAddress 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,
SQLServerDB intnull,
UpdateTime datetime)
go
--创建管理员用户表ifexists(select*from sysobjects where name='Admins')droptable Admins
createtable Admins
(
LoginId intidentity(1000,1)primarykey,
LoginPwd varchar(20)notnull,
AdminName varchar(20)notnull)
go
--创建数据表的各种约束use StudentManageDB
go
--创建“主键”约束primary keyifexists(select*from sysobjects where name='pk_StudentId')altertable Students dropconstraint pk_StudentId
altertable Students
addconstraint pk_StudentId primarykey(StudentId)--创建检查约束checkifexists(select*from sysobjects where name='ck_Age')altertable Students dropconstraint ck_Age
altertable Students
addconstraint ck_Age check(Age between18and35)--创建唯一约束uniqueifexists(select*from sysobjects where name='uq_StudentIdNo')altertable Students dropconstraint uq_StudentIdNo
altertable Students
addconstraint uq_StudentIdNo unique(StudentIdNo)--创建身份证的长度检查约束ifexists(select*from sysobjects where name='ck_StudentIdNo')altertable Students dropconstraint ck_StudentIdNo
altertable Students
addconstraint ck_StudentIdNo check(len(StudentIdNo)=18)--创建默认约束 ifexists(select*from sysobjects where name='df_StudentAddress')altertable Students dropconstraint df_StudentAddress
altertable Students
addconstraint df_StudentAddress default('地址不详')for StudentAddress
ifexists(select*from sysobjects where name='df_UpdateTime')altertable ScoreList dropconstraint df_UpdateTime
altertable ScoreList
addconstraint df_UpdateTime default(getdate())for UpdateTime
--创建外键约束ifexists(select*from sysobjects where name='fk_classId')altertable Students dropconstraint fk_classId
altertable Students
addconstraint fk_classId foreignkey(ClassId)references StudentClass(ClassId)ifexists(select*from sysobjects where name='fk_StudentId')altertable ScoreList dropconstraint fk_StudentId
altertable ScoreList
addconstraint fk_StudentId foreignkey(StudentId)references Students(StudentId)-------------------------------------------插入数据--------------------------------------use StudentManageDB
go
--插入班级数据insertinto StudentClass(ClassId,ClassName)values(1,'软件1班')insertinto StudentClass(ClassId,ClassName)values(2,'软件2班')insertinto StudentClass(ClassId,ClassName)values(3,'计算机1班')insertinto StudentClass(ClassId,ClassName)values(4,'计算机2班')--insert into StudentClass(ClassId,ClassName) values(5,'网络1班')--insert into StudentClass(ClassId,ClassName) values(6,'网络2班')--插入学员信息insertinto Students (StudentName,Gender,Birthday,Age,StudentIdNo,PhoneNumber,StudentAddress,ClassId)values('王小虎','男','1989-08-07',22,120223198908071111,'022-22222222','天津市南开区红磡公寓5-5-102',1)insertinto Students (StudentName,Gender,Birthday,Age,StudentIdNo,PhoneNumber,StudentAddress,ClassId)values('贺小张','女','1989-05-06',22,120223198905062426,'022-33333333','天津市河北区王串场58号',2)insertinto Students (StudentName,Gender,Birthday,Age,StudentIdNo,PhoneNumber,StudentAddress,ClassId)values('马小李','男','1990-02-07',21,120223199002078915,'022-44444444','天津市红桥区丁字沽曙光路79号',4)insertinto Students (StudentName,Gender,Birthday,Age,StudentIdNo,PhoneNumber,StudentAddress,ClassId)values('冯小强','女','1987-05-12',24,130223198705125167,'022-55555555',default,2)insertinto Students (StudentName,Gender,Birthday,Age,StudentIdNo,PhoneNumber,StudentAddress,ClassId)values('杜小丽','女','1986-05-08',25,130223198605081528,'022-66666666','河北衡水路北道69号',1)insertinto Students (StudentName,Gender,Birthday,Age,StudentIdNo,PhoneNumber,StudentAddress,ClassId)values('王俊桥','男','1987-07-18',24,130223198707182235,'022-77777777',default,1)insertinto Students (StudentName,Gender,Birthday,Age,StudentIdNo,PhoneNumber,StudentAddress,ClassId)values('张永利','男','1988-09-28',24,130223198909282235,'022-88888888','河北保定市风华道12号',3)insertinto Students (StudentName,Gender,Birthday,Age,StudentIdNo,PhoneNumber,StudentAddress,ClassId)values('李铭','男','1987-01-18',24,130223198701182257,'022-99999999','河北邢台市幸福路5号',1)insertinto Students (StudentName,Gender,Birthday,Age,StudentIdNo,PhoneNumber,StudentAddress,ClassId)values('宁俊燕','女','1987-06-15',24,130223198706152211,'022-11111111',default,3)insertinto Students (StudentName,Gender,Birthday,Age,StudentIdNo,PhoneNumber,StudentAddress,ClassId)values('刘玲玲','女','1989-08-19',24,130223198908192235,'022-11111222',default,4)--插入成绩信息insertinto ScoreList (StudentId,CSharp,SQLServerDB)values(100000,60,78)insertinto ScoreList (StudentId,CSharp,SQLServerDB)values(100001,55,88)insertinto ScoreList (StudentId,CSharp,SQLServerDB)values(100002,90,58)insertinto ScoreList (StudentId,CSharp,SQLServerDB)values(100003,88,75)insertinto ScoreList (StudentId,CSharp,SQLServerDB)values(100004,62,88)insertinto ScoreList (StudentId,CSharp,SQLServerDB)values(100006,52,80)insertinto ScoreList (StudentId,CSharp,SQLServerDB)values(100007,91,66)insertinto ScoreList (StudentId,CSharp,SQLServerDB)values(100009,78,35)--插入管理员信息insertinto Admins (LoginPwd,AdminName)values(123456,'王晓军')insertinto Admins (LoginPwd,AdminName)values(123456,'张明丽')--删除学员信息--delete from Students --truncate table Students --删除全部数据以后,自动标识列重新编号--显示学员信息和班级信息select*from Students
select*from StudentClass
select*from ScoreList
select*from Admins
use StudentManageDB
go
--创建主键约束ifexists(select*from sysobjects where name='pk_StudentId')altertable Students dropconstraint pk_StudentId
altertable Students addconstraint pk_StudentId primarykey(StudentId)--创建唯一约束ifexists(select*from sysobjects where name='uq_StudentIdNo')altertable Students dropconstraint uq_StudentIdNo
altertable Students addconstraint uq_StudentIdNo unique(StudentIdNo)--创建检查约束ifexists(select*from sysobjects where name='ck_Age')altertable Students dropconstraint ck_Age
altertable Students addconstraint ck_Age check(Age between18and25)ifexists(select*from sysobjects where name='ck_PhoneNumber')altertable Students dropconstraint ck_PhoneNumber
altertable Students addconstraint ck_PhoneNumber check(len(PhoneNumber)=11)update Students set PhoneNumber='13099012876'where StudentId=10000select*from Students
ifexists(select*from sysobjects where name='df_StudentAddress')altertable Students dropconstraint df_StudentAddress
altertable Students addconstraint df_StudentAddress default('地址不详')for StudentAddress
insertinto Students (StudentName,Gender,Birthday,Age,StudentIdNo ,PhoneNumber,
StudentAddress,ClassId)values('李小璐','女','1989-01-12',24,120229198901121315,'13099012876',default,1)insertinto Students (StudentName,Gender,Birthday,Age,StudentIdNo ,PhoneNumber,
ClassId)values('李小璐','女','1989-01-12',24,120229198901121316,'13099012876',1)insertinto StudentClass (ClassId,ClassName)values(1,'软件1班')ifexists(select*from sysobjects where name='fk_ClassId')altertable Students dropconstraint fk_ClassId
altertable Students addconstraint fk_ClassId foreignkey(ClassId)references StudentClass(ClassId)select*from studentClass
use StudentManageDB
go
select StudentName as 姓名,Gender as 性别,出生日期=birthday
from Students where Gender='男'select 姓名=StudentName,地址和电话=StudentAddress+'【'+PhoneNumber+'】'from Students where Gender='男'select 总成绩=CSharp+SQLServerDB from ScoreList
select*from ScoreList
insertinto ScoreList(StudentId,CSharp)values(100009,78)select*from ScoreList where SQLServerDB isnullselect StudentName as 姓名,Gender as 性别,出生日期=birthday,所在学校='北京大学'from Students where Gender='男'selecttop5 StudentName,Gender,Birthday from Students
selecttop20percent StudentName,Gender,Birthday from Students
select StudentId,(CSharp+5)as C#,DB=SQLServerDBfrom ScoreList where(CSharp+5)>90orderby CSharp ASCselect StudentId,(CSharp+5)as C#,DB=SQLServerDBfrom ScoreList where(CSharp+5)>90orderby CSharp DESCselecttop3 StudentId,CSharp as C#,DB=SQLServerDBfrom ScoreList
where StudentId notin(selecttop6 StudentId from ScoreList orderby SQLServerDB DESC,CSharp DESC)orderby SQLServerDB DESC,CSharp DESCselect StudentId,CSharp as C#,DB=SQLServerDBfrom ScoreList
orderby SQLServerDB DESC,CSharp DESC
use StudentManageDB
go
select StudentName,StudentAddress from Students
where StudentAddress like'天津%'select StudentName,StudentAddress from Students
where StudentName like'%小%'select*from ScoreList
where CSharp between80and90select StudentName,StudentAddress,Birthday from Students
where Birthday between'1987-01-01'and'1988-01-01'select StudentName,StudentAddress,age from Students
where Age in(21,22,23)select StudentName,StudentAddress,age from Students
where StudentName in('王小虎','贺小张')selectSUM(CSharp)as C#总成绩 from ScoreListselect 总人数=COUNT(*)from Students
selectMAX(Csharp)as C#最高分 ,MIN(CSharp) as C#最低分,AVG(CSharp) as C#最低分 from ScoreListselect Students.StudentId,C#成绩=CSharp,StudentName,ClassNamefrom ScoreList
innerjoin Students on Students.StudentId=ScoreList.StudentId
innerjoin StudentClass on Students.ClassId=StudentClass.ClassId
where CSharp >80select Students.StudentId,StudentName,Gender ,C#成绩=CSharp from Studentsleftouterjoin ScoreList on Students.StudentId=ScoreList.StudentId
where Gender='男'select Students.StudentId,StudentName,Gender ,C#成绩=CSharp from ScoreListleftouterjoin Students on Students.StudentId=ScoreList.StudentId
where Gender='男'select 班级=StudentClass.ClassName,人数=COUNT(*),C#最高分=Max(CSharp),DB最高分=MAX(SQLServerDB),AVG(CSharp)as C#平均分,AVG(SQLServerDB) as DB平均分from Students
innerJoin StudentClass on Students.ClassId =StudentClass.ClassId
innerjoin ScoreList on ScoreList.StudentId=Students.StudentId
groupby ClassName
havingAVG(CSharp)>=70andAVG(SQLServerDB)>=70select*from ScoreList
select StudentId from ScoreList groupby StudentId havingCOUNT(*)>1select*from ScoreList
where StudentId in(select StudentId from ScoreList groupby StudentId havingCOUNT(*)>1)orderby StudentId
select*from ScoreList
where(selectCOUNT(*)from ScoreList s where s.StudentId=ScoreList.StudentId)>1orderby StudentId
use StudentManageDB
go
insertinto ScoreList (StudentId,CSharp,SQLServerDB)values(100006,52,80)insertinto ScoreList (StudentId,CSharp,SQLServerDB)values(100007,91,66)insertinto ScoreList (StudentId,CSharp,SQLServerDB)values(100009,78,35)select*from ScoreList orderby StudentId
--在知道那个字段重复的情况select StudentId from ScoreList groupby StudentId havingCOUNT(*)>1--查询所有重复的记录select*from ScoreList
where StudentId in(select StudentId from ScoreList groupby StudentId havingCOUNT(*)>1)orderby StudentId
--其他方法select*from ScoreList
where(selectCOUNT(*)from ScoreList s where s.StudentId=ScoreList.StudentId)>1orderby StudentId
--过滤掉重复数据selectdistinct StudentId,CSharp from ScoreList
selectdistinct StudentId,CSharp,SQLServerDB from ScoreList
--指向当前要使用的数据库use master
go
--判断当前数据库是否存在ifexists(select*from sysdatabases where name='SMDB')dropdatabase SMDB --删除数据库
go
--创建数据库createdatabase SMDB
onprimary(--数据库文件的逻辑名
name='SMDB_data',--数据库物理文件名(绝对路径)
filename='D:\DB\SMDB_data.mdf',--数据库文件初始大小
size=10MB,--数据文件增长量
filegrowth=1MB
)--创建日志文件
log on(
name='SMDB_log',
filename='D:\DB\SMDB_log.ldf',
size=2MB,
filegrowth=1MB
)
go
--创建学员信息数据表use SMDB
go
ifexists(select*from sysobjects where name='Students')droptable Students
go
createtable Students
(
StudentId intidentity(100000,1),
StudentName varchar(20)notnull,
Gender char(2)notnull,
Birthday smalldatetime notnull,
StudentIdNo numeric(18,0)notnull,--身份证号
CardNo varchar(20)notnull,--考勤卡号
StuImage textnull,--学员照片
Age intnotnull,
PhoneNumber varchar(50),
StudentAddress 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,
SQLServerDB intnull,
UpdateTime smalldatetime notnull)
go
--创建考勤表ifexists(select*from sysobjects where name='Attendance')droptable Attendance
createtable Attendance
(
Id intidentity(100000,1)primarykey,--标识列
CardNo varchar(20)notnull,--学员卡号
DTime smalldatetime notnull--打卡时间)
go
--创建管理员用户表ifexists(select*from sysobjects where name='Admins')droptable Admins
createtable Admins
(
LoginId intidentity(1000,1)primarykey,
LoginPwd varchar(20)notnull,
AdminName varchar(20)notnull)
go
--创建数据表的各种约束use SMDB
go
--创建“主键”约束primary keyifexists(select*from sysobjects where name='pk_StudentId')altertable Students dropconstraint pk_StudentId
altertable Students
addconstraint pk_StudentId primarykey(StudentId)--创建检查约束checkifexists(select*from sysobjects where name='ck_Age')altertable Students dropconstraint ck_Age
altertable Students
addconstraint ck_Age check(Age between18and35)--创建唯一约束uniqueifexists(select*from sysobjects where name='uq_StudentIdNo')altertable Students dropconstraint uq_StudentIdNo
altertable Students
addconstraint uq_StudentIdNo unique(StudentIdNo)ifexists(select*from sysobjects where name='uq_CardNo')altertable Students dropconstraint uq_CardNo
altertable Students
addconstraint uq_CardNo unique(CardNo)--创建身份证的长度检查约束ifexists(select*from sysobjects where name='ck_StudentIdNo')altertable Students dropconstraint ck_StudentIdNo
altertable Students
addconstraint ck_StudentIdNo check(len(StudentIdNo)=18)--创建默认约束 ifexists(select*from sysobjects where name='df_StudentAddress')altertable Students dropconstraint df_StudentAddress
altertable Students
addconstraint df_StudentAddress default('地址不详')for StudentAddress
ifexists(select*from sysobjects where name='df_UpdateTime')altertable ScoreList dropconstraint df_UpdateTime
altertable ScoreList
addconstraint df_UpdateTime default(getdate())for UpdateTime
ifexists(select*from sysobjects where name='df_DTime')altertable Attendance dropconstraint df_DTime
altertable Attendance
addconstraint df_DTime default(getdate())for DTime
--创建外键约束ifexists(select*from sysobjects where name='fk_classId')altertable Students dropconstraint fk_classId
altertable Students
addconstraint fk_classId foreignkey(ClassId)references StudentClass(ClassId)ifexists(select*from sysobjects where name='fk_StudentId')altertable ScoreList dropconstraint fk_StudentId
altertable ScoreList
addconstraint fk_StudentId foreignkey(StudentId)references Students(StudentId)-------------------------------------------插入数据--------------------------------------use SMDB
go
--插入班级数据insertinto StudentClass(ClassId,ClassName)values(1,'软件1班')insertinto StudentClass(ClassId,ClassName)values(2,'软件2班')insertinto StudentClass(ClassId,ClassName)values(3,'计算机1班')insertinto StudentClass(ClassId,ClassName)values(4,'计算机2班')insertinto StudentClass(ClassId,ClassName)values(5,'网络1班')insertinto StudentClass(ClassId,ClassName)values(6,'网络2班')--插入学员信息insertinto Students (StudentName,Gender,Birthday,Age,StudentIdNo,CardNo,PhoneNumber,StudentAddress,ClassId)values('王小虎','男','1989-08-07',22,120223198908071111,'0004018766','022-22222222','天津市南开区红磡公寓5-5-102',1)insertinto Students (StudentName,Gender,Birthday,Age,StudentIdNo,CardNo,PhoneNumber,StudentAddress,ClassId)values('贺小张','女','1989-05-06',22,120223198905062426,'0006394426','022-33333333','天津市河北区王串场58号',2)insertinto Students (StudentName,Gender,Birthday,Age,StudentIdNo,CardNo,PhoneNumber,StudentAddress,ClassId)values('马小李','男','1990-02-07',21,120223199002078915,'0006073516','022-44444444','天津市红桥区丁字沽曙光路79号',4)insertinto Students (StudentName,Gender,Birthday,Age,StudentIdNo,CardNo,PhoneNumber,StudentAddress,ClassId)values('冯小强','女','1987-05-12',24,130223198705125167,'0006254540','022-55555555',default,2)insertinto Students (StudentName,Gender,Birthday,Age,StudentIdNo,CardNo,PhoneNumber,StudentAddress,ClassId)values('杜小丽','女','1986-05-08',25,130223198605081528,'0006403803','022-66666666','河北衡水路北道69号',1)insertinto Students (StudentName,Gender,Birthday,Age,StudentIdNo,CardNo,PhoneNumber,StudentAddress,ClassId)values('王俊桥','男','1987-07-18',24,130223198707182235,'0006404372','022-77777777',default,1)insertinto Students (StudentName,Gender,Birthday,Age,StudentIdNo,CardNo,PhoneNumber,StudentAddress,ClassId)values('张永利','男','1988-09-28',24,130223198909282235,'0006092947','022-88888888','河北保定市风华道12号',3)insertinto Students (StudentName,Gender,Birthday,Age,StudentIdNo,CardNo,PhoneNumber,StudentAddress,ClassId)values('李铭','男','1987-01-18',24,130223198701182257,'0006294564','022-99999999','河北邢台市幸福路5号',1)insertinto Students (StudentName,Gender,Birthday,Age,StudentIdNo,CardNo,PhoneNumber,StudentAddress,ClassId)values('宁俊燕','女','1987-06-15',24,130223198706152211,'0006092450','022-11111111',default,3)insertinto Students (StudentName,Gender,Birthday,Age,StudentIdNo,CardNo,PhoneNumber,StudentAddress,ClassId)values('刘玲玲','女','1989-08-19',24,130223198908192235,'0006069457','022-11111222',default,4)insertinto Students (StudentName,Gender,Birthday,Age,StudentIdNo,CardNo,PhoneNumber,StudentAddress,ClassId)values('王小军','女','1986-05-08',25,130224198605081528,'0006403820','022-66666666','河北衡水路北道69号',1)insertinto Students (StudentName,Gender,Birthday,Age,StudentIdNo,CardNo,PhoneNumber,StudentAddress,ClassId)values('刘小丽','女','1986-05-08',25,130225198605081528,'0006403821','022-66666666','河北衡水路北道69号',1)insertinto Students (StudentName,Gender,Birthday,Age,StudentIdNo,CardNo,PhoneNumber,StudentAddress,ClassId)values('张慧鑫','女','1986-05-08',25,130226198605081528,'0006403822','022-66666666','河北衡水路北道69号',1)insertinto Students (StudentName,Gender,Birthday,Age,StudentIdNo,CardNo,PhoneNumber,StudentAddress,ClassId)values('李素云','女','1986-05-08',25,130227198605081528,'0006403823','022-66666666','河北衡水路北道69号',1)insertinto Students (StudentName,Gender,Birthday,Age,StudentIdNo,CardNo,PhoneNumber,StudentAddress,ClassId)values('赵小金','女','1986-05-08',25,130228198605081528,'0006403824','022-66666666','河北衡水路北道69号',1)insertinto Students (StudentName,Gender,Birthday,Age,StudentIdNo,CardNo,PhoneNumber,StudentAddress,ClassId)values('王浩宇','男','1986-05-08',25,130229198605081528,'0006403825','022-66666666','河北衡水路北道69号',1)insertinto Students (StudentName,Gender,Birthday,Age,StudentIdNo,CardNo,PhoneNumber,StudentAddress,ClassId)values('崔永鑫','女','1986-05-08',25,130222198605081528,'0006403826','022-66666666','河北衡水路北道69号',1)insertinto Students (StudentName,Gender,Birthday,Age,StudentIdNo,CardNo,PhoneNumber,StudentAddress,ClassId)values('包丽云','女','1986-05-08',25,130220198605081528,'0006403827','022-66666666','河北衡水路北道69号',1)insertinto Students (StudentName,Gender,Birthday,Age,StudentIdNo,CardNo,PhoneNumber,StudentAddress,ClassId)values('孙丽媛','女','1986-05-08',25,130228198605081530,'0006403854','022-66666666','河北衡水路北道69号',1)insertinto Students (StudentName,Gender,Birthday,Age,StudentIdNo,CardNo,PhoneNumber,StudentAddress,ClassId)values('郝志云','男','1986-05-08',25,130229198605081531,'0006403855','022-66666666','河北衡水路北道69号',1)insertinto Students (StudentName,Gender,Birthday,Age,StudentIdNo,CardNo,PhoneNumber,StudentAddress,ClassId)values('王保华','女','1986-05-08',25,130222198605081532,'0006403856','022-66666666','河北衡水路北道69号',1)insertinto Students (StudentName,Gender,Birthday,Age,StudentIdNo,CardNo,PhoneNumber,StudentAddress,ClassId)values('李丽颖','女','1986-05-08',25,130220198605081544,'0006403857','022-66666666','河北衡水路北道69号',1)--插入成绩信息insertinto ScoreList (StudentId,CSharp,SQLServerDB)values(100000,60,78)insertinto ScoreList (StudentId,CSharp,SQLServerDB)values(100001,55,88)insertinto ScoreList (StudentId,CSharp,SQLServerDB)values(100002,90,58)insertinto ScoreList (StudentId,CSharp,SQLServerDB)values(100003,88,75)insertinto ScoreList (StudentId,CSharp,SQLServerDB)values(100004,62,88)insertinto ScoreList (StudentId,CSharp,SQLServerDB)values(100006,52,80)insertinto ScoreList (StudentId,CSharp,SQLServerDB)values(100007,91,66)insertinto ScoreList (StudentId,CSharp,SQLServerDB)values(100009,78,35)insertinto ScoreList (StudentId,CSharp,SQLServerDB)values(100000,60,78)insertinto ScoreList (StudentId,CSharp,SQLServerDB)values(100001,55,88)insertinto ScoreList (StudentId,CSharp,SQLServerDB)values(100002,90,58)insertinto ScoreList (StudentId,CSharp,SQLServerDB)values(100003,88,75)insertinto ScoreList (StudentId,CSharp,SQLServerDB)values(100004,62,88)insertinto ScoreList (StudentId,CSharp,SQLServerDB)values(100006,52,80)insertinto ScoreList (StudentId,CSharp,SQLServerDB)values(100007,91,66)insertinto ScoreList (StudentId,CSharp,SQLServerDB)values(100009,78,35)--插入管理员信息insertinto Admins (LoginPwd,AdminName)values(123456,'王晓军')insertinto Admins (LoginPwd,AdminName)values(123456,'张明丽')--删除学员信息--delete from Students --truncate table Students --删除全部数据以后,自动标识列重新编号--显示学员信息和班级信息select*from Students
select*from StudentClass
select*from ScoreList
select*from Admins
select*from Attendance
USE [master]GOIF EXISTS(SELECT * FROM sysdatabases WHERE NAME='ScadaData')BEGIN DROP DATABASE ScadaData --如果数据库存在先删掉数据库ENDGOCREATE DATABASE ScadaDataONPRIMARY --创建主数据库文件( NAME='ScadaData', FILENAME='E:\ScadaData.mdf', SIZE=5MB