`
coconut_zhang
  • 浏览: 541796 次
  • 性别: Icon_minigender_1
  • 来自: 天津
社区版块
存档分类
最新评论

DBA的SQL Server面试题(数据库面试题)

阅读更多
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 7: Can you tell me what the difference of two SQL statements at performance of execution?
Statement 1:

if NOT EXISTS ( select * from publishers where state = 'NY')
begin
Select 'Sales force needs to penetrate New York market'
end
else
begin
Select 'We have publishers in New York'
end
Statement 2:
if EXISTS ( select * from publishers where state = 'NY')
begin
Select 'We have publishers in New York'
end
else
begin
Select 'Sales force needs to penetrate New York market'
end

Answer 7:不同点:执行时的事务数,处理时间,从客户端到服务器端传送的数据量大小

Question8: How can I list all California authors regardless of whether they have written a book?
In database pubs, have a table authors and titleauthor , table authors has a column state, and titleauhtor have books each author written.
CA behalf of california in table authors.
Answer 8:
select * from  authors where state='CA'

Question9: How can I get a list of the stores that have bought both 'bussiness' and 'mod_cook' type books?
In database pubs, use three table stores,sales and titles to implement this requestment.
Now I want to get the result as below:
stor_id stor_name                               
------- ----------------------------------------

7896    Fricative Bookshop



Answer 9:

select distinct a.stor_id, a.stor_name from stores a,sales b,titles c
where a.stor_id=b.stor_id and b.title_id=c.title_id and c.type='business' and
exists(select 1 from sales k,titles g where stor_id=b.stor_id
and k.title_id=g.title_id and g.type='mod_cook')
  



Question10: 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

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 10:
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)

Question11: 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:

type         title                                                                            price                
------------ -------------------------------------------------------------------------------- ---------------------
business     The Busy Executive's Database Guide                                              19.9900






Answer 11:

select a.type,a.title,a.price from titles a,
(select type,price=avg(price) from titles group by type)b
where a.type=b.type and a.price>b.price


      试题点评:通览整个试题,我们不难发现,这份试题是针对SQL Server数据库人员的。而从难度分析上来看,这份试题也属于同类试题中比较难的了。之所以说它难,首先是限定时间的全英文试题;其次,尽管这份试题主要是考核开发能力,但却涉及到了算法的选择和性能的调优;最后,这份试题还夹进了SQL Server数据库的升级问题。因此,综上所述,我们估计这是一家从事程序外包工作的外企招聘后台开发或与后台开发相关的SQL Server高级程序员的试题。
分享到:
评论

相关推荐

    SQL_Server 面试笔试试题及答案

    * SQL Server 面试题涵盖了数据库管理、数据模型、SQL 语言、Transact-SQL 等多方面的知识点 * 本资源提供了 19 道 SQL Server 面试题,涵盖了数据模型、实体关系、SQL 语言、Transact-SQL 等多方面的知识点。

    SQLServer数据库 DBA面试题 最新试卷 SQL面试题

    在SQL Server数据库领域,DBA(Database Administrator,数据库管理员)的角色至关重要。他们负责数据库的设计、实施、监控、优化以及安全等方面的工作。以下是一些在DBA面试中可能会遇到的SQL Server相关知识点,...

    SQL SERVER面试题

    以上是对SQL Server面试题的详细解答,涵盖了磁盘配置、集群管理、复制策略、索引优化、备份策略、数据库管理和DBA素质等多个方面,旨在全面展示SQL Server的相关知识和实际操作经验。这些问题的答案有助于面试者...

    SQLServer面试题

    SQL Server 面试题 本文总结了 SQL Server 相关的知识点,涵盖了 SQL 语句的编写、查询优化、表合并、union 和 union all 的区别等内容。 一、查询优化 在 SQL Server 中,查询优化是非常重要的。通过编写高效的 ...

    SQlServer面试题.doc

    这篇文档“SQLServer面试题.doc”显然包含了与SQL Server相关的面试问题,可能是为了帮助求职者准备数据库管理员(DBA)、数据库开发人员或数据分析职位的面试。以下是一些可能出现在SQL Server面试中的关键知识点:...

    Oracle数据库DBA面试题50道及答案.pdf

    以下是针对给定的Oracle数据库DBA面试题的知识点详细解析: 1. **冷备份和热备份的区别及其优点**: - **热备份**:在数据库运行时(归档模式下)进行备份。优点是可以使用数据库,且可将数据库恢复到任意时间点。...

    12道必须掌握的数据库面试题(sql server 2008)

    以上就是针对SQL Server 2008数据库面试题可能涵盖的关键知识点,熟练掌握这些内容将极大地提高面试成功的机会。文件`十二道数据库连接面试题.sql`可能包含具体的题目,实际解答时需要结合这些题目深入探讨。

    微软SQL Server 2005数据库面试题

    【SQL Server 2005面试题解析】 1. 数据库系统的核心组成部分包括数据库(DB)、数据库管理系统(DBMS)、数据库管理员(DBA)以及操作系统(OS)和计算机硬件。选项D正确,它概括了数据库系统的基础架构。 2. 在...

    SQL_Server数据库管理员面试题(DBA)

    ### SQL Server数据库管理员(DBA)面试题解析 #### 标题与描述中的知识点解析: **SQL Server数据库管理员(DBA)面试题**这一标题表明了本文档主要关注的是针对SQL Server数据库管理员岗位的面试题目及其解答思路。...

    国外DBA面试题

    国外DBA面试题 Oracle DBA面试题

    DBA面试题 oracle

    DBA面试题 Oracle 本文总结了 Oracle 数据库管理员(DBA)面试中的一些重要知识点,从表连接方式、执行计划、CBO 和 RBO、SQL 调整、索引、绑定变量、执行计划、排序等方面进行了详细的解释。 一、表连接方式 在 ...

    SQL_Server_DBA_名企面试问题及答案

    ### SQL Server DBA 名企面试问题及答案 #### 1. 磁盘柜配置与数据库物理部署 **问题背景**:给定一个磁盘柜,包含14块73G的磁盘,需要配置以支持一个200G大小(含日志文件)的数据库。 **解决方案**: - **RAID...

    MySQL数据库高级工程师-面试题-MySQLDBA面试题03-风哥整理面试必过.rar

    【MySQL数据库高级工程师面试知识点详解】 在MySQL数据库高级工程师的...以上这些知识点是MySQL DBA面试中可能会遇到的重点,深入理解和实践这些内容,将有助于你顺利通过面试并成为一名优秀的MySQL数据库高级工程师。

    DBA常见理论面试题

    DBA常见理论面试题 以下是对给定文件的知识点总结: 数据库基础概念 * char、varchar、nvarchar之间的区别:char是固定长度字符串,varchar是可变长度字符串,nvarchar是unicode字符集的可变长度字符串。它们的...

    数据库面试题-DBA数据库管理员

    数据库面试题-DBA数据库管理员 以下是从给定的文件中生成的相关知识点: 1. 数据抽象: 数据抽象是指数据库管理系统中对数据的抽象表示,可以分为物理抽象、概念抽象和视图级抽象。物理抽象关心的是数据的物理存储...

    Oracle数据库DBA面试题

    ### Oracle数据库DBA面试题详解 #### 1. 解释冷备份和热备份的不同点以及各自的优点 - **冷备份**:这是一种简单的物理文件复制方式,通常在数据库完全关闭的情况下进行。冷备份适用于所有模式的数据库,无论是...

    SQL数据库面试题及答案

    SQL数据库面试题及答案,希望有帮助!有志于成为sql dba的可以看看。谢谢

    2021年sql数据库基础面试题复习题考试题全.docx

    以下是对SQL数据库基础面试题的解析,帮助你复习并准备相关考试。 1. SQLServer数据库的主数据文件扩展名是.mdf(选项D)。这代表了主要数据文件,其中存储了数据库的表、索引和其他对象。 2. 在SQL Server中,不...

    DBA_SQL查询面试题.doc

    DBA_SQL 查询面试题 本资源提供了 DBA_SQL 面试题,涵盖了 SQL 查询的基本概念和高级应用,涉及到嵌套语句、连接查询、子查询、分组和聚合函数等多个知识点。 知识点 1: 嵌套语句查询 知识点描述:使用标准 SQL ...

    oracle数据库dba面试题.doc

    Oracle数据库DBA面试题涵盖了数据库管理的多个关键领域,包括备份与恢复、数据库配置、数据存储、索引优化、约束、数据库性能监控等。以下是对这些知识点的详细说明: 1. **冷备份与热备份**:冷备份是在数据库关闭...

Global site tag (gtag.js) - Google Analytics