PHP-自动生成 MySQL 创建 Table 语句 returns 错误
PHP-autogenerated MySQL Create Table statement returns error
mysql> CREATE TABLE metadata
(
id int,
created_by int,
modified_by int,
deleted_by int,
created_at datetime,
modified_at datetime,
deleted_at datetime,
key varchar(45),
definition_type varchar(1),
metadata_type varchar(1),
no_of_decimals int,
is_required tinyint,
min_range decimal,
max_range decimal,
entity varchar(10),
sequence int,
meta_group varchar(2),
PRIMARY KEY (id) );
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'varchar(45), definition_type varchar(1), metadata_type varchar(1), no_of_decimal' at line 1
我不太确定如何更正此错误,因为此类问题通常不会在网上提供具体答案。我该如何解决这个错误?
key
是保留字,在MySQL:
中用反引号`
转义
`key` varchar(45)
mysql> CREATE TABLE metadata
(
id int,
created_by int,
modified_by int,
deleted_by int,
created_at datetime,
modified_at datetime,
deleted_at datetime,
key varchar(45),
definition_type varchar(1),
metadata_type varchar(1),
no_of_decimals int,
is_required tinyint,
min_range decimal,
max_range decimal,
entity varchar(10),
sequence int,
meta_group varchar(2),
PRIMARY KEY (id) );
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'varchar(45), definition_type varchar(1), metadata_type varchar(1), no_of_decimal' at line 1
我不太确定如何更正此错误,因为此类问题通常不会在网上提供具体答案。我该如何解决这个错误?
key
是保留字,在MySQL:
`
转义
`key` varchar(45)