一段输出代码本身的SQL代码
转自http://www.111cn.cn/database/109/b992816b1dddbb641c25c0999883427e.htm
declare @text nvarchar(max);
with tb
as
(
select blocking_session_id,
session_id,db_name(database_id) as dbname,text from master.sys.dm_exec_requests a
CROSS APPLY master.sys.dm_exec_sql_text(a.sql_handle)
),
tb1 as
(
select a.*,login_time,program_name,client_interface_name,login_name,cpu_time,memory_usage*8 as 'memory_usage(KB)',
total_scheduled_time,reads,writes,logical_reads
from tb a inner join master.sys.dm_exec_sessions b
on a.session_id=b.session_id
)
select @text=text from tb1 a inner join master.sys.dm_exec_connections b on a.session_id=b.session_id
print @text
/*
declare @text nvarchar(max);
with tb
as
(
select blocking_session_id,
session_id,db_name(database_id) as dbname,text from master.sys.dm_exec_requests a
CROSS APPLY master.sys.dm_exec_sql_text(a.sql_handle)
),
tb1 as
(
select a.*,login_time,program_name,client_interface_name,login_name,cpu_time,memory_usage*8 as 'memory_usage(KB)',
total_scheduled_time,reads,writes,logical_reads
from tb a inner join master.sys.dm_exec_sessions b
on a.session_id=b.session_id
)
select @text=text from tb1 a inner join master.sys.dm_exec_connections b on a.session_id=b.session_id
print @text
*/
还可以短一点:
declare @text nvarchar(max);
select @text=text
from master.sys.dm_exec_requests a
CROSS APPLY master.sys.dm_exec_sql_text(a.sql_handle)
print @text
/*
declare @text nvarchar(max);
select @text=text
from master.sys.dm_exec_requests a
CROSS APPLY master.sys.dm_exec_sql_text(a.sql_handle)
print @text
*/
相关文档:
select gztzid,
gztztt,
gztzbt,
gztznr,
fslxmc,
decode(fsfs, '0', '无需回复', '1', '需要回复') fsfs,
&nb ......
USE AdventureWorks
GO
CREATE PROC spEmployee
AS
SELECT * from Humanresources.Employee
EXEC spEmployee
ALTER PROC spEmployee
AS SELECT EmployeeID from Humanresources.Employee
drop proc spEmployee
ALTER PROC spEmployee
@LastName nvarchar(50) = NULL
AS
IF @LastName IS NULL
SELECT * f ......
此部分内容创建一个轻量级T-SQL测试套件,总共有3个脚本:
用于创建测试平台数据和待测存储过程的脚本
--======================
--makeDbTestAndResults.sql
use master
go
if exists (select * from sysdatabases where name = 'DbTestAndResults')
drop database makeDbTes ......
温故而知新,果然如此呀,第二次再翻开同样的内容果然有不同的收获,有些是第一次看的时候没有仔细理解的,还有些可能是在第一次看匆匆就跳过的,当然,可能还有部分是自己当时记住了完了又给忘记了。今天第二次看到子程序这一章节,发现了些新的内容,呵呵。在这里我就写下一些基本内容和容易忘记的,免得下次又给忘了。内 ......
(1)char、varchar、text和nchar、nvarchar、ntext
char和varchar的长度都在1到8000之间,它们的区别在于char是定长字符数据,而varchar是变长字符数据。所谓定长就是长度固定的,当输入的数据长度没有达到指定的长度时将自动以英文空格在其后面填充,使长度达到相应的长度;而变长字符数据则不会以空格填充。text存储可变 ......