RedGate 工具SQLTEST 1.0.15.1

浏览: 2220

SQL TEST1.0.15.1的破解可以参考这篇文章:http://www.cnblogs.com/VAllen/archive/2012/10/01/SQLTest.html

SQL TEST1.0.15.1下载:http://www.kuaipan.cn/file/id_4401224786926114.htm

安装完SQL TEST之后,会在SSMS了的工具栏见到SQL TEST的按钮

点击按钮就会弹出SQL TEST

 

SQL TEST默认已经创建好5个测试数据库中错误的存储过程

第一个存储过程测试数据库中是否有Decimal数据类型大小的问题

第二个存储过程测试数据库中是否有以SP_开头的存储过程

第三个存储过程测试数据库中使用的动态sql是否没有使用sp_executesql来调用

第四个存储过程测试数据库中的存储过程是否有@@Identity全局变量

第五个存储过程测试数据库中存储过程是否有使用SET ROWCOUNT

 

 

您可以编辑这些默认的测试存储过程

例如第一个存储过程,测试Decimal数据类型大小错误

 1 ALTER PROCEDURE [SQLCop].[test Decimal Size Problem]
2 AS
3 BEGIN
4 -- Written by George Mastros
5 -- February 25, 2012
6 -- http://sqlcop.lessthandot.com
7 -- http://blogs.lessthandot.com/index.php/DataMgmt/DBProgramming/always-include-precision-and-scale-with
8
9 SET NOCOUNT ON
10
11 Declare @Output VarChar(max)
12 Set @Output = ''
13
14 Select @Output = @Output + Schema_Name(schema_id) + '.' + name + Char(13) + Char(10)
15 From sys.objects
16 WHERE schema_id <> Schema_ID('SQLCop')
17 And schema_id <> Schema_Id('tSQLt')
18 and (
19 REPLACE(REPLACE(Object_Definition(object_id), ' ', ''), 'decimal]','decimal') COLLATE SQL_LATIN1_GENERAL_CP1_CI_AI LIKE '%decimal[^(]%'
20 Or REPLACE(REPLACE(Object_Definition(object_id), ' ', ''), 'numeric]','numeric') COLLATE SQL_LATIN1_GENERAL_CP1_CI_AI LIKE '%[^i][^s]numeric[^(]%'
21 )
22 Order By Schema_Name(schema_id), name
23
24 If @Output > ''
25 Begin
26 Set @Output = Char(13) + Char(10)
27 + 'For more information: '
28 + 'http://blogs.lessthandot.com/index.php/DataMgmt/DBProgramming/always-include-precision-and-scale-with'
29 + Char(13) + Char(10)
30 + Char(13) + Char(10)
31 + @Output
32 EXEC tSQLt.Fail @Output
33 End
34 END;

您也可以运行他,他会检查数据库中每个表的数据类型,并检查每个表中的数据

如果你想一次过执行所有的测试存储过程可以按左上角的Run Tests按钮


下面来试一下怎麽使用,先创建一个以SP_开头的存储过程

您可以按左上角的Run Tests按钮或者只选中test Procedures Named SP_这个测试存储过程

然后右键-》Run Test

 

其他4个测试存储过程

 1 ALTER PROCEDURE [SQLCop].[test Procedures With SET ROWCOUNT]
2 AS
3 BEGIN
4 -- Written by George Mastros
5 -- February 25, 2012
6 -- http://sqlcop.lessthandot.com
7 -- http://sqltips.wordpress.com/2007/08/19/set-rowcount-will-not-be-supported-in-future-version-of-sql-server/
8
9 SET NOCOUNT ON
10
11 Declare @Output VarChar(max)
12 Set @Output = ''
13
14 SELECT @Output = @Output + Schema_Name(schema_id) + '.' + name + Char(13) + Char(10)
15 From sys.all_objects
16 Where type = 'P'
17 AND name Not In('sp_helpdiagrams','sp_upgraddiagrams','sp_creatediagram','testProcedures With SET ROWCOUNT')
18 And Replace(Object_Definition(Object_id), ' ', '') COLLATE SQL_LATIN1_GENERAL_CP1_CI_AI Like '%SETROWCOUNT%'
19 And is_ms_shipped = 0
20 and schema_id <> Schema_id('tSQLt')
21 and schema_id <> Schema_id('SQLCop')
22 ORDER BY Schema_Name(schema_id) + '.' + name
23
24 If @Output > ''
25 Begin
26 Set @Output = Char(13) + Char(10)
27 + 'For more information: '
28 + 'http://sqltips.wordpress.com/2007/08/19/set-rowcount-will-not-be-supported-in-future-version-of-sql-server/'
29 + Char(13) + Char(10)
30 + Char(13) + Char(10)
31 + @Output
32 EXEC tSQLt.Fail @Output
33 End
34 END;

 1 ALTER PROCEDURE [SQLCop].[test Procedures with @@Identity]
2 AS
3 BEGIN
4 -- Written by George Mastros
5 -- February 25, 2012
6 -- http://sqlcop.lessthandot.com
7 -- http://wiki.lessthandot.com/index.php/6_Different_Ways_To_Get_The_Current_Identity_Value
8
9 SET NOCOUNT ON
10
11 Declare @Output VarChar(max)
12 Set @Output = ''
13
14 Select @Output = @Output + Schema_Name(schema_id) + '.' + name + Char(13) + Char(10)
15 From sys.all_objects
16 Where type = 'P'
17 AND name Not In('sp_helpdiagrams','sp_upgraddiagrams','sp_creatediagram','testProcedures with @@Identity')
18 And Object_Definition(object_id) COLLATE SQL_LATIN1_GENERAL_CP1_CI_AI Like '%@@identity%'
19 And is_ms_shipped = 0
20 and schema_id <> Schema_id('tSQLt')
21 and schema_id <> Schema_id('SQLCop')
22 ORDER BY Schema_Name(schema_id), name
23
24 If @Output > ''
25 Begin
26 Set @Output = Char(13) + Char(10)
27 + 'For more information: '
28 + 'http://wiki.lessthandot.com/index.php/6_Different_Ways_To_Get_The_Current_Identity_Value'
29 + Char(13) + Char(10)
30 + Char(13) + Char(10)
31 + @Output
32 EXEC tSQLt.Fail @Output
33 End
34
35 END;

 1 ALTER PROCEDURE [SQLCop].[test Procedures using dynamic SQL without sp_executesql]
2 AS
3 BEGIN
4 -- Written by George Mastros
5 -- February 25, 2012
6 -- http://sqlcop.lessthandot.com
7 -- http://blogs.lessthandot.com/index.php/DataMgmt/DataDesign/avoid-conversions-in-execution-plans-by-
8
9 SET NOCOUNT ON
10
11 Declare @Output VarChar(max)
12 Set @Output = ''
13
14 SELECT @Output = @Output + SCHEMA_NAME(so.uid) + '.' + so.name + Char(13) + Char(10)
15 From sys.sql_modules sm
16 Inner Join sys.sysobjects so
17 On sm.object_id = so.id
18 And so.type = 'P'
19 Where so.uid <> Schema_Id('tSQLt')
20 And so.uid <> Schema_Id('SQLCop')
21 And Replace(sm.definition, ' ', '') COLLATE SQL_LATIN1_GENERAL_CP1_CI_AI Like '%Exec(%'
22 And Replace(sm.definition, ' ', '') COLLATE SQL_LATIN1_GENERAL_CP1_CI_AI Not Like '%sp_Executesql%'
23 And OBJECTPROPERTY(so.id, N'IsMSShipped') = 0
24 Order By SCHEMA_NAME(so.uid),so.name
25
26 If @Output > ''
27 Begin
28 Set @Output = Char(13) + Char(10)
29 + 'For more information: '
30 + 'http://blogs.lessthandot.com/index.php/DataMgmt/DataDesign/avoid-conversions-in-execution-plans-by-'
31 + Char(13) + Char(10)
32 + Char(13) + Char(10)
33 + @Output
34 EXEC tSQLt.Fail @Output
35 End
36
37 END;

 1 ALTER PROCEDURE [SQLCop].[test Procedures Named SP_]
2 AS
3 BEGIN
4 -- Written by George Mastros
5 -- February 25, 2012
6 -- http://sqlcop.lessthandot.com
7 -- http://blogs.lessthandot.com/index.php/DataMgmt/DBProgramming/MSSQLServer/don-t-start-your-procedures-with-sp_
8
9 SET NOCOUNT ON
10
11 Declare @Output VarChar(max)
12 Set @Output = ''
13
14 SELECT @Output = @Output + SPECIFIC_SCHEMA + '.' + SPECIFIC_NAME + Char(13) + Char(10)
15 From INFORMATION_SCHEMA.ROUTINES
16 Where SPECIFIC_NAME COLLATE SQL_LATIN1_GENERAL_CP1_CI_AI LIKE 'sp[_]%'
17 And SPECIFIC_NAME COLLATE SQL_LATIN1_GENERAL_CP1_CI_AI NOT LIKE '%diagram%'
18 AND ROUTINE_SCHEMA <> 'tSQLt'
19 Order By SPECIFIC_SCHEMA,SPECIFIC_NAME
20
21 If @Output > ''
22 Begin
23 Set @Output = Char(13) + Char(10)
24 + 'For more information: '
25 + 'http://blogs.lessthandot.com/index.php/DataMgmt/DBProgramming/MSSQLServer/don-t-start-your-procedures-with-sp_'
26 + Char(13) + Char(10)
27 + Char(13) + Char(10)
28 + @Output
29 EXEC tSQLt.Fail @Output
30 End
31 END;

 

SQLTEST还会在测试数据库生成一些存储过程和函数

其中某些存储过程是加密了的

并且SQL PROMPT也不能解密这些tSQLt存储过程并且没有语法提示,应该是REDGATE想保护自己的产品吧

所以不给你显示这些存储过程的内容也不给你调用这些加密的存储过程

你只能查看并调用没有加密的tSQLt存储过程


 创建测试存储过程

如果自己编写测试案例的话,需要掌握tSQLt这个工具

由于tSQLt比较复杂,网上资料也很少,所以本人还没有掌握怎麽编写新的测试存储过程

这里给出一些参考网站:

使用tSQLt进行SQL Server单元测试

SQL Test让SQL Server Management Studio具备tSQLt单元测试功能
tSQLt Tutorial

tSQLt User Guide


SQL TEST跟SQL PROMPT一样,根据SQLSERVER版本来开发的

 

如有不对的地方,欢迎大家拍砖o(∩_∩)o

推荐 0
本文由 桦仔 创作,采用 知识共享署名-相同方式共享 3.0 中国大陆许可协议 进行许可。
转载、引用前需联系作者,并署名作者且注明文章出处。
本站文章版权归原作者及原出处所有 。内容为作者个人观点, 并不代表本站赞同其观点和对其真实性负责。本站是一个个人学习交流的平台,并不用于任何商业目的,如果有任何问题,请及时联系我们,我们将根据著作权人的要求,立即更正或者删除有关内容。本站拥有对此声明的最终解释权。

0 个评论

要回复文章请先登录注册