正文

软件测试---白盒测试指南(七)2007-06-27 12:48:00

【评论】 【打印】 【字体: 】 本文链接:http://blog.pfan.cn/lym51/27152.html

分享到:

8.1). SQL语句规范:(详见数据库处理规范)

序号

测试项

测试内容

质量保证标准

问题属性

出错频率

S1

书写规范

语句全部用小写

 

 

 

S2

SQL语法

l          禁止使用“select  *  from ”语法。

l          禁止使用“insert into table_name values(?,?,……)”语法,

l          统一使用“insert into table_name (col1,col2,……) values(?,?,…...)”

 

 

 

S3

SQL语法

如果在语句中有not inin)操作,是否考虑用not existsexists)来重写。

 

 

 

S4

类型转换

避免显式或隐含的类型转换。例如在where子句中numeric 型和int型的列的比较

 

 

 

S5

 

SQL语句含有运算符时,运算符需与其他字符串用空格区分。否则容易导致以下类似问题。在语句select a–b from table 中, ab均为变量。拼写该语句时,如果a=6 b= -3,则语句变为select 6--3 from table--变为Sql的注释,语句报错

 

 

 

S6

查询优化

为提高索引的效率,查询路径优化(尤其是要尽力减少查询嵌套)。

 

 

 

S7

视图

使用静态视图,不允许动态创建视图,索引,存储过程等数据库对象

 

 

 

S8

Null

不能将Null   空串“”视为相同

 

 

 

S9

多表连接

1.SQL语句包含多表连接时,是否加上表的别名。

1.   子查询问题。对于能用连接方式或者视图方式实现的功能,不要用子查询。

例如:select name from customer where customer_id in ( select customer_id from order where money>1000)。应该用如下语句代替:select name from customer inner join order on customer.customer_id=order.customer_id where order.money>100

3. 多表关联查询时,写法必须遵循以下原则,这样做有利于建立索引,提高查询效率。格式如下select sumtable1.je from table1 table1,  table2 table2,  table3  table3 where (table1的等值条件(=) and (table1的非等值条件) and (table2table1的关联条件) and (table2的等值条件) and (table2的非等值条件) and (table3table2的关联条件) and (table3的等值条件) and (table3的非等值条件)

 

 

 

S10

复杂SQL语句

对复杂SQL语句必须单独测试:如多表查询拚写语句是否符合业务要求

 

 

 

S11

多数据库适配

1.Sql语句转换类。调用方法:SqlTranslator trans = new SqlTranslator(); destSql = trans.getSql(sourceSql, databaseType)

2.提供SQLException信息转换。同一个SQL在不同数据库操作,JDBC返回的错误号以及错误信息不同。SQLException信息转换器将不同JDBC返回的错误号统一为以Sql Server7.0为准,错误信息仍以不同JDBC返回的错误信息为主

 

 

 

S11

多数据库适配

3SQL语法限制

(1)  字符串连接必须用“||”符号。例如: select f1 || f2 from test:而不是: select f1 + f2   from test 如果用“+”号,则Oracle不支持。

(2)  左连接的写法必须带“outer”关键字。例如:select f1 from t1 left outer t2 on t1.f1 = t2.f1;而不是: select f1 from t1 left t2 on t1.f1 = t2.f1

(3)  参与左连接的列不能为常量例如,不允许如下语句: select * from t1 left outer join t2 on t1.f1='A'

(4)  Case when语句中只能出现 =>=<= 以及is null运算符,不能出现 <> <>!=、以及is not null运算符。 否则在Oracledecode函数无法表达。

(5)  Case when语句中参与比较的列只能有一个。例如不能使用如下

         case……when语句:case  when f1 > 1 then …...when f2 > 1 then ……end

(6)  在对char类型比较时,要对列加上rtrim()函数,否则在Oracle中不会得到正确结果。

(7)  DeleteUpdateInsertSelect语句中char类型的数值引用使用单引,

         例如语句:Insert into t vlaues(“book”,5)SQL Server中可以使用,而在OracleDB2中不支持。应为:Insert into t vlaues(‘book’,5)

(8)  通配符不能使用‘[a-c]%’这种形式,应写成如:select * from table_name where col1 like ‘[a]%’ OR col1 like ‘[b]%’ OR col1 like ‘[c]%’

(9)  不能通过来top n/percent限制查询结果集的记录数,oracle不支持

(10)              Unionorder byGroup byhavingbetween…andinexistsis null 用法一致

 

 

 

S12

函数

不允许动态创建函数。

 

 

 

阅读(2858) | 评论(0)


版权声明:编程爱好者网站为此博客服务提供商,如本文牵涉到版权问题,编程爱好者网站不承担相关责任,如有版权问题请直接与本文作者联系解决。谢谢!

评论

暂无评论
您需要登录后才能评论,请 登录 或者 注册