You need to enable JavaScript to run this app.
导航
EXISTS语句(EXISTS)
最近更新时间:2025.08.14 10:17:09首次发布时间:2025.05.07 15:04:15
复制全文
我的收藏
有用
有用
无用
无用

使用 EXISTS 语句查询表或数据库是否存在。执行该语句后,返回一个单独的 UInt8类型的列,如果表或数据库不存在,则包含一个值 0,如果表在指定的数据库中存在,则包含一个值 1

语法

EXISTS [TEMPORARY] [TABLE|DICTIONARY] [db.]name

示例

-- 1. 创建数据库
CREATE DATABASE IF NOT EXISTS sample_db ON CLUSTER sample_cluster;

-- 2. 创建表
DROP TABLE IF EXISTS sample_db.sample_able ON CLUSTER sample_cluster;
CREATE TABLE IF NOT EXISTS sample_db.sample_able ON CLUSTER sample_cluster (
  id UInt32,
  name String DEFAULT '',
  CONSTRAINT constraint1 CHECK id > 10
)
ENGINE=MergeTree()
ORDER BY id;

-- 3. 查询表是否存在
exists table sample_db.sample_able;