SQL使用小结
1. 如果你希望使用selcet top语句,并且还要附带where条件,那么条件中的列就得是合适的索引,如聚集索引、复合索引里的主列
等,同时,where条件里也要尽量避开使用函数,or,判断NULL等会引起全部扫描的语句,不然执行的是全表扫描。
2. 通过设置STATISTICS我们可以查看执行SQL时的执行效率以及相关性能测试。选项有PROFILE,IO ,TIME。
例:SET STATISTICS PROFILE ON
SET STATISTICS IO ON
SET STATISTICS TIME ON
GO /*--你的SQL脚本开始*/
SELECT * from [TableName]
GO /*--你的SQL脚本结束*/
SET STATISTICS PROFILE OFF
SET STATISTICS IO OFF
SET STATISTICS TIME OFF
相关文档:
select case when b.name is null and c.name is null then '合计' when b.name is null and c.name is not null then '小计' else b.name end as mtrname,
sum(a.number),c.name as cname from x_sell a join x_material b on a.mtr=b.fid join p_organi c on c.fid=a.customer
where a.stime>'2009-10-01'
GROUP B ......
create table [表名]
(
[自动编号字段] int IDENTITY (1,1) PRIMARY KEY ,
[字段1] nVarChar(50) default '默认值' null ,
[字段2] ntext null ,
[字段3] datetime,
[字段4] money null ,
[字段5] int default 0,
[字段6] Decimal (12,4) default 0,
[字段7] image null ,
)
删除表:
Drop t ......
select case when c.colid=1 then object_name(c.id) else '' end as 表名
,c.name as 字段名
,t.name 数据类型
,c.prec as 长度 ......
如果一个 SQL 语句发生了错误,那么 sqlca.sqlcode 将是非零值。
如果 sqlca.sqlcode 小于 0 那么就是发生了某种严重的错误,象数据库定义与查询定义不一致等.
如果大于 0 则是通常的错误,象表不包括所要求的行等.
sqlca.sqlcode == 0,成功
sqlca.sqlcode == -1 失败 (获取具体失败信息 ......