SQL实验

发布 2022-09-21 01:29:28 阅读 6928

实验一 sql语言。实验1.1

创建数据库表customers(cid,cname,city,discnt)数据表agents(aid,aname,city,percent)数据表products(pid,pname)其中cid,aid,pid为主键具有唯一性约束。

create table customer

cid char(8) unique,cname char(20),city char(8),discnt int,primary key(cid))

create table agents

aid char(8) unique,aname char(20),city char(8),percents float,primary key(aid))

create table products

pid char(8) unique,pname char(20),primary key(pid))

创建数据表orders

create table orders

ordna char(8) unique,month int,cid char(8),aid char(8),pid char (8),qty int,dollars float,primary key(ordna),foreign key(cid) references customer,foreign key(aid)

references agents,foreign key(pid) references products)

增加数据库表products的三个属性列。

alter table products add city char(8)

alter table products add quantity int

alter table products add price float

增加前。增加后。

为以上四个表建立各自的按主建增序排列的索引。

create index xsno on customer(cid)

create index xsno on agents(aid)

create index xsno on products(pid)

create index xsno on orders(ordna)

取消四个索引。

drop index

drop index

drop index

drop index 实验1.2

查询全部课程的详细记录。

select * from courses

查询所有有选课的学生的编号。

select sid from choices

查询课时<88(小时)的课程的编号。

select cid from courses where hour<88

请找出总分超过400分的学生。

select sid from choices group by sid h**ing sum(score)>400

查询课程的总数。

select count(cid) from courses

查询所有课程和选修该课的学生的总数。

select cid,count(sid) from choices group by cid

查询选修成绩合格的课程超过两门的学生的编号。

select sid from choices where score>60 group by sid h**ing count(cid)>2

统计各个学生的选修课程数目和平均成绩。

select sid,count(cid),**g(score) from choices group by sid

查询选修j**a的所有学生的编号。

select from students,choices,courses where and and 'j**a'

分别适用等值连接和谓词in两种方式查询姓名为sssht的学生所选的课程的编号及成绩。

select from choices,students where sname='sssht' and

select cid,score from choices where sid in(

select from students where sname='sssht')

查询课时比课程c++多的课程的编号。

select from courses as c1,courses as c2

where > and 'c++'

查询选修c++课程的成绩比姓名为znkoo的学生高的所有学生的编号和姓名。

select sid,sname from students where sid in(

select from choices as c1,choices as c2

where > and

and sid from students where sname='znkoo')

and cid from courses where cname='c++'

找出和学生***或学生***的年纪一样的学生的姓名。

select sname from students where grade in(

select grade from students where sid in('883794999','850955252'))

查询没有选修j**a的学生的名称。

select sname from students where sid not in(

select sid from choices where cid=(select cid from courses where cname='j**a'))

找出课时最少的课程的详细信息。

select * from courses where hour<=all(select hour from courses)

查询工资最高的老师的编号和所教授的课程。

select from choices where not exists(

select*from teachers where >=

select salary from teachers where

找出选修课程erp成绩最高的学生编号。

select sid from choices where score=

select max(score)from choices where cid=(

select cid from courses where cname='erp'))

查询没有学生选的课程的名称。

select cname from courses where cid not in(

select cid from choices)

找出讲授课程uml的教师讲授的所有课程名称。

select cname from courses where cid=some(

select cid from choices where tid=some(

select tid from courses,choices where cname='uml'and

查询选修编号为***的教师开设的所有课程的学生编号。

select sname from students where not exists(

select*from choices as c1 where not exists(

select*from choices as c2 where and and '200102901'))

查询选修课程打database的学生的集合与选修课程uml的学生集合的并集。

select sid from choices,courses where

and 'datebase'

unionselect sid from choices,courses where and 'uml'

实现集合交运算,查询既选修课程database又选修uml的学生的编号。

select from choices as x,choices as y

where( cid from courses where cname='database')

and cid from courses where cname='uml'))and

实现集合减运算,查询选修课程打database而没有选修umlde学生的编号。

select from choices as x,choices as y

where( cid from courses where cname='database'))

sql实验

sql与pl sql基础操作。实验目的与要求 了解pl sql在oracle中的基本概念 掌握pl sql的各组成部分 pl sql的运用。注意此次实验需提交到实验平台 平台实验项目编号3中 实验内容。必做题 一 sql基础。1 以首字母大写其余字母小写的方式显示所有员工的姓名。提示 需用到subs...

sql实验

建立数据表如下数据库关系模型3张表 学生表 专业表 学院表 学生信息表。专业信息表。学院信息表。sql语言。1 插入一条新记录到学院信息表中 学院号 17 学院名称 机械学院 insert into 学院信息表1 学院号,学院名称 valuse 17 机械学院 2 将学生表中所有女生的专业号修改为 ...

sql实验1sql入门

实验1 sql server 2008入门。一 实验目的。1.了解sql server 2008的安装过程中的关键问题 2.掌握服务管理器的启动和停止方法 3.掌握注册服务器的步骤 二 实验学时。2学时。三 实验要求。1.熟练掌握sql server2008数据库服务器登录方法。2.熟练掌握sql ...