简体   繁体   English

mysql:仅当表存在时才更改表名

[英]mysql: alter tablename only if table exists

I tried writing query using exists , but no success so far.我尝试使用exists编写查询,但到目前为止没有成功。 Searching hasn't helped so far.到目前为止,搜索没有帮助。

If you attempt to alter a table that does not exist, the query will fail with an error: Table 'database.table' doesn't exist如果您尝试更改不存在的表,查询将失败并出现错误: Table 'database.table' doesn't exist

MySQL does support ALTER IGNORE TABLE , but that only turns errors into warnings if you're attempting to create a unique index while there are values in the table that violate that index. MySQL 确实支持ALTER IGNORE TABLE ,但是如果您尝试创建唯一索引而表中存在违反该索引的值,则只会将错误变成警告。

If you would like to make sure that you do not produce any database queries , I would suggest ensuring the table's existence using SHOW TABLES LIKE 'tablename' before running your ALTER TABLE query.如果您想确保不产生任何数据库查询,我建议在运行ALTER TABLE查询之前使用SHOW TABLES LIKE 'tablename'确保表的存在。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM