MySQL查询语法错误,哪里出了问题
我在这里疯了...我是一个 SQL 初学者..但我一生都看不出我的语句有什么问题:
CREATE TABLE usage
(id BIGINT AUTO_INCREMENT
, use_date datetime
, ctn VARCHAR(255)
, destination VARCHAR(255)
, cost_type BIGINT
, cost BIGINT
, up_data bigint
, down_data bigint
, INDEX cost_type_idx (cost_type)
, PRIMARY KEY(id) ) ENGINE = INNODB;
这是 MySQL 抛出的错误(版本 5.5.8)
SQLSTATE[42000]:语法错误或访问冲突:1064 您的 SQL 语法有错误;检查与您的 MySQL 服务器版本相对应的手册,了解在第 1 行的“usage (id BIGINT AUTO_INCRMENT, use_date datetime, ctn VARCHAR(255), destinatio”附近使用的正确语法。失败的查询:“CREATE TABLE use (id BIGINT AUTO_INCRMENT) 、 use_date datetime、ctn VARCHAR(255)、destination VARCHAR(255)、cost_type BIGINT、cost BIGINT、up_data bigint、down_data bigint、INDEX cost_type_idx (cost_type)、PRIMARY KEY(id)) ENGINE = INNODB"。查询失败:CREATE TABLE用法(id BIGINT AUTO_INCRMENT、use_date 日期时间、ctn VARCHAR(255)、目标 VARCHAR(255)、cost_type BIGINT、cost BIGINT、up_data bigint、down_data bigint、INDEX cost_type_idx (cost_type)、PRIMARY KEY(id)) ENGINE = INNODB
它说near
然后给我大约 30 个字符!
我尝试了不同的列名称,以防我使用不同的数据类型 - 仍然没有运气,
我确信这是非常明显的 !对那些 10 分钟内没有撕扯头发的人不起作用 - 有人请让我摆脱痛苦!
I am going out of my mind here ... I am an SQL beginner .. but I cannot for the life of me see what is wrong with my statement :
CREATE TABLE usage
(id BIGINT AUTO_INCREMENT
, use_date datetime
, ctn VARCHAR(255)
, destination VARCHAR(255)
, cost_type BIGINT
, cost BIGINT
, up_data bigint
, down_data bigint
, INDEX cost_type_idx (cost_type)
, PRIMARY KEY(id) ) ENGINE = INNODB;
Here is the error thrown by MySQL (Version 5.5.8)
SQLSTATE[42000]: Syntax error or access violation: 1064 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 'usage (id BIGINT AUTO_INCREMENT, use_date datetime, ctn VARCHAR(255), destinatio' at line 1. Failing Query: "CREATE TABLE usage (id BIGINT AUTO_INCREMENT, use_date datetime, ctn VARCHAR(255), destination VARCHAR(255), cost_type BIGINT, cost BIGINT, up_data bigint, down_data bigint, INDEX cost_type_idx (cost_type), PRIMARY KEY(id)) ENGINE = INNODB". Failing Query: CREATE TABLE usage (id BIGINT AUTO_INCREMENT, use_date datetime, ctn VARCHAR(255), destination VARCHAR(255), cost_type BIGINT, cost BIGINT, up_data bigint, down_data bigint, INDEX cost_type_idx (cost_type), PRIMARY KEY(id)) ENGINE = INNODB
It says near
and then gives me about 30 characters !
I have tried different column names, in case I am using a keyword. I have tried different DataTypes - still no luck !
I'm sure it's very obvious why it's not working to someone who hasn't been tearing their hair out for 10 minutes - someone please put me out of my misery !
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
出现该错误是因为
USAGE
是 mysql 中的保留字。请参阅: http://dev.mysql.com/doc/refman /5.5/en/reserved-words.html 获取保留字列表。
另外,虽然它确实为您提供了查询的很大一部分,但最重要的是第一部分......它说
接近“使用”
,所以这通常是它遇到的问题。That error appears because
USAGE
is a reserved word in mysql.See: http://dev.mysql.com/doc/refman/5.5/en/reserved-words.html for a list of reserved words.
Also, while it did give you a big part of the query, it's the first part that is most important... It said
near 'usage
so that is usually what it had an issue with.