use master
go
create database scd --建立scd资料库
go
use scd
go
create rule age_rule --建立规则
as @age = 18
go
create table student --建立资料表student
( student_id varchar(16) null,
student_name varchar(16) null,
age int null,
class_no varchar(16))
go
exec sp_bindrule age_rule, [studentage] --绑定规则
go
create table class --建立资料表class
( class_no varchar(16) null,
specialties_name varchar(32) null,
department_name varchar(32) null,
enrolment_name int check(enrolment_name <2008) null) --加入入学年份check约束
go
create table department --建立资料表department
( department_no varchar(16) null,
department_name varchar(32) null)
第一个:
select MAX(职工号)
from 职工
where 职工 部门号 in (select 部门号 from 部门)
第二个:
create proc procStaff
@staffID nvarchar(30) --@staffID 表示职工号
as
select 月工资, avg(select 月工资 from 职工 where 职工号 = @staffID
and 部门 in (select 部门号 from 部门))
from 职工
where 职工号 = @staffID
第三个:
select productID , productName , Max(clickNum)
from productInfo
where productInfoparentID in(select chassID from className group by classID)
group by productName
order by Max(clickNum) desc
1、创建数据库
create
database
学生成绩数据库
on
primary
(name='学生成绩数据库_mdf',
filename='e:\学生成绩数据库mdb',
size=1,
maxsize=10,
filegrowth
=10%)
log
on
(name='学生成绩数据库_ldf',
filename='e:\学生成绩数据库ldf',
size=1,
maxsize=10,
filegrowth
=10%)
2、创建课程表
create
table
(课程号
char(6)
primary
key,
课程名称
char(20)
not
null,
任课教师
char(8))
3、
创建学生表
create
table
学生表
(学号
char(6)
primary
key,
姓名
char(8)
not
null,
性别
char(2)
constraint
ck_性别
check(
性别
in
('男','女')),
民族
char(20)
not
null
default
'汉')
4、创建成绩表
create
table
成绩表
(学号
char(6)
not
null
foreign
key(学号)
references
学生表(学号),
课程号
char(6)
not
null
foreign
key(课程号)
references
课程表(课程号),
分数
int
constraint
ck_分数
check(分数
between
0
and
150))
5、添加信息
insert
课程表(课程号,课程名)
values
('100001',
'大学语文')
insert
课程表(课程号,课程名)
values
('100002',
'大学英语')
6
写出创建成绩表视图(学号,姓名,课程号,课程名称,成绩)的代码
create
view
成绩表视图
as
select
学生表学号,姓名,课程表课程号,课程名称,成绩
from
学生表,课程表,成绩表
where
学生表学号=成绩表学号
and
成绩表课程号=课程表课程号
7
写出计算大学语文课程成绩最高分、最低分、平均分的代码
select
max(分数)
'最高分数',min(分数)
'最低分数',avg(分数)
'平均分数'
from
成绩表
where
学号
in
(select
学号
from
课程表
where
课程名称='大学语文')
8、
检索姓李的女同学的信息:姓名、性别、民族
select
姓名,性别,民族
from
学生表
where
姓名
like
'李%'
and
性别='女'
1select pname,qty from p,s where mno='m1' and ppno=spno
2select pname as '商品名',avg(qty) as 平均销售量 from s,p,m where mcity='上海' and smno=mmno and ppno=spno
3select MNO,pno,qty from s where pno in(select pno form p where color='red'
4π pno,pname,qty (φ(pno(s)=pno(p)))
5π pname,qty φ(mno='M1'∧pno(p)=pno(s))
π是投影的意思 φ是选择的意思,我自己做的,感觉正确你再检查下
--1,找出选修了学号为“05201”的学生所选修所有课程的学生姓名
select 姓名
from student
where 学号 in (select 学号
from xuanke
where 课程号 in (select 课程号
from xuanke
where 学号 = '05201')
group by 学号
having count() = (select count()
from xuanke
where 学号 = '05201'))
--2,求至少选修了“ *** 作系统”和“数据结构”课程的学生学号
select 学号
from xuanke
where 课程号 in (select 课程号
from course
where 课程名 in (' *** 作系统', '数据结构'))
group by 学号
having count() = 2
--3,查询所有不姓刘的学生的姓名和平均成绩
select 姓名, avg(成绩) as '平均成绩'
from student, xuanke
where student学号 = xuanke学号 and 姓名 not like '刘%'
group by 姓名
这题目很有意思,做得我很爽……嘿嘿!
D
也就是
数据库描述语言 (DDL) CREATE TABLE 之类的语句
和
数据库 *** 作语言 (DML) INSERT /UPDATE /DELETE 之类的语句。
一:
1c
2a
3d
4d
5a/d
6b
7d
8d
9c
10d
11b
12d
13b
14c
15b
16c
17d
18c
19b
20a/d
二:
1、
你输入的是a或者b
2、
i=2
j=1
3、
0
1
2
3
4
6
7
4、
从Student表选择StudentId列的最后一位为2的行插入StudentBak表
影响行数:3
5、
StudentBak表:
2003300102
李明明
2003300202
王五
2003300302
张红
以上就是关于SQL数据库的设计题,T-SQL语言。高分求解答!全部的内容,包括:SQL数据库的设计题,T-SQL语言。高分求解答!、这几道题用数据库的SQL语言怎么实现、数据库题目sql语言等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)