當前位置:成語大全網 - 新華字典 - sql裏判斷表存在不存在的語句

sql裏判斷表存在不存在的語句

使用exists判斷。

以Oracle為示例:

exists(select 1 from all_tables u where 條件壹:限制用戶名 and 條件二:限制表名)

查詢系統字典表all_tables,判斷表是否存在,存在則結果為真;不存在則結果為假

通過結合if語句使用:

if exists(select 1 from all_tables u where 條件壹:限制用戶名 and 條件二:限制表名) then 執行子句壹

else 執行子句二;