sql
data source=bxxx.xxxw.com,1433;User ID=xxxx59;pwd=lixxx6;Initial Catalog=bxxx9_db
建表
create table Students
(
StudentId int identity(100000,1) ,
StudentName varchar(20) not null,
Gender char(2) not null,
Birthday smalldatetime not null,
StudentIdNo numeric(18,0) not null,--身份证号
CardNo varchar(20) not null,--考勤卡号
PhoneNumber varchar(50),
StudentAddress varchar(500),
ClassId int not null --班级外键
)
create table StudentClass
(
ClassIdint primary key,
ClassName varchar(20) not null
)
create table ScoreList
(
Id int identity(1,1) primary key,
StudentId int not null,
CSharp int null,
SQLServerDB int null,
UpdateTime smalldatetime not null
)
create table Attendance
(
Idint identity(100000,1) primary key,--标识列
CardNo varchar(20) not null,--学员卡号
DTime smalldatetime not null --打卡时间
)
create table Admins
(
LoginIdint identity(1000,1) primary key,
LoginPwd varchar(20) not null,
AdminName varchar(20) not null
)
alter table Students
add constraint pk_StudentId primary key(StudentId)
alter table Students
add constraint uq_StudentIdNo unique(StudentIdNo)
alter table Students
add constraint uq_CardNo unique (CardNo)
alter table Students
add constraint ck_StudentIdNo check(len(StudentIdNo)=18)
alter table Students
add constraint df_StudentAddress default ('地址不详' ) for StudentAddress
alter table ScoreList
add constraint df_UpdateTime default(getdate() ) for UpdateTime
alter table Attendance
add constraint df_DTime default (getdate()) for DTime
alter table Students
add constraint fk_classId foreign key(ClassId) references StudentClass(ClassId)
alter table ScoreList
add constraint fk_StudentId foreignkey(StudentId) references Students(StudentId)
insert into StudentClass(ClassId,ClassName)values(1,'软件a班')
insert into StudentClass(ClassId,ClassName)values(2,'软件b班')
insert into StudentClass(ClassId,ClassName)values(3,'计算机c班')
insert into StudentClass(ClassId,ClassName)values(4,'计算机d班')
insert into StudentClass(ClassId,ClassName)values(5,'网络e班')
insert into StudentClass(ClassId,ClassName)values(6,'网络f班')
insert into Students(StudentName,Gender,Birthday,StudentIdNo,CardNo,PhoneNumber,StudentAddress,ClassId)
values('王虎','男','1989-08-07',120223198908071111,'0004018766','022-222222','天津2',1)
insert into Students (StudentName,Gender,Birthday,StudentIdNo,CardNo,PhoneNumber,StudentAddress,ClassId)
values('贺张','女','1989-05-06',120223198905062426,'0006394426','022-333333','天王串场58号',2)
insert into Students(StudentName,Gender,Birthday,StudentIdNo,CardNo,PhoneNumber,StudentAddress,ClassId)
values('马李','男','1990-02-07',120223199002078915,'0006073516','022-444444','天丁曙光路79号',4)
insert into Students(StudentName,Gender,Birthday,StudentIdNo,CardNo,PhoneNumber,StudentAddress,ClassId)
values('冯强','女','1987-05-12',130223198705125167,'0006254540','022-555555',default,2)
insert into Students(StudentName,Gender,Birthday,StudentIdNo,CardNo,PhoneNumber,StudentAddress,ClassId)
values('杜丽','女','1986-05-08',130223198605081528,'0006403803','022-666666','河路北道69号',1)
insert into Students(StudentName,Gender,Birthday,StudentIdNo,CardNo,PhoneNumber,StudentAddress,ClassId)
values('王桥','男','1987-07-18',130223198707182235,'0006404372','022-77777777',default,1)
insert into Students (StudentName,Gender,Birthday,StudentIdNo,CardNo,PhoneNumber,StudentAddress,ClassId)
values('张利','男','1988-09-28',130223198909282235,'0006092947','022-88888888','河风华道12号',3)
insert into Students(StudentName,Gender,Birthday,StudentIdNo,CardNo,PhoneNumber,StudentAddress,ClassId)
values('李铭','男','1987-01-18',130223198701182257,'0006294564','022-99999999','河台市幸福路5号',1)
insert into Students(StudentName,Gender,Birthday,StudentIdNo,CardNo,PhoneNumber,StudentAddress,ClassId)
values('宁燕','女','1987-06-15',130223198706152211,'0006092450','022-11111111',default,3)
insert into Students(StudentName,Gender,Birthday,StudentIdNo,CardNo,PhoneNumber,StudentAddress,ClassId)
values('刘玲','女','1989-08-19',130223198908192235,'0006069457','022-11111222',default,4)
insert into ScoreList(StudentId,CSharp,SQLServerDB)values(100000,60,78)
insert into ScoreList(StudentId,CSharp,SQLServerDB)values(100001,55,88)
insert into ScoreList (StudentId,CSharp,SQLServerDB)values(100002,90,58)
insert into ScoreList(StudentId,CSharp,SQLServerDB)values(100003,88,75)
insert into ScoreList(StudentId,CSharp,SQLServerDB)values(100004,62,88)
insert into ScoreList(StudentId,CSharp,SQLServerDB)values(100006,52,80)
insert into ScoreList(StudentId,CSharp,SQLServerDB)values(100007,91,66)
insert into ScoreList(StudentId,CSharp,SQLServerDB)values(100009,78,35)
insert into Admins (LoginPwd,AdminName)values(123456,'刘红')
insert into Admins (LoginPwd,AdminName)values(123456,'张丽')
select * from Students
select * from StudentClass
select * from ScoreList
select * from Admins
select * from Attendance