数据库社团
我最初没学过数据库时,我就想用数据库(access),那时,是我在刚学完C语言,写一个学生管理系统的程序(dos窗口那种),当时是用文件,读写文件来实现。后来还没学数据库时,我用数据库代替我原来的文件。也就是我只用数据库来保存数据而已。 ...
2. 在职工-社团数据库有3个基本表:职工(职工号,姓名,年龄,性别);
1,社会团体(编号,名称,负责人,活动地点) society
参加(职工号,编号,参加日期)Join
职工(职工号) Employee
select 职工号
from Employee a
where a.职工号 in(select 职工号 from Join
where 编号 in(select 编号 from Join
where 职工号='1001'));
2,select (select 名称 from society where 编号=Join.编号) 社会团体名称,
sum(职工编号) 参加人数
from Join where 编号 =
(select bb.编号 from (select 编号,count(*) 数量 from Join group by 编号 ) bb
where bb.数量 =( select max(数量) from --得到最大数量
(select 编号,count(*) 数量 from Join
group by 编号 ) aa ) ); --根据最大数量得到团体编号
3,grant select, insert, delete on society to 李平 with grant option;
grant select, insert, delete on Join to 李平 with grant option;
3. 设教工社团数据库有三个基本表:
1. select distinct a.工号, a.姓名 from 职工 a, 社团 b, 参加 c
where a.工号=c.工号
and c.编号=b.编号
and b.名称 in ('体操队','篮球队')
2. select distinct a.工号, a.姓名, a.年龄 from 职工 a
where a.性别='男' and exists
(select 1 from 参加 b where b.工号=a.工号)
3. select a.工号 from 职工 a
where a.工号 in
(select b.工号 from 参加 b group by b.工号 having count(*) > 2)
4. select a.* from 职工 a
where not exists ( select * from 社团 b where not exists
(select * from 参加 c where c.工号=a.工号 and c.编号=b.编号)
)
4. sql数据库的创建表
第一题不知道为什么网络说有不合适内容不给我提交。
二、写出SQL语句:(各10分,共50分)
1.select distinct no,name from table where 2010-year(birth) >=50;
2.select no,name from table where livecity=workingcity;
3.select no,name from table where company!='联华公司';
4.create view emp_female as select e#,ename,c#,cname,salary from emp group by e#;
5.use emp
go
update emp set salary=salary+0.5*salary;
我无语了 做了好几题都说有不适合发表的内容 我都不知道哪些语句是不适合发表的- -明明是数据库语句啊
二、写出SQL语句:
1、建立视图:社团负责人(编号,名称,负责人职工号,负责人姓名,负责人性别);
2、建立视图:参加人情况(职工号,姓名,社团编号,社团名称,参加日期)
3、查找参加唱歌队或篮球队的职工号和姓名。
4、求参加人数最多的社会团体的名称和参加人数。
5、把对社会团体和参加两个表的数据查看、插入和删除数据的权力赋给用户李平,并允许他将此权力授予其他用户
create view 社团负责人(编号 char(7),名称 char(8),负责人职工号 char(8),负责人姓名 char(8),负责人性别 char(2));
create view 参加人情况(职工号,姓名,社团编号,社团名称,参加日期);
select 职工号,姓名 where 社团名称=‘唱歌队’or‘篮球队’;
select count(*) max(名称),max(社团名称) from 参加人情况 ;
grant select,insert,delete on 社会团体and参加人数 to 李平 with admin option;
5. 给数据库社团起个好听的名字,谁来帮我想想!!
DB COVER 就是Discovers (DATABASE)new continent
6. 求数据库,关于学生社团管理系统,JAVA web前段加MySQL数据库,事后定当答谢
可以帮你做一个
7. SQL数据库 职工(职工号,姓名,年龄,性别) 社会团体(编号,名字,负责人,活动地点,会费)
--1
update[社会团体]
set[会费]=[会费*1.1]
--2
createviewUVW_testas
select[名字],[总人数]from[社会团体]Arightjoin(select[编号],count(*)[总人数]from[参加]groupby[编号])B
onA.[编号]=B.[编号]
--3
select[编号],[名称],[负责人]from[社会团体]
where[编号]notin(select[编号]from[参加])
8. 设职工社团数据库有三个基本表: 职工(职工号,姓名,年龄,性别); 社会团体(社团号,名称,负责人
--设职工社团数据库有三个基本表:
-- 职工(职工号,姓名,年龄,性别);
-- 社会团体(社团号,名称,负责人,活动地点)
--参加(职工号,社团号,参加日期)
---其中: (1)职工表的主码为职工号。
--(2)社会团体表的主码为社团号;外码为负责人,被参照表为职工表,对应属性为职工号。
--(3)参加表的职工号和社团号为外码;职工号为外码,其被参照表为职工表,对应属性为职工号;
--社团号为外码,其被参照表为社会团体表,对应属性为社团号。
--试用SQL语句表达下列操作:
---1.定义职工表、社会团体表和参加表,并说明其主码和参照关系。
create table em
(
emid varchar(5) primary key,
emname nvarchar(5) not null,
age int,
sex nchar(1))
create table team
(
tid char(3) primary key,
tname nvarchar(10) not null,
leader varchar(5) foreign key references em(emid),
workstation nvarchar(20)
)
create table takepartin
(emid varchar(5) foreign key references em(emid),
tid char(3) foreign key references team(tid),
takedate smalldatetime,
primary key(emid,tid))
--- 2.建立下列两个视图: 社团负责人(社团号,名称,负责人职工号,负责人姓名,负责人性别);
create view leaders
as
select tid,tname,em.emid,emname,sex from team join emp on team.emid=team.leader;
----参加人情况(职工号,姓名,社团号,社团名称,参加日期)。
create view takes
as
select A.emid,emname,c.tid,tname,takedate from emp A join takepartin B on a.emid=B.emid
join team C on B.tid=C.tid
--3.查找参加的职工号和姓名。
select emid,emname from takes where tname='唱歌队' or tname='篮球队'
---4.查找没有参加任何社会团体的职工情况。
select * from emp where emid not in(select emid from takepartin)
--5.查找参加了全部社会团体的职工情况。