Microsoft SQL Server 2005检查临时表是否为空

Kev*_*vin 2 sql-server temp-tables

是否有快速/有效的方法来检查表是否为空?

DECLARE @StartEndTimes TABLE
(
    id bigint,
    StartTime datetime,
    EndTime datetime
)

IF @StartEndTimes IS NOT NULL
Run Code Online (Sandbox Code Playgroud)

Ale*_* K. 8

而不是数数你可以;

if exists (select id from @StartEndTimes)
   set @has_stuff = 1
Run Code Online (Sandbox Code Playgroud)

一旦碰到一行就会返回.