---
title: "SQL面试"
author: "eminem"
date: "2008-02-25T16:35:54Z"
tags: []
slug: "sql"
draft: false
lastmod: "2008-02-25T16:35:54Z"
id: 164776
url: "https://eminem.iteye.com/blog/164776"
---

1 	SQL面试题
	
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. select lower(trim(‘H’from‘Hello World’))from dual;

9)which are DML statements(choose all that apply)______.
A.commit  B.merge   C.update  D.delete E.creat  F.drop

10)Select 语句中用来连接字符串的符号是______.
A. “+”   B. “&” C.“||” D.“|”

问答题： 什么是聚集索引，什么是非聚集索引，什么又是主键？
	
	作者： fffly   2006-10-4 10:52 　 回复此发言  
	
2 	回复：SQL面试题
	
1
B. select dept_id, job_cat,max(salary) from employees group by dept_id,job_cat;

2
C.count(start_date)
E.min(start_date)

3
B. primary
E. unique

4
E. after the where clause

5
C.after all clause

6
A.the same result 

7
D. select to_char(sydate,’yyyymmdd hh24:mi:ss’)from dual;

8
D. select lower(trim(‘H’from‘Hello World’))from dual;

9
不详,猜测B,( E.creat F.drop 都是DDL)

10
C.“||”

问答题： 什么是聚集索引，什么是非聚集索引，什么又是主键？

 表中经常有一个列或列的组合，其值能唯一地标识表中的每一行。这样的一列或多列称为表的主键.
 聚集索引确定表中数据的物理顺序。聚集索引类似于电话簿，后者按姓氏排列数据。由于聚集索引规定数据在表中的物理存储顺序，
 因此一个表只能包含一个聚集索引。但该索引可以包含多个列（组合索引），就像电话簿按姓氏和名字进行组织一样。
 非聚集索引与课本中的索引类似。数据存储在一个地方，索引存储在另一个地方，索引带有指针指向数据的存储位置。
 索引中的项目按索引键值的顺序存储，而表中的信息按另一种顺序存储（这可以由聚集索引规定）。
 如果在表中未创建聚集索引，则无法保证这些行具有任何特定的顺序。
	
	作者： fffly   2006-10-4 10:53 　 回复此发言  
	
3 	回复：SQL面试题
	
1.磁盘柜上有14块73G的磁盘， 数据库为200G 大小包括日志文件，如何设置磁盘？
2.有两服务器群集，分别为node1和node2 现在要打win200系统补丁，打完后，要重新启动，如何打补丁，不能影响用户使用。
3.有一个A 数据库，分别复制到B和C B 要求 每次数据更新 也同时更新，C 每天更新一次就行，如何制定复制策略!
4.有一个order 表，有90个字段，20个索引，15个复合索引，其中有3个索引字段超过10个，如何进行优化
5.有一个数据库200G大小，每天增加50M 允许用户随时访问，制定备份策略。
6.管理50台数据库，日常工作是检查数据库作业是否完成，你该如何完成这项检查工作？
7.自定义函数和存储过程的区别是什么，什么情况下只能用自定义函数，什么情况下只能用存储过程
8.SQL 2005 的新特性是什么 ？ 与oracle 有什么区别？
9.DBA 的品质应该有哪些，你有哪些， 有什么欠缺的？
	
	作者： fffly   2006-10-4 10:54 　 回复此发言  
	
4 	回复：SQL面试题
	
1)采用RAID 5方式.数据文件和日志文件分别放在不同的磁盘上.
2)先打node2,完成后切换到node2然后再打node1.
3)A->B采用事务复制,A->C采用快照复制并指定日期过滤条件
4)采用差异日志备份.
5)写一个自动管理程序,遍历50太机器上的所有job执行状态然后给出状态报表
6)函数都有返回值,存储过程不一定有,函数都必须被其他程序调用,存储过程不是,函数结果可以作为查询结果集的一个字段,存储过程不能.当要直接获得结果集时,只能使用存储过程
7)SQL server 2005增加了CRL和Try...catch异常检查语法增加了rownumber,rank, dense_rank以及pivot和unpivot等等新的语法.把先前的开发和管理以及监控等工具集成到了一个叫management studio 的工具.
8)DBA应有敏锐的观察力和判断能力,要细心和有耐心.

1.磁盘柜上有14块73G的磁盘， 数据库为200G 大小包括日志文件，如何设置磁盘？
 Raid0+1
2.有两服务器群集，分别为node1和node2 现在要打win200系统补丁，打完后，要重新启动，如何打补丁，不能影响用户使用。
 先启动一台再启动另一台
3.有一个A 数据库，分别复制到B和C B 要求 每次数据更新 也同时更新，C 每天更新一次就行，如何制定复制策略!
 事务复制和快照复制
4.有一个order 表，有90个字段，20个索引，15个复合索引，其中有3个索引字段超过10个，如何进行优化
 索引过多，要整合，90个字段，尽量范式
5.有一个数据库200G大小，每天增加50M 允许用户随时访问，制定备份策略。
 先做一次完整备份，然后日志备份
6.管理50台数据库，日常工作是检查数据库作业是否完成，你该如何完成这项检查工作？
 a、作业运行完发mail
 b、写程序访问msdb中的相关表
7.自定义函数和存储过程的区别是什么，什么情况下只能用自定义函数，什么情况下只能用存储过程
 区别：我想存储过程被调用后会常驻内存，下次调用会更快；函数必须有返回值而存储过程可以没有。
8.SQL 2005 的新特性是什么 ？ 与oracle 有什么区别？
 增加了新的数据类型varchar(MAX)、XML；增强了排序功能(Row_Number、Rank、NTile等)；新增CET功能，表分区，在线索引，DDL触发器，安全方面的加强等等。
 当然与oracle有区别，很多方面都不同，具体问题才好具体回答。
9.DBA 的品质应该有哪些，你有哪些， 有什么欠缺的？
 至少有良好的心理素质，抗压能力强！强的责任心，细心，太多了...