4221学习网
首页 | 网址大全 | 脑力倍增 | 电脑学院 | 学习方法 | 英语学习 | 口才交际 | 工作职场 | 成功励志 | 文学小说 | 视频教程 | 视频短片 | 下载中心 | NBA | 奥运 | 图片专区 | QQ·技巧 | 游戏技巧 | 恋爱技巧 | 谈天说地 | 专题教程 | 4221论坛
热门关键字: 视频教程  百家讲坛  美女  记忆力  疯狂英语
 → 当前位置:4221学习网>电脑学院>数据库>sql server>正文

某外企SQL Server面试题

4221学习网 2007-06-08 来源:互联网 收藏本文

训练30小时,让阅读提速5-10倍!---速读记忆训练软件免费下载!(点击下载)

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:
Answer 4:用动态SQL实现

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


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:

共2页: 上一页 1 [2] 下一页
上一篇:一些SQL Server的应用实例   下一篇:SQL Server数据库文件恢复技术
添加到google书签 digg this! 添加到bolaa 添加到yahoo+ 添加到新浪vivi 添加到365key  
收藏】 【评论】 【推荐】 【投稿】 【打印】 【关闭

相关文章
·一些SQL Server的应用实例
·SQL Server数据库文件恢复技术
·同步两个SQLServer数据库
·SQL SERVER服务器的“偷梁换柱”
·精通数据库系列之入门-技巧篇5
·精通数据库系列之入门-技巧篇4
·精通数据库系列之入门-技巧篇3
·精通数据库系列之入门-技巧篇2
·精通数据库系列之入门-技巧篇1
·精通数据库系列之入门-基础篇3
发表评论
要记得去论坛讨论,点击注册新会员) 密码: 匿名评论
评论内容:(请自觉遵守互联网相关政策法规。)

最新文章
·精通数据库系列之入门-基础篇1
·精通数据库系列之入门-基础篇2
·精通数据库系列之入门-基础篇3
·精通数据库系列之入门-技巧篇1
·精通数据库系列之入门-技巧篇2
·精通数据库系列之入门-技巧篇3
·精通数据库系列之入门-技巧篇4
·精通数据库系列之入门-技巧篇5
·SQL SERVER服务器的“偷梁换柱”
·同步两个SQLServer数据库
本类阅读排行榜
·同步两个SQLServer数据库
·一些SQL Server的应用实例
·精通数据库系列之入门-基础篇1
·SQL SERVER服务器的“偷梁换柱”
·SQL Server数据库文件恢复技术
·精通数据库系列之入门-基础篇2
·精通数据库系列之入门-技巧篇1
·精通数据库系列之入门-技巧篇2
·精通数据库系列之入门-基础篇3
·精通数据库系列之入门-技巧篇3
热点视频教程
视频街舞 舞步 教学
视频windowsxp重装系统视频教程
视频李孝利十分钟详细舞蹈教程
视频美女教你跳舞
视频街舞 舞步 教学2
视频双截棍视频教程-定式
视频如何安装双操作系统
视频韩国的太空步教程,后滑、侧滑、旋转太空
视频【WindowsXP入门教程】 - 硬盘分区
视频台球教程-基本杆法
视频[百家讲坛]三十六计01_借刀杀人
视频24式太极拳教学---基本动作
视频 斯诺克台球竿法-后退球
视频动物世界之决战生死线2
视频超级全脑速读训练教程

设为首页 - 加入收藏 - 关于我们 - 联系我们 - 友情连接

4221学习网版权所有-鄂ICP备07006816号
已浏览: