Do mysql support something like this?
mysql支持这样的东西吗?
INSERT INTO `table` VALUES (NULL,"1234") IF TABLE EXISTS `table` ELSE CREATE TABLE `table` (id INT(10), word VARCHAR(500));
3 个解决方案
#1
5
I'd create 2 statements. Try this:
我创建了2个语句。尝试这个:
CREATE TABLE IF NOT EXISTS `table` (
id INT(10),
word VARCHAR(500)
);
INSERT INTO `table` VALUES (NULL,"1234");
#2
1
You can first check if the table exists, if it doesn't then you can create it. Do the insert statement after this..
您可以先检查表是否存在,如果不存在,则可以创建表。这之后做插入语句..
http://dev.mysql.com/doc/refman/5.1/en/create-table.html
http://dev.mysql.com/doc/refman/5.1/en/create-table.html
Something like
就像是
CREATE TABLE IF NOT EXISTS table (...)
INSERT INTO table VALUES (...)
Note:
注意:
However, there is no verification that the existing table has a structure identical to that indicated by the CREATE TABLE statement.
但是,没有验证现有表的结构与CREATE TABLE语句指示的结构相同。
#3
0
MySQL doesn't support creating a table in the SELECT
statement, but you can easily preface with a quick check to create your table if it doesn't exist:
MySQL不支持在SELECT语句中创建表,但如果表不存在,您可以通过快速检查来创建表:
CREATE TABLE IF NOT EXISTS `table` (
id INT(10),
word VARCHAR(500)
);
#1
5
I'd create 2 statements. Try this:
我创建了2个语句。尝试这个:
CREATE TABLE IF NOT EXISTS `table` (
id INT(10),
word VARCHAR(500)
);
INSERT INTO `table` VALUES (NULL,"1234");
#2
1
You can first check if the table exists, if it doesn't then you can create it. Do the insert statement after this..
您可以先检查表是否存在,如果不存在,则可以创建表。这之后做插入语句..
http://dev.mysql.com/doc/refman/5.1/en/create-table.html
http://dev.mysql.com/doc/refman/5.1/en/create-table.html
Something like
就像是
CREATE TABLE IF NOT EXISTS table (...)
INSERT INTO table VALUES (...)
Note:
注意:
However, there is no verification that the existing table has a structure identical to that indicated by the CREATE TABLE statement.
但是,没有验证现有表的结构与CREATE TABLE语句指示的结构相同。
#3
0
MySQL doesn't support creating a table in the SELECT
statement, but you can easily preface with a quick check to create your table if it doesn't exist:
MySQL不支持在SELECT语句中创建表,但如果表不存在,您可以通过快速检查来创建表:
CREATE TABLE IF NOT EXISTS `table` (
id INT(10),
word VARCHAR(500)
);