数据库管理人员的面试题
一、Transact-SQL问题:
1 有订单表SO_Table,单号字段RefNo VARCHAR(10),需要实现自动编号,格式为YYYYMMXXXX,其中XXXX为序号,如:2004050001,2004050002 (2004059999)
等,采用Transact-SQL实现新订单编号的思路。
2 有表T1,T2,现有一事务,在向表T1添加数据时,同时也必须向T2也添加数据,如何确何数据的完整性。
3 如何求表中相邻(按聚集索引相邻)的两条记录的某字段的值之差,用Transact-SQL语句或存储过程。
4 如何删除表中的重复数据,用Transact-SQL写出代码。
5 基于MS-SQLSERVER 2000,如何统计数据库中所有用户表的数据,显示格式如下:
表名记录数
sales        23
6 人员情况表(employee)中字段包括,员工号(ID),姓名(name),年龄(age),文化程度(wh):包括四种情况(本科以上,大专,高中,初中以下),现在我要根据年龄字段查询统计出:表中文化程度为本科以上,大专,高中,初中以下,各有多少人,占总人数多少。结果如下:
学历年龄人数百分比
本科以上  20        34          14
大专      20        33          13
高中      20        33          13
初中以下  20        100          40
本科以上  21        50          20
。。。。。。
Transact-SQL查询语句如何写?
7表一(AAA)
商品名称mc  商品总量sl
A          100
B          120
表二(BBB)
商品名称mc  出库数量sl
A          10
A          20
B          10
B          20
B          30
用一条Transact-SQL语句算出商品A,B目前还剩多少?
二、数据库管理问题(DBMS为:MS-SQL Server 2000)(选作一道题)
1使用文件与文件组恢复的方式恢复数据库
2 设计作业进行周期性的备份数据库
3 一个B/S结构ERP系统,出入库单据超过100万条,系统在单据调出、保存过程中速度比较慢,原因可能有哪些?有哪些办法可以提高速度?
三、数据库设计
有一个钢铁产品检验数据库,包括产品的化学实验结果和物理试验结果,质检部门会根据高炉号来对这批产品进行综合判定,最后根据一个关键字段(比如说叫高炉号)将两个表中的内容取出来放到质量证明书中。钢铁产品有多种不同的规格,针对同一个规格的钢材需要的物理性能检验包括力学性能、高倍指标、低倍指标、气体含量四个大项,每个大项里边包含的内容也不一样,力学性能大约有20个小项,高倍有60个小项,低倍有20个小项、气体有8个小项,并且如果某一个大项中有不合格的,必须取双倍的试样重新进行检验,而另外的大项不重做复验。
请给出物理试验结果表的设计思路。
四、项目管理问题
请叙述你经历的你认为是最为成功的或典型的项目的项目运作(管理)体系、业务流程体系和软件技术体系统。
五、请叙述你的职业理想。
内容正文:
Question 1:Can you use a batch SQL or store procedure to calculating the Number of Days in a Month
Answer 1:出当月的天数
程序代码
select
datepart(dd,dateadd(dd,-1,dateadd(mm,1,cast(cast(year(getdate()) as varchar)+'-'+cast(month(getdate()) as varchar)+'-01' as datetime))))
Question2:Can you use a SQL statement to calculating it!
How can I print "10 to 20" for books that sell for between $10 and $20,"unknown" for books whose price is null, and "other" for all other prices? Answer 2:
select bookid,bookname,price=case when price is null then 'unknown'        when  price between 10 and 20 then '10 to 20' else price end from books
Question3:Can you use a SQL statement to finding duplicate values! How can I find authors with the same last name?
You can use the table authors in datatabase pubs. I want to get the result as below:
Output:
程序代码
au_lname                                number_dups
---------------------------------------- -----------
Ringer                                  2
(1 row(s) affected)
Answer 3
select au_lname,number_dups=count(1) from authors group by au_lname
Question4:Can you create a cross-tab report in my SQL Server!
How can I get the report about sale quality for each store and each quarter and the total sale quality for each quarter at year 1993?
You can use the table sales and stores in datatabase pubs.
Table Sales record all sale detail item for each store. Column store_id is the id of each store, ord_date is the order date of each sale item, and column qty is the sale qulity. Table stores record all store information.
I want to get the result look like as below:
Output:
程序代码
stor_name                                Total      Qtr1        Qtr2        Qtr3        Qtr4
---------------------------------------- ----------- -----------
----------- ----------- -----------
Barnum's                                50          0          50          0          0
Bookbeat                                55          25          30          0          0
Doc-U-Mat: Quality Laundry and
Books    85          0          85          0          0
Fricative
Bookshop                      60          35          0          0          25
Total                                    250        60          165        0          25
Answer 4:用动态SQL实现
Question5: The Fastest Way to Recompile All Stored Procedures
I have a problem with a database running in SQL Server 6.5 (Service Pack
4). We moved the database (object transfer) from one machine to another last night, and an error (specific to a stored procedure) is cropping up. However, I can't tell which procedure is causing it. Permissions are granted in all of our stored procedures; is there a way from the isql utility to force all stored procedures to recompile?
Tips: sp_recompile can recomplie a store procedure each time
Answer 5:在执行存储过程时,使用 with recompile 选项强制编译新的计划;使用sp_recompile系统存储过程强制在下次运行时进行重新编译
Question6: How can I add row numbers to my result set?
In database pubs, have a table titles , now I want the result shown as below,each row have a row number, how can you do that?
Result:
程序代码
line-no    title_id
----------- --------
1          BU1032
2          BU1111
3          BU2075
4          BU7832
5          MC2222
6          MC3021
7          MC3026
8          PC1035
9          PC8888
10          PC9999
11          PS1372
12          PS2091
13          PS2106
14          PS3333
15          PS7777
16          TC3218
17          TC4203
18          TC7777
Answer 6:
--SQL 2005的写法
select row_number() as line_no ,title_id from titles
--SQL 2000的写法
select line_no identity(int,1,1),title_id into #t from titles
select * from #t
drop table #t
===--
Question: How can I list non-contignous data?
In database pubs, I create a table test using statement as below, and I insert several row as below
多表查询sql语句面试题
程序代码
create table test
( id int primary key )
go
insert into test values (1 )
insert into test values (2 )
insert into test values (3 )
insert into test values (4 )
insert into test values (5 )
insert into test values (6 )
insert into test values (8 )
insert into test values (9 )
insert into test values (11)
insert into test values (12)
insert into test values (13)
insert into test values (14)
insert into test values (18)
insert into test values (19)
go
Now I want to list the result of the non-contignous row as below,how can I do it?
程序代码
Missing after Missing before
------------- --------------
6            8
9            11
Answer :
select id from test t where not exists(select 1 from test where id=t.id+1)  or not exists(select 1 from test where id=t.id-1)
Question: How can I list all book with prices greather than the average price of books of the same type?
In database pubs, have a table named titles , its column named price mean the price of the book, and another named type mean the type of books. Now I want to get the result as below:

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。