(3)日志文件:逻辑名为SchoolLog,文件名为“D:\School\SchoolLog.ldf,”文件初始大小为10MB,文件的最大大小为50MB,文件的增长率为1MB;
create database School
on primary
(name='SchoolData',
filename='D:\School\SchoolData.mdf',
size=50MB,
maxsize=unlimited ,
filegrowth=20%)
log on(
name='SchoolLog',
filename='D:\School\SchoolLog.ldf',
size=10MB,
maxsize=50MB,
filegrowth=1MB
)
2.创建数据类型和表,增加约束。
(1)表tblstudent(学生表):
SQL语句如下:
create table tblstudent(
stuID bigint primary key,
stuName nvarchar(10) not null,
stuSex nchar(1) not null,
stuBirth datetime,
stuNum nvarchar(18) unique,
Departed int,
City nvarchar(10) default '杭州' ,//设置默认值
constraint ck_tblstudent_stusex check(stuSex IN('男','女') ),//建立约束
constraint ck_tblstudent_stuBirth check(stuBirth
(2)表tblscore(成绩表):
sql语句如下:
create table tblscope(
stuID bigint ,
Math int,
English int,
Computer int,
Summary int,
/*建立外键约束*/
constraint stuID_FK foreign key (stuID) references tblstudent(stuID),
constraint ck_tblscope_Math CHECK(Math between 0 and 100 or Math is null),
constraint ck_tblscope_English CHECK(English between 0 and 100 or English is null),
constraint ck_tblscope_Computer CHECK(Computer between 0 and 100 or Computer is null)
)
/*批量插入,当添加一条新的记录时,可以省略字段名,但每个字段都必须有值)*/
insert into tblscope values(1001,70,80,90,null),(1002,45,55,60,null);
SQL语句如下:
/*第一步:从tblscope表中找出最高成绩*/
select max(Math+English+Computer) from tblscope
/*第二步:从tblscope表中找出总成绩=最高分的那位学生ID*/
select stuID from tblscope group by stuID having
sum(Math+English+Computer)=(select max(Math+English+Computer) from tblscope )
/*第三步:根据最高分查出来的学生stuID再来查询学生信息*/
select stuID,stuName from tblstudent where stuID=
(select stuID from tblscope group by stuID having
sum(Math+English+Computer)=(select max(Math+English+Computer) from tblscope ))
SQL语句如下:
select stuSex as '性别',count(*) as '人数 'from tblstudent group by stuSex
恒生电子2016(2018)实习生招聘数据库试题