SQL存储过程测试(9)——示例程序
此部分内容创建一个轻量级T-SQL测试套件,总共有3个脚本:
用于创建测试平台数据和待测存储过程的脚本
--======================
--makeDbTestAndResults.sql
use master
go
if exists (select * from sysdatabases where name = 'DbTestAndResults')
drop database makeDbTestAndResults
go
if exists (select * from sysxlogins where name = 'testLogin')
exec sp_droplogin 'testLogin'
go
create database makeDbTestAndResults
go
use makeDbTestAndResults
go
create table tb1TestCases
(
caseID char(4) primary key,
input datetime not null,
expectedChecksum int not null
)
go
--下面插入的是用于usp_HiredAfter的测试数据,采用了对期望值求校验和的方法
--也可以通过BCP,BTS或者C#程序从文本文件读入这些数据
insert into tb1TestCases values('0001','10/25/2009',1042032)
insert into tb1TestCases values('0002','10/25/2009',9999999)--deliberate error
insert into tb1TestCases values('0003','10/25/2008',25527856)
insert into tb1TestCases values('0004','10/10/2006',1042032)
go
create table tb1Results
(
caseID char(4) not null,
result char(4) not null,
whenRun datetime not null
)
go
exec sp_addlogin 'testLogin','secret'
go
exec sp_grantdbaccess 'testLogin'
go
grant select,insert,delete,update on tb1TestCases to testLogin
go
grant select,insert,delete,update on tb1Results to testLogin
go
--结束脚本
用于创建测试例例数据和测试结果存储的脚本
--==========================
--makeDbEmployees.sql
use master
go
if exists(select * from sysdatabases where name = 'dbEmployees')
drop database dbEmployees
go
if exists(select * from sysxlogins where name = 'employeesLogin')
exec sp_droplogin 'employeesLogin'
go
create database dbEmployees
go
use dbEmployees
go
create table tb1Employees
(
empID char(3) primary key,
empLast varchar(35) not null,
empDOH datetime not null,
)
go
insert into tb1Employees values('e11','Adams','10/25/2009')
insert into tb1Employees
相关文档:
摘要
对于SQL Server中的约束,想必大家并不是很陌生。但是约束中真正的内涵是什么,并不是很多人都很清楚的。本文以详细的文字来介绍了什么是约束,以及如何在数据库编程中应用和使用这些约束,来达到更好的编程效果。(本文部分内容参考了SQL Server联机手册)
内容
数据完整性分类
实体完整性
&nb ......
这里介绍sql server2005里面的一个使用实例:
CREATE TABLE tb(province nvarchar(10),city nvarchar(10),score int)
INSERT tb SELECT '陕西','西安',3
UNION ALL SELECT '陕西','安康',4
UNION ALL SELECT '陕西','汉中',2
UNION ALL SELECT '广东','广州',5
UNION ALL SELECT '广东','珠海',2
UNION ......
我们在做很多项目时都要涉及到数据库,特别是一些比较大型的web项目,更是有较大的并发处理,所以对数据库的操作有可能会产生死锁,对于数据库的死锁,一般数据库系统都会有一套机制去解锁,一般不会造成数据库的瘫痪,但解锁的过程会造成数据库性能的急速下降,反映到程序上就会造成程序的反应性能的下降,并 ......
SQL Server 几个好用的SQL语句
1、复制表
select * into desttable from srctable
将 srctable 完整地复制一份到 desttable 中,当然后面也可以加上条件来限定需要复制的记录
要求:desttable 必须为不存在的表名。
insert into desttable(column1, column2) select columna, columnb from sr ......