您的位置:首页 > 职场人生

一套面试题及答案

2016-05-25 15:30 519 查看
1.创建表空间aaaspace,数据文件命名为aaadata.dbf,存放在d:\data目录下,文件大小为200MB,设为自动增长,增量5MB,文件最大为500MB。

create tablespace aaaspace datafile 'd:\data\aaadata.dbf' size 200M auto extend on next 5M maxsize 500M;
2.假设表空间aaaspace已用尽500MB空间,现要求增加一个数据文件,存放在e:\appdata目录下,文件名为appaaadata,大小500MB,不自动增长。

alter tablespace aaaspace add datafile 'e:\appdata\appaaadata.dbf' size 500m;


3.以系统管理员身份登录,创建账号tom,设置tom的默认表空间为aaaspace。为tom分配connect和resource系统角色,获取基本的系统权限。然后为tom分配对用scott的表emp的select权限和对salary,mgr属性的update权限。

create user tom identified by password default tablespace aaaspace;
grant connect,resource to tom;
grant select,update(salary,mgr) on scott.emp to tom;


4.按如下要求创建表class,student

属性

类型(长度)
默认值
约束
含义
CLASSNO数值 (2)主键班级编号
CNAME变长字符 (10)非空班级名称
属性
类型(长度)
默认值
约束
含义
STUNO数值 (8)主键学号
SNAME变长字符 (12)非空姓名
SEX字符 (2)性别
BIRTHDAY日期生日
EMAIL变长字符 (20)唯一电子邮件
SCORE数值 (5, 2)检查成绩
CLASSNO数值 (2)外键,关联到表CLASS的CLASSNO主键班级编号
create table class(classno number(2) constraint class_classno_pk primary key,cname varchar2(10) not null);
create table student(stuno number(8) constraint student_stuno_pk primary key,sname varchar2(12) not null,sex char(2) default '男' ,birthday date,email varchar2(20) constraint student_email_uk unique,score number(5,2) constraint student_score_ck check(score>=0 and score <=100),classno number(2) constraint student_classno_fk reference class(classno));


5.在表student的sname属性上创建索引student_sname_ind

create index student_sname_ind on student(sname);
6.创建序列stuseq,要求初值为20050001,增量为1,最大值为20059999

create sequence stuseq increment by 1 start with 20050001 maxvalue 20059999 nocache nocycle;


7.向表student插入如下两行

STUNOSNAMESEXBIRTHDAYEMAILSCORECLASSNO
从stuseq取值tom1979-2-3 14:30:25tom@163.net89.501
从stuseq取值jerry默认值2
insert into student values(stuseq.nextval,'tom','男',to_date('1979-2-3 14:30:25','yyyy-mm-dd hh24:mi:ss'),'tom@163.net',89.50,1);
insert into student(stuno,sname,classno) values(stuseq.nextval,'jerry',2);
8.修改表student的数据,将所有一班的学生成绩加10分。

update student set score=score+10 where classno=1;
9.删除表student的数据,将所有3班出生日期小于1981年5月12日的记录删除。

delete from student where classno=3 and birthday>'12-5月-81';
10.完成以下SQL语句

(1)按班级升序排序,成绩降序排序,查询student表所有记录。

select * from student order by classno,score desc;
(2)查询student表中所有二班的成绩大于85.50分且出生日期大于1982-10-31的男生的记录。

select * from student where classno=2 and score>85.50 and birthday<'31-10月-82' and sex='男';


(3)查询student表中所有三班成绩为空的学生记录。

select * from student where classno=3 and score is null;


(4)表student与class联合查询,要求查询所有学生的学号,姓名,成绩,班级名称。

select s.stuno,s.sname,s.score,c.cname from studetn s,class c where s.classno=c.classno;


(5)按班级编号分组统计每个班的人数,最高分,最低分,平均分,并按平均分降序排序。

select classno,count(9),max(score),min(score),avg(score) from student group by classno order by avg(score) desc;
(6) 查询一班学生记录中所有成绩高于本班学生成绩平均分的记录。

select * from student where classno=1 and score>(select avg(score) from student where classno=1);
(7)统计二班学生中所有成绩大于所有班级平均分的人数。

select count(*) from student where classno=2 and score>all(select avg(score) from student group by classno);


(8)查询平均分最高的班级编号与分数。;

select classno,avg(score) from student group by classno having avg(score)=(select max(avg(score)) from student group by classno);
(9)查询所有学生记录中成绩前10名的学生的学号,姓名,成绩,班级编号

select stuno,sname,score,classno from (select * from student order by score desc) where rownum<=10;


(10)创建视图stuvu,要求视图中包含student表中所有一班学生的stuno,sname,score,classno四个属性,并具有with check option限制。

create view stuvu as select stuno,sname,score,classno from student where classno=1 with check option;


11.truncate和delete的区别

(1)truncate在各种表(无论大表还是小表)都非常快。如果有rollback命令delete会被撤销,而truncate不会被撤销。

(2)truncate是一个DDL语言,而delete是DML语言,向其他所有DDL语言一样,它将被隐式提交,不能对truncate使用rollback命令。

(3)truncate将重新设置高水平线和所有的索引。在对整个表和索引进行完全浏览时,经过truncate操作后的表比delete操作后的表要快很多。

(4)truncate不能触发触发器,delete可以。

(5)不能授予任何人清除他人的表的权限。

(6)当表被清空,表和表索引将被重新设置成初始大小,而delete则不能。

(7)不能清空父表。

12.表空间如何扩展,并用语句写出。

1. alter tablespace  aaaspace add datafile 'd:\aaaspace2.dbf' 200m;


2.alter database datafile 'd:\aaaspace.dbf' resize 500m;
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: