You need to enable JavaScript to run this app.
文档中心
ByteHouse 企业版

ByteHouse 企业版

复制全文
下载 pdf
DDL
EXISTS语句(EXISTS)
复制全文
下载 pdf
EXISTS语句(EXISTS)

使用 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;
最近更新时间:2025.08.14 10:17:09
这个页面对您有帮助吗?
有用
有用
无用
无用