“创建表如果不存在” - 如何检查模式,太? [英] "Create table if not exists" - how to check the schema, too?

查看:128
本文介绍了“创建表如果不存在” - 如何检查模式,太?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有(或多或少)标准方法来检查不仅是 mytable 的表是否存在,而且它的模式是否类似它应该是什么?我正在尝试 H2数据库

Is there a (more or less) standard way to check not only whether a table named mytable exists, but also whether its schema is similar to what it should be? I'm experimenting with H2 database, and

CREATE TABLE IF NOT EXISTS mytable (....)

语句显然只检查表的名称

statements apparently only check for the table´s name. I would expect to get an exception if there's a table with the given name, but different schema.

推荐答案

SELECT  *
FROM    INFORMATION_SCHEMA.TABLES
WHERE   TABLE_NAME      = 'TableName'
    AND TABLE_SCHEMA    = 'public'

这篇关于“创建表如果不存在” - 如何检查模式,太?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆