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.
相关文档:
select t.OSUSER,t.STATUS,t.LOGON_TIME from v$session t
select t.OSUSER,t.STATUS,t.LOGON_TIME from v$session t where t.OSUSER='admin'
select t.OSUSER,t.STATUS,t.LOGON_TIME from v$session t where t.OSUSER='liuzhaoqing'
select t.OSUSER,t.STATUS,t.LOGON_TIME from v$session t where t.OSUSER='ymx'
sel ......
一般的公司通常会在他们的信息系统架构中引入多种数据库平台,同时引入三到四种不同的RDBMS解决方案的中大型公司也并不少见,当然这些公司里面的DBA们通常也需要同时拥有管理多种不同平台的技能了。
只在一种平台上展开工作的数据库专家们也通常会期待着在他们的下一份工作中能学到点不一样的东西,那些有勇气的人们则愿意 ......
SQL Server DATEDIFF() 函数
定义和用法
DATEDIFF() 函数返回两个日期之间的天数。
语法
DATEDIFF(datepart,startdate,enddate)
startdate 和 enddate 参数是合法的日期表达式。
datepart 参数可以是下列的值:
datepart缩写
年
yy, yyyy
季度
qq, q
月
mm, m
年中的日
dy, y
日
dd, d
周
wk, ww
星期
......
SQL UNION 操作符
UNION 操作符用于合并两个或多个 SELECT 语句的结果集。
请注意,UNION 内部的 SELECT 语句必须拥有相同数量的列。列也必须拥有相似的数据类型。同时,每条 SELECT 语句中的列的顺序必须相同。
SQL UNION 语法
SELECT column_name(s) from table_name1
UNION
SELECT column_name(s) from table_na ......