gbn*_*gbn 95
出于什么目的?
IF EXISTS (SELECT * FROM Table)...SELECT TOP 1 1 FROM Table返回零行或一行SELECT COUNT(*) FROM TableMon*_*ong 37
此外,您可以使用存在
select case when exists (select 1 from table)
then 'contains rows'
else 'doesnt contain rows'
end
Run Code Online (Sandbox Code Playgroud)
或检查特定记录是否有子行:
select * from Table t1
where exists(
select 1 from ChildTable t2
where t1.id = t2.parentid)
Run Code Online (Sandbox Code Playgroud)
或在程序中
if exists(select 1 from table)
begin
-- do stuff
end
Run Code Online (Sandbox Code Playgroud)
Pac*_*eco 11
像其他人说你可以使用类似的东西:
IF NOT EXISTS (SELECT 1 FROM Table)
BEGIN
--Do Something
END
ELSE
BEGIN
--Do Another Thing
END
Run Code Online (Sandbox Code Playgroud)