如果表不存在执行一个长查询

编程入门 行业动态 更新时间:2024-10-27 15:24:45
本文介绍了如果表不存在执行一个长查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我使用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

更多推荐

如果表不存在执行一个长查询

本文发布于:2023-10-28 18:49:48,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1537472.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:不存在

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!