sql 2005 强制使用执行计划 T—SQl
select * from tt t inner loop join ss s with(nolock) on s.c=t.c
使用 nested join
select * from tt t inner merge join ss s with(nolock) on s.c=t.c
使用 merge join
select * from tt t inner hash join ss s with(nolock) on s.c=t.c
使用 hash jion
nolock 不允许锁
Microsoft SQL Server sometimes uses hash and merge joins when querying large tables when uncomplicated nested loop joins would result in better performance and less server impact. In many such cases, query times go from many milliseconds to many seconds because hash table joins require that large amounts of data be processed and temporarily stored, and merge joins require sorting and then processing similarly large amounts of data.
This is fine for one-time administrative "fact finding" queries where you don't have or want the indices needed to optimize the query, and you're willing to wait the seconds or minutes it takes to get results.
For day-in-and-day-out application queries, however, you don't want your database engine to be hashing or sorting hundreds of thousands or millions of rows, especially when the end result is only a small number of rows.
相关文档:
我们知道用powerdesigner导出的sql文件后缀为'.sql';用phpmyadmin很容易导入MysQL数据库,但是用PHP怎么导入数据库呢?
我用powerdesigner设计一个数据库后导出sql文件(一个投票系统)为'vote.sql';
文件内容为(一些sql语句和注释):
/*======================= ......
事务就是负责把一系列操作看做一个独立的逻辑单元,这些操作要么同时成功,要么同时失败。下面是一个经典的例子:
create procedure TransferMoeny
(
@fromAccountNo varchar(50),-- 转出账号
@ToAccountNo varchar(50),--转入账号
& ......
昨天我说,用组合索引优化SQL,并不是最优的,这是因为在8亿的表上面有个等价的物化视图,这个物化视图可以代替我在之前在表上面建立的组合索引。
SQL> explain plan for SELECT distinct * from (select
2 (PROD_9005_GDF_WK_SS_FDIM.PROD_4_NAME),
3 PROD_9005_GDF_WK ......
SQL Server DATEDIFF() 函数
定义和用法
DATEDIFF() 函数返回两个日期之间的天数。
语法
DATEDIFF(datepart,startdate,enddate)
startdate 和 enddate 参数是合法的日期表达式。
datepart 参数可以是下列的值:
datepart缩写
年
yy, yyyy
季度
qq, q
月
mm, m
年中的日
dy, y
日
dd, d
周
wk, ww
星期
......