我使用MySQL 5.0+,如果表不存在,我试图执行一个大的命令列表。所以我想有:
I am using MySQL 5.0+ and I am trying to execute a big list of commands if a table does not exist. So I would like to have:
if not exist table then 10000 line query that creates and populates the table with a lot of entries. end if唯一的问题是我一直在搜索,
The only problem is that I have been searching and so far I found out that MySQL does not support such a feature.
目前我有:
IF NOT EXISTS `profiles` THEN A LOT OF QUERIES; END IF;由于某种原因,它继续给我错误,说第1行语法错误。
For some reason it keeps on giving me error saying syntax is wrong on line 1.
所以我想知道是否有人会有一个更好的想法,如何去处理这个问题,或如何解决它。
So I was wondering if anyone would happen to have a better idea as to how go about approaching this problem, or how to fix it.
推荐答案添加到bfavaretto的代码,如果你有information_schema.tables,尝试这样:
Addding on to code from bfavaretto, if you do have information_schema.tables, try something like this:
IF NOT EXISTS (SELECT * FROM information_schema.tables WHERE table_schema = 'databasename' AND table_name = 'tablename') do your big long create table stuff更多推荐
如果表不存在执行一个长查询
发布评论