快精灵印艺坊 您身边的文印专家
广州名片 深圳名片 会员卡 贵宾卡 印刷 设计教程
产品展示 在线订购 会员中心 产品模板 设计指南 在线编辑
 首页 名片设计   CorelDRAW   Illustrator   AuotoCAD   Painter   其他软件   Photoshop   Fireworks   Flash  

 » 彩色名片
 » PVC卡
 » 彩色磁性卡
 » 彩页/画册
 » 个性印务
 » 彩色不干胶
 » 明信片
   » 明信片
   » 彩色书签
   » 门挂
 » 其他产品与服务
   » 创业锦囊
   » 办公用品
     » 信封、信纸
     » 便签纸、斜面纸砖
     » 无碳复印纸
   » 海报
   » 大篇幅印刷
     » KT板
     » 海报
     » 横幅

SQL SCRIPT TIPS FOR MS SQL SERVER

This posting will show you some script tips about MS SQL Server.
1. Waitfor
The WAITFOR statement is specified with one of two clauses:
(1) The DELAY keyword followed by an amount of time to pass before completing the WAITFOR statement. The time to wait before completing the WAITFOR statement can be up to 24 hours. For example,
-- Wait for ten secondes before perforing a select statement
WAITFOR DELAY \\\'00:00:10\\\'
Select EmployeeID From Northwind.dbo.Employees

(2) The TIME keyword followed by a time to execute, which specifies completion of the WAITFOR statement.
For example,
-- Wait until 10:00 PM to perform a check of the pubs database to make sure that all pages are correctly allocalted and used.
Use pubs
BEGIN
WAITFOR TIME \\\'22:00\\\'
DBCC CHECKALLOC
END

2. Enable SQL Debugging
-- The SP_SDIDEBUG stored procedure is used by SQL Server for debugging Transact-SQL statements
Use master
Grant Execute on SP_SDIDEBUG to Username

3. Execute a dynamically built string
(1) EXECUTE statement
With the EXECUTE statement, all parameter values must be converted to character or Unicode and made a part of Transact-SQL string. For example,
DECLARE @IntVariable INT
DECLARE @SQLString NVARCHAR(500)
/* Build and execute a string with one parameter value. */
SET @IntVariable = 35
SET @SQLString = N\\\'SELECT * FROM pubs.dbo.employee WHERE job_lvl = \\\' +
CAST(@IntVariable AS NVARCHAR(10))
EXEC(@SQLString)
/* Build and execute a string with a second parameter value. */
SET @IntVariable = 201
SET @SQLString = N\\\'SELECT * FROM pubs.dbo.employee WHERE job_lvl = \\\' +
CAST(@IntVariable AS NVARCHAR(10))
EXEC(@SQLString)

(2) SP_ExecuteSQL
Using sp_executesql is recommended over using the EXECUTE statement to execute a string. Not only does the support for parameter substitution make sp_executesql more versatile than EXECUTE, it also makes sp_executesql more efficient because it generates execution plans that are more likely to be reused by SQL Server.
sp_executesql supports the setting of parameter values separately from the Transact-SQL string:

DECLARE @IntVariable INT
DECLARE @SQLString NVARCHAR(500)
DECLARE @ParmDefinition NVARCHAR(500)

/* Build the SQL string once. */
SET @SQLString =
N\\\'SELECT * FROM pubs.dbo.employee WHERE job_lvl = @level\\\'
/* Specify the parameter format once. */
SET @ParmDefinition = N\\\'@level tinyint\\\'

/* Execute the string with the first parameter value. */
SET @IntVariable = 35
EXECUTE sp_executesql @SQLString, @ParmDefinition,
@level = @IntVariable
/* Execute the same string with the second parameter value. */
SET @IntVariable = 32
EXECUTE sp_executesql @SQLString, @ParmDefinition,
@level = @IntVariable

4. SP_HelpText
Prints the text of a rule, a default, or an unencrypted stored procedure, user-defined function, trigger, or view.
-- This example displays the text of the employee_insupd trigger, which is in the pubs database
Use Pubs
Exec sp_helptext \\\'employee_insupd\\\'
返回类别: 教程
上一教程: 三大数据库之间对比
下一教程: 将一个更新划分为几个批次

您可以阅读与"SQL SCRIPT TIPS FOR MS SQL SERVER"相关的教程:
· 建立安全的MSSQL SERVER启动账号
· 在LINUX下访问MS SQL SERVER数据库
· 使用MS SQL7的LINKED SERVER(三)
· 关于MSSQL SERVER中DATETIME类型数据的处理
· 使用MS SQL7的LINKED SERVER(二)
    微笑服务 优质保证 索取样品