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

数据库面试题

2006-08-27 14:09 351 查看
数据库面试常用测试题(SQL Server)

题目1

  问题描述:

  为管理岗位业务培训信息,建立3个表:

  S (S#,SN,SD,SA) S#,SN,SD,SA 分别代表学号、学员姓名、所属单位、学员年龄

  C (C#,CN ) C#,CN 分别代表课程编号、课程名称

  SC ( S#,C#,G ) S#,C#,G 分别代表学号、所选修的课程编号、学习成绩

  1. 使用标准SQL嵌套语句查询选修课程名称为’税收基础’的学员学号和姓名

  --实现代码:

  Select SN,SD FROM S

  Where [S#] IN(

  Select [S#] FROM C,SC

  Where C.[C#]=SC.[C#]

  AND CN=N'税收基础')

  2. 使用标准SQL嵌套语句查询选修课程编号为’C2’的学员姓名和所属单位

  --实现代码:

  Select S.SN,S.SD FROM S,SC

  Where S.[S#]=SC.[S#]

  AND SC.[C#]='C2'

  3. 使用标准SQL嵌套语句查询不选修课程编号为’C5’的学员姓名和所属单位

  --实现代码:

  Select SN,SD FROM S

  Where [S#] NOT IN(

  Select [S#] FROM SC

  Where [C#]='C5')

  4. 使用标准SQL嵌套语句查询选修全部课程的学员姓名和所属单位

  --实现代码:

  Select SN,SD FROM S

  Where [S#] IN(

  Select [S#] FROM SC

  RIGHT JOIN

  C ON SC.[C#]=C.[C#] GROUP BY [S#]

  HAVING COUNT(*)=COUNT([S#]))

  5. 查询选修了课程的学员人数

  --实现代码:

  Select 学员人数=COUNT(DISTINCT [S#]) FROM SC

  6. 查询选修课程超过5门的学员学号和所属单位

  --实现代码:

  Select SN,SD FROM S

  Where [S#] IN(

  Select [S#] FROM SC

  GROUP BY [S#]

  HAVING COUNT(DISTINCT [C#])>5)

题目2

  问题描述:

  已知关系模式:

  S (SNO,SNAME) 学生关系。SNO 为学号,SNAME 为姓名

  C (CNO,CNAME,CTEACHER) 课程关系。CNO 为课程号,CNAME 为课程名,CTEACHER 为任课教师

  SC(SNO,CNO,SCGRADE) 选课关系。SCGRADE 为成绩

  1. 找出没有选修过“李明”老师讲授课程的所有学生姓名

  --实现代码:

  Select SNAME FROM S

  Where NOT EXISTS(

  Select * FROM SC,C

  Where SC.CNO=C.CNO

  AND CNAME='李明'

  AND SC.SNO=S.SNO)

  2. 列出有二门以上(含两门)不及格课程的学生姓名及其平均成绩

  --实现代码:

  Select S.SNO,S.SNAME,AVG_SCGRADE=AVG(SC.SCGRADE)

  FROM S,SC,(

  Select SNO

  FROM SC

  Where SCGRADE<60

  GROUP BY SNO

  HAVING COUNT(DISTINCT CNO)>=2

  )A Where S.SNO=A.SNO AND SC.SNO=A.SNO

  GROUP BY S.SNO,S.SNAME

  3. 列出既学过“1”号课程,又学过“2”号课程的所有学生姓名

  --实现代码:

  Select S.SNO,S.SNAME

  FROM S,(

  Select SC.SNO

  FROM SC,C

  Where SC.CNO=C.CNO

  AND C.CNAME IN('1','2')

  GROUP BY SNO

  HAVING COUNT(DISTINCT CNO)=2

  )SC Where S.SNO=SC.SNO

  4. 列出“1”号课成绩比“2”号同学该门课成绩高的所有学生的学号

  --实现代码:

  Select S.SNO,S.SNAME

  FROM S,(

  Select SC1.SNO

  FROM SC SC1,C C1,SC SC2,C C2

  Where SC1.CNO=C1.CNO AND C1.NAME='1'

  AND SC2.CNO=C2.CNO AND C2.NAME='2'

  AND SC1.SCGRADE>SC2.SCGRADE

  )SC Where S.SNO=SC.SNO

  5. 列出“1”号课成绩比“2”号课成绩高的所有学生的学号及其“1”号课和“2”号课的成绩

  --实现代码:

  Select S.SNO,S.SNAME,SC.[1号课成绩],SC.[2号课成绩]

  FROM S,(

  Select SC1.SNO,[1号课成绩]=SC1.SCGRADE,[2号课成绩]=SC2.SCGRADE

  FROM SC SC1,C C1,SC SC2,C C2

  Where SC1.CNO=C1.CNO AND C1.NAME='1'

  AND SC2.CNO=C2.CNO AND C2.NAME='2'

  AND SC1.SCGRADE>SC2.SCGRADE

  )SC Where S.SNO=SC.SNO

 某数据集团数据库初试笔试题(数据库面试 笔试题)
1)Which statement shows the maximum salary paid in each job category of each department?_______
A. select dept_id, job_cat,max(salary) from employees where salary > max(salary);
B. select dept_id, job_cat,max(salary) from employees group by dept_id,job_cat;
C. select dept_id, job_cat,max(salary) from employees;
D. select dept_id, job_cat,max(salary) from employees group by dept_id;
E. select dept_id, job_cat,max(salary) from employees group by dept_id,job_cat,salary;

2)description of the students table:
sid_id number
start_date date
end_date date
which two function are valid on the start_date column?_________。
A. sum(start_date)
B. avg(start_date)
C. count(start_date)
D. avg(start_date,end_date)
E. min(start_date)
F. maximum(start_date)

3)for which two constraints does the oracle server implicitly create a unique index?______。
A. not null
B. primary
C. foreign key
D. check
E. unique

4)in a select statement that includes a where clause,where is the group by clause placed in the select statement?______。
A. immediately after the select clause
B. before the where clause
C. before the from clause
D. after the order by clause
E. after the where clause

5)in a select statement that includes a where clause,where is the order by clause placed in the select statement?______.
A.immediately after the select clause
B.before the where clause
C.after all clause
D.after the where clause
E.before the from clause

6)evaluate there two sql statements______.
Select last_name,salary from employees order by salary;
Select last_name,salary from employees order by 2 asc;
A.the same result B.different result C.the second statement returns a syntax error

7) you would like to display the system date in the format“20051110 14:44:17”。Which select statement should you use?______。
A. select to_date(sydate,’yearmmdd hh:mm:ss’)from dual;
B. select to_char(sydate,’yearmonthday hh:mi:ss’)from dual;
C. select to_date(sydate,’yyyymmdd hh24:mi:ss’)from dual;
D. select to_char(sydate,’yyyymmdd hh24:mi:ss’)from dual;
E. select to_char(sydate,’yy-mm-dd hh24:mi:ss’)from dual;

8)which select statement will the result ‘ello world’from the string‘Hello world’?______.
A. select substr(‘Hello World’,1)from dual;
B. select substr(trim(‘Hello World’,1,1))from dual;
C. select lower(substr(‘Hello World’,1))from dual;
D
4000
. select lower(trim(‘H’from‘Hello World’))from dual;

9)which are DML statements(choose all that apply)______.
A.commit B.merge
<script type="text/javascript">google_ad_client = "pub-4475724770859924";google_alternate_color = "FFBBE8";google_ad_width = 468;google_ad_height = 60;google_ad_format = "468x60_as";google_ad_type = "text_image";google_ad_channel ="9379930647";google_color_border = "F8F8F8";google_color_bg = "FFFFFF";google_color_link = "FF6FCF";google_color_url = "38B63C";google_color_text = "B3B3B3";</script>
<script src="http://pagead2.googlesyndication.com/pagead/show_ads.js" type="text/javascript"></script>
C.update D.delete E.creat F.drop

10)Select 语句中用来连接字符串的符号是______.
A. “+” B. “&” C.“||” D.“|”

问答题: 什么是聚集索引,什么是非聚集索引,什么又是主键?

数据库面试(Oracle与Sql专题)

oracle Certification Program (OCP认证)的题目

  (1) A 表中有100条记录.

  Select * FROM A Where A.COLUMN1 = A.COLUMN1

  这个语句返回几条记录? (简单吧,似乎1秒钟就有答案了:)

  (2) Create SEQUENCE PEAK_NO

  Select PEAK_NO.NEXTVAL FROM DUAL --> 假设返回1

  10秒中后,再次做
<script type="text/javascript">google_ad_client = "pub-4475724770859924";google_alternate_color = "FFBBE8";google_ad_width = 468;google_ad_height = 60;google_ad_format = "468x60_as";google_ad_type = "text_image";google_ad_channel ="9379930647";google_color_border = "F8F8F8";google_color_bg = "FFFFFF";google_color_link = "FF6FCF";google_color_url = "38B63C";google_color_text = "B3B3B3";</script>
<script src="http://pagead2.googlesyndication.com/pagead/show_ads.js" type="text/javascript"></script>

  Select PEAK_NO.NEXTVAL FROM DUAL --> 返回多少?

  (3) SQL> connect sys as sysdba

  Connected.

  SQL> insert into dual values ( 'Y');

     1 row created.

  SQL> commit;

     Commit complete.

  SQL> select count(*) from dual;

     COUNT(*)

     ----------

     2

  SQL> delete from dual;

     commit;

     -->DUAL里还剩几条记录?

  JUST TRY IT
一些高难度的SQL面试题

以下的null代表真的null,写在这里只是为了让大家看清楚

根据如下表的查询结果,那么以下语句的结果是(知识点:not in/not exists+null)
SQL> select * from usertable;
USERID USERNAME
----------- ----------------
1 user1
2 null
3 user3
4 null
5 user5
6 user6

SQL> select * from usergrade;
USERID USERNAME GRADE
---------- ---------------- ----------
1 user1 90
2 null 80
7 user7 80
8 user8 90
执行语句:

select count(*) from usergrade where username not in (select username from usertable);

select count(*) from usergrade g where not exists
(select null from usertable t where t.userid=g.userid and t.username=g.username);

结果为:语句1( 0 ) 语句2 ( 3 )

A: 0 B:1 C:2 D:3 E:NULL

2

在以下的表的显示结果中,以下语句的执行结果是(知识点:in/exists+rownum)
SQL> select * from usertable;
USERID USERNAME
----------- ----------------
1 user1
2 user2
3 user3
4 user4
5 user5

SQL> select * from usergrade;
USERNAME GRADE
---------------- ----------
user9 90
user8 80
user7 80
user2 90
user1 100
user1 80

执行语句
Select count(*) from usertable t1 where username in
(select username from usergrade t2 where rownum <=1);

Select count(*) from usertable t1 where exists
(select 'x' from usergrade t2 where t1.username=t2.username and rownum <=1);

以上语句的执行结果是:( ) ( )
A: 0 B: 1 C: 2 D: 3

根据以下的在不同会话与时间点的操作,判断结果是多少,其中时间T1<T2<……<Tn。(知识点:封锁与并发)
原始表记录为;
select * from emp;
EMPNO DEPTNO SALARY
----- ------ ------
100 1 55
101 1 50

select * from dept;
DEPTNO SUM_OF_SALARY
------ -------------
1 105
2

可以看到,现在因为还没有部门2的员工,所以总薪水为null,现在,
有两个不同的用户(会话)在不同的时间点(按照特定的时间顺序)执行了一系列的操作,那么在其中或最后的结果为:

time session 1 session2
----------- ------------------------------- -----------------------------------
T1 insert into emp
values(102,2,60)

T2 update emp set deptno =2
where empno=100

T3 update dept set sum_of_salary =
(select sum(salary) from emp
where emp.deptno=dept.deptno)
where dept.deptno in(1,2);

T4 update dept set sum_of_salary =
(select sum(salary) from emp
where emp.deptno=dept.deptno)
where dept.deptno in(1,2);

T5 commit;

T6 select sum(salary) from emp group by deptno;
问题一:这里会话2的查询结果为:
T7 commit;
=======到这里为此,所有事务都已完成,所以以下查询与会话已没有关系========

T8 select sum(salary) from emp group by deptno;
问题二:这里查询结果为

T9 select * from dept;
问题三:这里查询的结果为

问题一的结果( ) 问题二的结果是( ) 问题三的结果是( )

A: B:
---------------- ----------------
1 50 1 50
2 60 2 55

C: D:
---------------- ----------------
1 50 1 115
2 115 2 50

E: F:
---------------- ----------------
1 105 1 110
2 60 2 55

有表一的查询结果如下,该表为学生成绩表(知识点:关联更新)
select id,grade from student_grade
ID GRADE
<script type="text/javascript">google_ad_client = "pub-4475724770859924";google_alternate_color = "FFBBE8";google_ad_width = 468;google_ad_height = 60;google_ad_format = "468x60_as";google_ad_type = "text_image";google_ad_channel ="9379930647";google_color_border = "F8F8F8";google_color_bg = "FFFFFF";google_color_link = "FF6FCF";google_color_url = "38B63C";google_color_text = "B3B3B3";</script>
<script src="http://pagead2.googlesyndication.com/pagead/show_ads.js" type="text/javascript"></script>

-------- -----------
1 50
2 40
3 70
4 80
5 30
6 90

表二为补考成绩表
select id,grade from student_makeup
ID GRADE
-------- -----------
1 60
2 80
5 60

现在有一个dba通过如下语句把补考成绩更新到成绩表中,并提交:
update student_grade s set s.grade =
(select t.grade from student_makeup t
where s.id=t.id);
commit;
请问之后查询:
select GRADE from student_grade where id = 3;结果为:

A: 0 B: 70 C: null D: 以上都不对

根据以下的在不同会话与时间点的操作,判断结果是多少,
其中时间T1<T2<……<Tn。(知识点:DDL与封锁)

session1 session2
-------------------------------------- ----------------------------------------
T1 select count(*) from t;
--显示结果(1000)条

T2 delete from t where rownum <=100;

T3 begin
delete from t where rownum <=100;
commit;
end;
/

T4 truncate table t;

T5 select count(*) from t;
--这里显示的结果是多少

A: 1000 B: 900 C: 800 D: 0
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  数据库 google date user sql c#