SQL基础问题整理

在程序中,数据库操作是必不可少的部分,所以我们要备足数据库相关知识才能去应付程序中出现的种种问题。基于此,我特地在国外网站、博客上整理了一些问题,并附带了答案和解释、参考。为了保证“原汁原味”,我就保留了英文。大家也来看看你答对了多少?

1.SQL Server 2008 Backup

题目:Is it possible to restore a SQL Server 2008 Enterprise Edition compressed  backup to a SQL Server 2008 Standard Edition?

答案:yes

解释:RESTORE from compressed backups on SQL Server 2008 Standard Edition is  possible, although the backup compression feature is not supported in SQL Server  2008 Standard Edition.

参考:备份压缩 (SQL Server)

2.Identity

题目:We want to insert record into table a

create table a (a int identity(1,1))

Which statement will work?

  1. insert into a default values
  2. insert into a values (default)
  3. insert into a values (1)
  4. could not insert explicit for identity column

答案:insert into a default values

解释:An insert statement with "default values" works.

参考:INSERT

3.Dynamic SQL

题目:Sam has to run a query dynamically & get the count in a variable and do  some processing based on the count. Which of the following queries will return  expected output?

declare @tablevariable varchar(100)
set @tablevariable = 'Employees'

A)

declare @sql varchar(100) 
Declare @cnt int 
Set @sql = 'Select ' + Convert(varchar(100),@cnt) + ' =count(*) from ' + @tablevariable 
Exec (@sql) select @cnt

B)

declare @sql varchar(100) 
Declare @cnt int 
Set @sql = 'Select count(*) from ' + @tablevariable 
@cnt = Exec (@sql) select @cnt

C)

DECLARE @sql nvarchar(4000), @params nvarchar(4000), @count int 
SELECT @sql = N' SELECT @cnt = COUNT(*) FROM dbo.' + quotename(@tablevariable) 
SELECT @params = N'@cnt int OUTPUT' 
EXEC sp_executesql @sql, @params, @cnt = @count OUTPUT select @count

答案:C

解释:For getting a variable as output in a dynamic statement, we need to use  sp_executeSQL.

参考:Introducing Dynamic SQL

4.T-SQL Output Clause

题目:Executing the following code. How many rows are returned by the first and  second SELECT * FROM #CategoryChanges statements?

USE Northwind;
CREATE TABLE #CategoryChanges
(ChangeID int Primary Key Identity, CategoryID int, OldCategoryName nvarchar(15), NewCategoryName nvarchar(15), ModifiedDate datetime2, LoginID nvarchar(30));
BEGIN TRANSACTION
UPDATE Categories
SET CategoryName = 'Dried Produce'
OUTPUT inserted.CategoryID, deleted.CategoryName, inserted.CategoryName, getdate(), SUSER_SNAME() INTO #CategoryChanges
WHERE CategoryID = 7;
SELECT * FROM #CategoryChanges  --first select statement
Rollback tran
SELECT * FROM #CategoryChanges  --second select statement

Choose your answer:

  1. 1st 0 rows 2nd 0 rows
  2. 1st 1 row, 2nd 0 rows
  3. 1st 1 row. 2nd 2 rows

答案:1st 1 row, 2nd 0 rows

解释:The ROLLBACK TRANSACTION rolls back both the update to the table  categories and the temp table #CategoryChanges.

5.T-SQL

题目:In T-SQL, what would this be considered: " colmnnX IN (x, y, z, ...)"

答案:Predicate

解释:In T-SQL, a PREDICATE allows you to check whether a value or scalar  expression evaluates to TRUE, FALSE, or UNKNOWN. The IN clause, with column and  values becomes a predicate and checks to see if at least one of the elements in  a set is equal to a given value or expression.

参考:谓词 (Transact-SQL)

6.Server Administration

题目:Select the best option to allocate maximum available RAM (Already  installed on Windows) to SQL Server where system has following configuration:  OS: Windows 2008 64 bit, Enterprise Edition. SQL: SQL Server 2008 64 bit,  Enterprise Edition. RAM: 6 GB.

Choose your answer

  1. Enable AWE option from SQL Server configuration
  2. Add /3GB switch in boot.ini
  3. Do Nothing

答案:Do Nothing

解释:AWE is valid option for 32 bit architecture. Note that the sp_configure  awe enabled option is present on 64-bit SQL Server, but it is ignored. It is  subject to removal in future releases or service packs of 64-bit SQL Server.

3 GB Switch is supported for 32 bit editions. It tell operating system to  allocate 2 GB RAM to OS and 2 GB RAM to other program such as SQL Or Exchange,  if 4 GB RAM is installed.

参考:内存体系结构

7.SQL Server 2008

题目:The DEFAULT value for a column can be specified in the definition of a  user-defined table type?

答案:True

解释:A DEFAULT value can be specified in the definition of a user-defined table  type.

参考:CREATE  TYPE (Transact-SQL)

8.Session Settings

题目:In SQL 2008, the QOD_Customers table contains the column [Region] [nvarchar](15)  NULL and 90 rows of data. The following stored procedure is created and then  run.

SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[QOD_Test_1]
ASSET ANSI_DEFAULTS ON
-- Before rollback Select StatementSELECT COUNT(CompanyName) AS 'Before rollback' FROM [dbo].[QOD_Customers]WHERE [dbo].[QOD_Customers].[Region] IS NULLUPDATE Dbo.QOD_Customers SET Region = 'XXX' WHERE dbo.QOD_Customers.region IS NULL
-- The after update Select StatementSELECT COUNT(CompanyName) AS 'After update' FROM [dbo].[QOD_Customers]WHERE [dbo].[QOD_Customers].[Region] IS NULLROLLBACK TRANSACTION SET ANSI_DEFAULTS OFF
-- The after rollback Select StatementSELECT COUNT(CompanyName) AS 'After Rollback' FROM [dbo].[QOD_Customers]WHERE [dbo].[QOD_Customers].[Region] IS NULL
GO

The before rollback Select statement returns a count of 60. The after update  Select statement returns a count of 0 What count of rows does the after rollback  Select statement return?

答案:60

解释:When ANSI_DEFAULTS is enabled (ON), this option enables the following ISO  settings:...SET IMPLICIT_TRANSACTIONS. Msg 3903 The ROLLBACK TRANSACTION request  has no corresponding BEGIN TRANSACTION.

参考:SET  ANSI_DEFAULTS (Transact-SQL)

9.Severity Levels

题目:Error messages with severity levels below 10 indicate what?

Choose your answer:

  1. Errors can be corrected by the user
  2. Insufficient Resources
  3. Informational messages
  4. Nonfatal Internal Error Detected
  5. SQL Server Error in Resource

答案:Informational messages

解释:This is an informational message that indicates a problem caused by  mistakes in the information the user has entered and not actual errors.

参考:Error  Message Severity Levels

10.Exec on Linked Server

题目:What parameter marker is used, when EXEC() is executed on a Linked Server?

答案:?

解释:There is one thing that you can do with EXEC() at a linked server, that  you cannot do with EXEC() on a local server: you can use parameters, both for  input and output. The confuse matters, you don't use parameters with names  starting with @, instead you use question marks (?) as parameter holders. You  can run this:

DECLARE @cnt int
EXEC('SELECT ? = COUNT(*) FROM Northwind.dbo.Orders WHERE CustomerID = ?',
@cnt OUTPUT, N'VINET') AT SQL2K
SELECT @cnt

参考:How to use EXEC() at Linked Server

11.SQL 2005 - Table-Valued Parameters

题目:In SQL Server 2005 variables and parameters of a table type can be set to  NULL?

答案:SQL 2005 does not support Table-Valued Parameters

解释:Only SQL Server 2008 supports the Table-Valued Parameters. This was not a  feature available in SQL Server 2005.

12.SQL Server 2008 Policy-Based Management

题目:SQL Server 2008 Policies can be defined against the following SQL Server  Editions. Choose all if apply.

Choose your answer:

  1. SQL Server 2008
  2. SQL Server 2005
  3. SQL Server 2000

答案:SQL Server 2008, SQL Server 2005, SQL Server 2000

解释:The Enterprise Policy Management (EPM) Framework leverages and extends the  new Microsoft SQL Server 2008 Policy-Based Management feature across an entire  SQL Server enterprise, including down-level instances of SQL Server such as SQL  Server 2000 and SQL Server 2005.

参考:Enterprise  Policy Management Framework with SQL Server 2008

13.Indexes in SQL Server 2005

题目:What is the maximum number of indexes (clustered and nonclustered) allowed  for a table in SQL Server 2005?

答案:250

解释:Number of Clustered indexes in SQL 2005 is one and 249 non clustered  indexes, altogether 250 indexes for a table in SQL Server 2005. In SQL Server  2008, the maximum is 1000.

参考:CREATE  INDEX (Transact-SQL)

14.Predict output

题目:Try to predict the output of this code...

declare @i int, @j intset @i = 1
create table #temp (id int)while (@i<=5)beginbegin trybegin transactionif (@i = 3) set @j = @i/0insert into #temp values (@i)commit transactionend try begin catchrollback transactionprint 'this is an exception';end catchset @i = @i + 1 endselect * from #temp

Choose your answer:

  1. Results: 1 2 3 4 5 No messages
  2. Results: 1 2 3 No Messages
  3. Results: 1 2 4 5 Message: this is an exception
  4. Results: 1 2 Message: this is an exception

答案:Results: 1 2 4 5 Message: this is an exception

解释:This is a beautiful usage of TRY-CATCH block with looping. This will do  the action, create the error message for the erroneous action, don't disturb the  other actions and iterate until the last one. The results will include 4 rows,  skipping the "3" and the Messages tab will list the exception.

15.Database Size

题目:What is the Initial size of newly created database (w/o specifiing the  size for mdf/ldf)?

答案:3MB

解释:When you create the database without specifying the size for mdf / ldf the  initial size for the database if 3 MB. Click on the database node create new  database enter database name just click on OK. Check the size in properties or  can also see the before creating it in Initial Size col of New database dialog  box.

The default size for an mdf is 2MB and 1MB for an ldf, based on the model  database.

16.Removing permissions

题目:You have a standard SQL Server 2005 instance. You allow the user 'Mary' to  call a stored procedure 'UpdateCustomer' by using the following sql :

grant execute on UpdateCustomer to Mary

Prior to issuing this statement, Mary had no explicit permissions on the SP.  You then realise that you've made a mistake and want to reverse the action you  have just taken. Which statement is the best option, without impacting on any  other effective permissions?

Choose your answer:

  1. REMOVE EXECUTE permission statement
  2. REVOKE EXECUTE permission statement
  3. DENY EXECUTE permission statement
  4. GRANT NONEXECUTE permission statement

答案:REVOKE EXECUTE permission statement

解释:You are simply looking to revoke the permission you have just granted.  DENY would take precedence over any other effective permissions, and may not be  what you want to achieve. REMOVE and GRANT NONEXECUTE are not valid SQL.

17.Declarative Data Integrity

题目:After executing the following code, how many rows remain in each table  (Countries, Cities and Buyers)?

CREATE TABLE Test.Countries(CountryId INT PRIMARY KEY)
INSERT INTO Test.Countries VALUES(1),(2),(3)
GO
CREATE TABLE Test.Cities( CityId INT PRIMARY KEY,CountryId INT REFERENCES Test.Countries ON DELETE CASCADE);
INSERT INTO Test.Cities VALUES(1,1),(2,1),(3,2) 
GO
CREATE TABLE Test.Buyers(CustomerId INT PRIMARY KEY,CityId INT REFERENCES Test.Cities ON DELETE CASCADE);INSERT INTO Test.Buyers  VALUES(1,1),(2,1),(3,2)
GODELETE FROM Test.Countries WHERE CountryId = 1

答案:Countries 2, Cities 1, Buyers 0

解释:The constraints prevent some inserts and deletes from occurring.

参考:级联引用完整性约束

18.Wildcard

题目:From the data below, I need to get records with the FirstName of Kim or  Tim only. Frame the query, applying a wildcard search on the FirstName column.

like语法

答案:WHERE FirstName LIKE '[KT]im'

解释:The wildcards that can be used with LIKE include the brackets, [], which match any single character that's included inside them with the data in the field.

参考:LIKE (Transact-SQL)

19.Query cost

题目:Which of the two WHERE clauses is cost effective:

--1.
SELECT [name] FROM teacher WHERE teacher_id IN (SELECT teacher_id FROM student)--2. 
SELECT [name] FROM teacher WHERE EXISTS (SELECT 1 FROM student WHERE teacher.teacher_id = student.teacher_id)

答案:2 is more cost effective

解释:This is not a great question, and there is some debate about it. Please  read the discussion to understand. The original explanation is below:

EXISTS will return a boolean value, while IN retruns actual result set  (making results from IN heavier than EXISTS).

参考:EXISTS (Transact-SQL)、IN (Transact-SQL)

20.Bit by bit

题目:What will be result of following query:

DECLARE @bit BIT
SET @bit = 500IF @bit = 1
PRINT 'yes'
ELSE 
PRINT 'no'

答案:yes

解释:Bit constants are represented by the numbers 0 or 1, if a number larger  than one is used, it is converted to one.

参考:常量(Transact-SQL)

21.Rowcount

题目:In SQL Server 2005/2008, what would be the output of this code when you  open a new query window and execute it?

select @@ROWCOUNT 
select @@ROWCOUNT

答案:1,1

解释:When we first open a query window, the client must execute something to  connect with no results. However the result of @@rowcount is set to one. If you  were to execute some command like a SET NOCOUNT ON will @@rowcount return 0.

转载于:https://www.cnblogs.com/jameslif/p/3620907.html

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/432748.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

腾讯或联姻优酷,微信嫁女模式引发互联网通婚潮流

据消息称&#xff1a;腾讯在前段时间联姻京东后有可能继续做甩手掌柜&#xff0c;这回要甩的是腾讯视频。 前几年&#xff0c;最火爆的电商业务除了电商外&#xff0c;再者一个就是视频业务了。 不知道大家还记得优酷当时的崛起之初的情景么?我来罗列一下&#xff1a; 1、 大…

[翻译] 学习iOS开发的建议:如何从菜鸟到专家

[文章原地址] http://mobile.tutsplus.com/tutorials/iphone/ios-quick-tip-from-novice-to-expert/ 翻译有误之处请勿见笑&#xff0c;本人将在文章的部分地方添加注释&#xff0c;并根据需求增减文章内容&#xff0c;在此对原作者辛勤劳作表示感谢 iOS Quick Tip: From Novi…

[nodejs]国内npm安装nodejs modules失败的几个解决方案

使用npm安装node模块时经常有卡住安装失败的情况&#xff0c;如图所示。原因在于npm服务器在美国&#xff0c;还有就是某强大的防火墙作用。这样的问题导致很多新手放弃使用node&#xff0c;几乎每天都有新手再问这个问题。现在分享一下解决这个问题的解决方案 1.可以通过一劳永…

java 合并单元格 把数据合并没了_合并单元格

合并单元格同样也是在表格中进行&#xff0c;关于合并单元格我们需要了解的两个概念&#xff1a;colspan 合并列&#xff0c;rowspan 合并行。colspan(跨列)合并列&#xff1a;colspan属性常用在 td 中&#xff0c;用来指定单元格横向跨越的列数。比如&#xff1a;将下面表格的…

一步步学习微软InfoPath2010和SP2010--第九章节--使用SharePoint用户配置文件Web service(2)--在事件注册表单上创建表单加载规则...

下面练习中&#xff0c;你将添加表单加载规则&#xff0c;将四个文本框域和图片控件与用户配置文件web service连接。当使用用户配置文件web service时&#xff0c;你需要将控件和来自web service合适的域绑定。这个过程需要用户配置文件架构的导航和筛选&#xff0c;来抽取合适…

光耦驱动单向可控硅_华越国际一文带路:可控硅触发设计技巧

序可控硅(Silicon Controlled Rectifier,简称SCR)&#xff0c;是可控硅整流元件的简称&#xff0c;是一种具有三个PN结的四层结构的大功率半导体器件&#xff0c;亦称为晶闸管。具有体积小、结构相对简单、功能强等特点&#xff0c;是比较常用的半导体器件之一。家用电器中的调…

Servlet JSP系列文章总结

前言 谢谢大家的捧场&#xff0c;真心感谢我的阅读者。 all 下一期&#xff0c;重点在 数据结构和算法 &#xff0c;希望给大家带来开心。已经出了几篇&#xff0c;大家爱读就是我的开心。 Servlet & JSP系列总结 博客&#xff0c;呵呵&#xff01;很开心&#xff0c;认识…

一般通话记录能保存多少条_鸡蛋放冰箱,能保存多少天?正确保存方法是什么?...

鸡蛋是我们经常吃的食物&#xff0c;很多家庭都会经常的买鸡蛋吃。相信大家买回来鸡蛋之后&#xff0c;普遍都是把鸡蛋放入冰箱里&#xff0c;什么时候想吃什么时候拿一个。但是大家可能不知道的是&#xff0c;鸡蛋就算是放在冰箱里保存&#xff0c;也是有保质期的&#xff0c;…

基本矩阵运算的Java实现

基本矩阵运算的Java实现 分类&#xff1a; 图像处理2012-09-18 10:36 2537人阅读 评论(3) 收藏 举报javamatrixparametersstringclassnull一&#xff1a; 矩阵的加法与减法 规则&#xff1a;矩阵的加法与减法要求两个矩阵的行列完全相等&#xff0c;方可以完成两个矩阵的之间的…

json返回页面读取data里的值都是object_【一】尤大神都说Vite香,让我来手把手分析Vite原理...

戳蓝字"前端优选"关注我们哦&#xff01;一.什么是Vite&#xff1f;法语Vite(轻量&#xff0c;轻快)vite 是一个基于 Vue3单文件组件的非打包开发服务器&#xff0c;它做到了本地快速开发启动、实现按需编译、不再等待整个应用编译完成的功能作用。对于Vite的描述&am…

e记法 python 底数_备战python二级

明天考试去&#xff0c;滚吧提醒与分值&#xff1a;1*40&#xff08;选择&#xff09;5*3&#xff08;填空&#xff09;101520比如今年的一个题目是要求随机抽一个手机品牌&#xff0c;这道题目的关键点在于你要使用seed()函数覆盖原来的给定的种子seed(1)&#xff0c;因为要求…

V210 UART TX 流程

1. 虽然V210的uart驱动是平台总线设备驱动模型&#xff0c;但实际上他还是以字符设备驱动存在&#xff0c;那么分析他的发送流程&#xff0c; 首先找到他的file_operations的write函数 drivers/char/tty_io.c tty_write(struct file *file, const char __user *buf, size_t cou…

浙江省计算机二级办公软件高级应用分值,浙江计算机二级高级办公软件word题分值是多少...

计算机文化基础试题集(浙江省计算机办公室软件等级考试悬赏分&#xff1a;10 - 离问题结束还有 12 天 23 小时一、选择题((1)&#xff5e;(30)每小题1分&#xff0c;(31)&#xff5e;(55)每小题2分&#xff0c;共80分)下列各题 A) 、B)、C)、D)四个选项中&#xff0c;只有一个选…

pppd 源码修改1

1. pppd拨号成功后&#xff0c;会将解析到的dns服务器IP地址&#xff0c;写入/etc/ppp/resolv.conf 这样的话&#xff0c;gethostbyname_r并不会识别&#xff0c;并且&#xff0c;如果有启动两路pppd的话&#xff0c;后面一路会将resolv.conf文件重写。 因此&#xff0c;这块代…

location.href属于重定向还是转发_servlet2 单元测试、转发、重定向

解决服务端接收数据乱码问题。服务器默认采用 ISO8859-1 编码响应内容。// 1req.setCharacterEncoding("utf-8");// 2 byte[] bytes req.getParameter("username").getBytes("iso-8859-1"); System.out.println("username:" n…

如何在CSDN博客中的所贴的代码进行【代码块】显示

笔者最近很喜欢在csdn发一些技术博客&#xff0c;可是看了别人的博客&#xff0c;有代码的地方总是可以显示出代码块&#xff0c;而自己贴上去的代码总是没有。刚开始还以为CSDN博客里面的编辑功能有&#xff0c;可是找来找去都没有找到。后来才发现原来需要自己在源码上进行修…

学安全工程用不用计算机,上重点大学的末流专业,不如上普通大学的重点专业,你赞成吗?...

上重点大学的末流专业&#xff0c;不如上普通大学的重点专业&#xff0c;你赞成吗&#xff1f;首先&#xff0c;我对这个说法不赞成&#xff0c;这个说法是错误的。可以说&#xff1a;基本上说的是对的也是错的。说对的&#xff0c;是这个思路是对的&#xff0c;说错&#xff0…

ORACLE复杂查询之连接查询

一、传统的连接查询 1、交叉连接&#xff1a;返回笛卡尔积 WHERE中限定查询条件&#xff0c;可以预先过滤掉掉不符合条件的记录&#xff0c;返回的只是两个表中剩余记录&#xff08;符合条件的记录&#xff09;的笛卡尔积。 2、内连接&#xff1a;参与连接的表地位平等&#xf…

12306加密传输_三大运营商发5G消息白皮书:短消息服务升级,支持加密传输

4月8日&#xff0c;中国电信、中国移动、中国联通联合举行线上发布会&#xff0c;共同发布《5G消息白皮书》。《白皮书》阐述了5G消息的核心理念&#xff0c;明确了相关业务功能及技术需求&#xff0c;提出了对5G消息生态建设的若干构想。据介绍&#xff0c;5G消息业务是终端原…

winpe修复计算机无法启动,用winpe来修复无法进入系统的问题

很多网友都碰到过有的时候无法进入系统&#xff1f;不知道该怎么操作&#xff0c;U大师告诉你一个方法&#xff1a;那就是用winpe来修复无法进入系统的问题,可以先在硬盘上安装一个PE维护系统&#xff0c;重启电脑时在多重启动菜单选择Windows PE&#xff0c;系统便会自动进入P…