SQL存储过程测试(4)——创建T
问题
如何创建一个T-SQL测试套件用于测试SQL存储过程。
设计
首无,通过插入大量测试平台数据准备好一个包含待测存储过程的底层数据库。接下来,使用一个SQL游标(cursor)遍历这个测试用例数据表。针对每个测试用例,调用待测存储过程并且取得它的返回值,把实际返回值与期望值进行比较,从而判定测试结果是通过与否,然后显示或保存测试结果。
方案
——testAuto.sql
——为dbEmployees填充数据
truncate table dbEmployees.dbo.tblEmployees
insert into dbEmployees.dbo.tblEmployees values('e11','Adams','15/10/2009')
insert into dbEmployees.dbo.tblEmployees values('e22','Baker','15/10/2009')
insert into dbEmployees.dbo.tblEmployees values('e33','Young','15/10/2009')
insert into dbEmployees.dbo.tblEmployees values('e44','Zetta','15/10/2009')
——此处插入更多数据
declare tCursor cursor fast_forward
for select caseID,input,expected
from dbTestCasesAndResults.dbo.tblTestCases
order by caseID
declare @caseID char(4),@input char(3),@expected int
declare @actual int,@whenRun datetime
declare @resultLine varchar(50)
set @whenRun = getdate()
open tCursor
fetch next
from tCursor
into @caseID,@input,@expected
while @@fetch_status = 0
begin
exec @actual = dbEmployees.dbo.usp_StatusCode @input
if (@actual = @expected)
begin
set @resultLine = @caseID + ': Pass'
print @resultLine
end
else
begin
set @resultLine = @caseID + ': FAIL'
&nbs
相关文档:
1、与group by搭配使用的函数
在数据库中,我们可以使用GROUP BY函数把数据组合在一起,从而获得总计信息。可以把此功能看成是一种当数据从数据库中返回时把相同类型的信息集中到一起的能力。下面给出了完整列表。
avg([distinct]column_name)
求所有雇员薪水的平均值。
select AVG(emp_salary)
from employee;
求取c ......
index.jsp
<%@ page language="java" import="java.sql.*" import="java.lang.*" import="java.util.*" pageEncoding="GB2312"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<%!
& ......
1 ,对于日期字段字段
access表示为:#1981-28-12#
SQLSERVER2000表示为:''1981-02-12''
2,SQL语句区别,select ,update 在对单表操作时都差不多,
但多表操作时update语句的区别ACCESS与SQLSERVER中的Update语句对比:
SQLSERVER中更新多表的Update语句:
Update Tab1
SET a.Name = b.Name
from Tab1 a,Tab2 b
Whe ......
如果你经常遇到下面的问题,你就要考虑使用SQL Server的模板来写规范的SQL语句了:
SQL初学者。
经常忘记常用的DML或是DDL SQL 语句。
在多人开发维护的SQL中,每个人都有自己的SQL习惯,没有一套统一的规范。
在SQL Server Management Studio中,已经给大家提供了很多常用的现成SQL规范模板。
SQL Server Management ......
--将系统datediff函数重写,主要把datepart类型改为varhcar,方便调用
--作者:敖士伟
--Date:2009-10-14 10:29
create function MyDateDiff(@datepart varchar(50), --日期间隔类型:year,month,day.etc
@date1 varchar(50), @date2 varchar(50))
returns int
as
begin
declare @part int
if @datepart ......