易截截图软件、单文件、免安装、纯绿色、仅160KB

SQL基础问题整理(1)——你答对了多少?

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


相关文档:

ASP.NET防SQL注入脚本程序

public class SqlCheck  
{  
    public SqlCheck()  
    {  
        //  
        // TODO: 在此处添加构造函数逻辑  
  & ......

SQL执行顺序

一、sql语句的执行步骤:
1)语法分析,分析语句的语法是否符合规范,衡量语句中各表达式的意义。
2) 语义分析,检查语句中涉及的所有数据库对象是否存在,且用户有相应的权限。
3)视图转换,将涉及视图的查询语句转换为相应的对基表查询语句。
4)表达式转换, 将复杂的 SQL 表达式转换为较简单的等效连接表达式 ......

安装Oracle 10g inistant client后是PL/SQL出现乱码

想使用PL/SQL开发工具,但不想安装那个几百兆的oracle客户端,于是安装了oracle 10g inistant client,40多M吧。
安装后PL/SQL可以用了,但是查询出记录里面的中文却是乱码。折腾了好久才找出解决方法:
设置环境变量:NLS_LANG,值为Oracle数据库设置的字符集,在我的系统里面设置是:SIMPLIFIED CHINESE_CHINA.ZHS16GBK ......

SQL Server2005 中用 Pivot 生成交叉表

最近在做一个数据统计,要求对一个表中的数据按照两个维度呈现,也就是传统的交叉表
比如,有一个问题表,有三个字段,(标题、问题类别、问题状态)
要求按照不同的类别,分别统计处各个状态的问题数量(如:产品问题中未处理的数量、服务问题中遗留问题数量等等)。
经过查找和尝试,终于生成了结果,现在分享给大家。 ......

测试一下自己的SQL水平

 
create table Student(Sname varchar(10),Ssex varchar(5),Sage int,S# int)
insert into Student
select '夏亮','男','21','1004'
select '成平','男','20','1001' union all
select '王波','男','19','1002' union all
select '突然','女','19','1003'
 
create table Course(C# varchar(10),Cname v ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号