数据库应用题(在线等)

数据库应用题(在线等),第1张

一、select salary from emp where ename = 'AAA';

二、select dname from dept where dno = (select dno from emp where eno = C1);

简单的题要自己做,并多练习,才能学的到技术

(1)

create table pet

(

  name varchar(20) not null,

  owner varchar(20) null,

  species varchar(20) not null,

  sex char(1) not null,

  birth date not null,

  death date null

)

插入方法1

insert into pet values('Fluffy','Harold','cat','f','2003','2010')

insert into pet values('Claws','Gwen','cat','m','2004',null)

insert into pet values('Buffy',null,'dog','f','2009',null)

insert into pet values('Fang','Benny','dog','m','2000',null)

insert into pet values('Bowser','Diane','dog','m','2003','2009')

insert into pet values('Chirpy',null,'bird','f','2008',null)

插入方法2

insert into pet 

select 'Fluffy','Harold','cat','f','2003','2010' union all

select 'Claws','Gwen','cat','m','2004',null union all

select 'Buffy',null,'dog','f','2009',null union all

select 'Fang','Benny','dog','m','2000',null union all

select 'Bowser','Diane','dog','m','2003','2009' union all

select 'Chirpy',null,'bird','f','2008',null

(2)

update pet set owner='Kevin' where name='Fang'

(3)

update pet set owner='Duck' where owner is null

(4)

delete from pet where death is not null

(5)

delete from pet

习题5第5题p148

create database 职工_社团

use 职工_社团

create table 职工(

职工号 char(10) primary key,

姓名 char(8),

年龄 smallint default 20,

性别 char(20),

constraint C1 check (性别 in ('男','女')));

create table 社会团体(

编号 char(10) primary key,

名称 char(8),

负责人 char(10),

活动地点 char(20),

constraint C2 foreign key (负责人) references 职工 (职工号));

create table 参加(

职工号 char(10),

编号 char(10),

参加日期 smalldatetime,

constraint C3 primary key (职工号,编号),

constraint C4 foreign key (职工号) references 职工 (职工号),

constraint C5 foreign key (编号) references 社会团体 (编号));

(2)

create view 社团负责人(编号,名称,负责人职工号,负责人姓名,负责人性别)

as select 社会团体编号,社会团体名称,社会团体负责人, 职工职工号,职工性别

from 职工,社会团体,参加

where 社会团体编号=参加编号 and 职工职工号=参加职工号

create view 参加人情况(职工号,姓名,社团编号,社团名称,参加日期)

as select 参加职工号,姓名,社会团体编号,名称,参加日期

from 职工,社会团体,参加

where 职工职工号=参加职工号 and 参加编号=社会团体编号

(3)

select distinct 职工职工号,姓名

from 职工,社会团体,参加

where 职工职工号=参加职工号 and 参加编号=社会团体编号

and 社会团体名称 in('歌唱队','篮球队');

(4)

select

from 职工

where not exists (select

from 参加

where 参加职工号=职工职工号);

(5)

select from 职工

where not exists

(select

from 社会团体

where not exists

(select

from 参加

where 参加职工号=职工职工号 and 参加编号=社会团体编号));

(6)

select 职工号

from 职工

where not exists (select

from 参加 参加1

where 参加1职工号='001'and not exists

(select

from 参加 参加2

where 参加2编号=参加1编号 and 参加2职工号=职工职工号))

(7)

select 编号,count(职工号) as 参加人数

from 参加

group by 编号;

(8)

select TOP 1 名称,count() 参加人数

from 参加,社会团体

where 参加编号=社会团体编号

group by 名称

order by 参加人数 desc

(9)

select distinct 社会团体名称,职工姓名 as 负责人

from 职工,社会团体,参加

where 社会团体编号=参加编号

and 社会团体负责人=职工职工号

and 参加编号 in(select 参加编号

from 参加

group by 参加编号 having count(参加编号)>100)

(10)

grant select,insert,delete on 社会团体 to 李平

with grant option;

grant select,insert,delete on 参加 to 李平

with grant option;

习题6第9题p212

create database 学生选课

use 学生选课

create table 学生(

学号 char(10) primary key,

姓名 char(10),

性别 char(10),

constraint C1 check (性别 in ('男','女')),

年龄 smallint default 20,

所在系 char(20));

create table 课程(

课程号 char(10) primary key,

课程名 char(20),

先行课 char(20));

create table 选课(

学号 char(10),

课程号 char(10),

成绩 smallint,

constraint D1 primary key (学号,课程号),

constraint D2 foreign key (学号) references 学生(学号),

constraint D3 foreign key (课程号) references 课程(课程号))

create index student_ind on 学生(学号)

create index class_ind on 课程(课程号)

create index select_ind on 选课(学号,课程号)

create rule value_rule as @value in ('男','女')

go

exec sp_bindrule 'value_rule','学生性别'

go

create default 性别缺省 as '男'

go

exec sp_bindefault '性别缺省','学生性别'

go

create trigger 选课插入更新 on 选课

for insert,update

as if (select count()

from 学生,inserted,课程

where 学生学号=inserted学号 and 课程课程号=inserted课程号)=0

rollback transaction

go

create trigger delete_all on 学生

for delete

as delete 选课

from 选课,deleted

where 选课学号=deleted学号

go

select 所在系,count(学号)as 学生人数

from 学生

group by 所在系

order by 所在系

compute count(所在系),sum(count(学号))

select

from 学生 inner join 选课 on 学生学号=选课学号

go

select

from 学生 left outer join 选课 on 学生学号=选课学号

go

select

from 学生 right outer join 选课 on 学生学号=选课学号

go

select 选课学号,学生姓名,

学习情况=case

when avg(成绩)>=85 then '好'

when avg(成绩)>=75 and avg(成绩)<85 then '较好'

when avg(成绩)>=60 and avg(成绩)<75 then '一般'

when avg(成绩)<60 then '较差'

end

from 学生,选课

where 学生学号=选课学号

group by 选课学号,姓名

go

以上就是关于数据库应用题(在线等)全部的内容,包括:数据库应用题(在线等)、哪位亲会做SQL数据库管理与应用的课后题可加分…、求数据库系统原理及应用教程第三版课后习题答案,机械工业出版社。苗雪兰等主编 急急急~~!!等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/sjk/10149602.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2023-05-05
下一篇2023-05-05

发表评论

登录后才能评论

评论列表(0条)

    保存