今年天拿論壇上一個問題,讓我更多瞭解一下SQL時間函數。
問題在大量數據的情況下 比較下面那個數據查詢語句的效率高
select id from table_a where table_a.id in (select table_b.id from table_b where table_a.id=table_b.id)
select table_a.id from Ttable_a,table_b where table_a.id=table_b.id
select table_a.id from table_a left outer join table_b on table_a.id=table_b.id
答:用查詢用的時間做對比
1.用MSSQL2000的數據查詢分析器
DECLARE @begin datetime
DECLARE @chaju int
DECLARE @end datetime
set @begin=getdate()
**********上面的三個select 語句之一 ********
set @end=getdate()
SELECT @chaju = datediff(Millisecond, @begin, @end)
print @chaju
@chaju 用時多少毫秒
-------------------------------------------------------------------------------------------------------------------------
2用SYBASE數據庫 SQL Advantage工具
DECLARE @begin_time datetime
SELECT @begin_time =getdate()
Select CONVERT(varchar(100), getdate(), 8)
**********上面的三個select 語句之一 ********
go
DECLARE @end_time datetime
SELECT @end_time =getdate()
Select CONVERT(varchar(100), getdate(), 8)
go
可以查出時間 只精確到秒。
大家有興趣的也可以參與進來,一起討論這個問題。