Mysql 如果不存在,请按名称检查表
我想用mysql为敏捷数据库开发创建幂等脚本。如果您想了解它,请访问以下链接: 如果存在drop table,则此操作是错误的。我在找这样的东西:Mysql 如果不存在,请按名称检查表,mysql,Mysql,我想用mysql为敏捷数据库开发创建幂等脚本。如果您想了解它,请访问以下链接: 如果存在drop table,则此操作是错误的。我在找这样的东西: IF NOT EXISTS ( SELECT * FROM information_schema.tables WHERE table_schema = 'foo' AND table_name = 'customer' LIMIT 1; ) BEGIN CREATE TABLE customer(n
IF NOT EXISTS
(
SELECT *
FROM information_schema.tables
WHERE table_schema = 'foo'
AND table_name = 'customer'
LIMIT 1;
)
BEGIN
CREATE TABLE customer(n int);
END
如果有帮助,我正在寻找以下功能:
If Not exists something
then
statement1
statement2
...
statementN
else
do nothing
fi
请参见您应该能够在存储过程中执行此操作。无需存储过程;这是
CREATE TABLE
附带的一项基本功能。哦,请阅读手册!!这对我的要求不起作用。脚本需要是幂等的,但不行。这不是瓷器店里的牛。如果不存在,则执行N个步骤,而不仅仅是一个步骤。
CREATE TABLE IF NOT EXISTS customer
(n int);