MySQL建表错误??也许是版本问题?

发布于 2024-11-01 06:50:50 字数 1066 浏览 0 评论 0原文

我从 mysql_error() 得到以下信息:

您的 SQL 语法有错误;检查与您的 MySQL 服务器版本相对应的手册,了解在第 1 行附近 -->'assets' ('assetid' INT UNSIGNED NOT NULL AUTO_INCRMENT , PRIMARY KEY('assetid'<-- ) 使用的正确语法

我已经也尝试过这样的事情:

'assets' ('assetid' INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,

...但没有运气。

编辑:

实际上,我在放置之前已经尝试过不使用 (') 代码是动态的,但这些是示例。 :

CREATE TABLE 'assets' (
   'assetid' INT UNSIGNED NOT NULL AUTO_INCREMENT, 
    PRIMARY KEY('assetid'),
    'rfid' VARCHAR( 128 ) ,
    'createddate' DATE ,
    'modifieddate' DATE ,
    'curlocid' INT( 11 ) ,
    'type' VARCHAR( 128 ) ,
    'brand' VARCHAR( 128 ) ,
    'name' VARCHAR( 128 ) ,
    'condition' VARCHAR( 128 ) 
);

编辑2:

刚才我尝试用反引号(`)更改所有单引号(')..发生了其他错误..

无法创建表“mydb.assets”(错误号:121)

这是好还是坏?

编辑3:

我尝试使用不同的表名创建它,你猜怎么着?有用!天哪,为什么我不能创建表名“assets”?是不是因为之前的操作还有剩余??如果是的话我该如何清洁它?如果我说我通过删除表的文件来删除表怎么办??(frm,myd,myi)(由于懒惰而不是删除它)..我该如何修复它?

I am getting the following from the mysql_error():

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 -->'assets' ('assetid' INT UNSIGNED NOT NULL AUTO_INCREMENT , PRIMARY KEY('assetid'<-- at line 1

I've also tried something like this :

'assets' ('assetid' INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,

...but with no luck. The mysql version is 5.0.7.

EDIT:

Actually, I've tried it without (') first before putting it. The code is dynamic, but these are the examples:

CREATE TABLE 'assets' (
   'assetid' INT UNSIGNED NOT NULL AUTO_INCREMENT, 
    PRIMARY KEY('assetid'),
    'rfid' VARCHAR( 128 ) ,
    'createddate' DATE ,
    'modifieddate' DATE ,
    'curlocid' INT( 11 ) ,
    'type' VARCHAR( 128 ) ,
    'brand' VARCHAR( 128 ) ,
    'name' VARCHAR( 128 ) ,
    'condition' VARCHAR( 128 ) 
);

EDIT 2:

Just now I tried changing all the single quotes ( ' ) with back ticks ( ` ).. Other error occurred..

Can't create table 'mydb.assets' (errno: 121)

Is this better or worse?

EDIT 3:

I tried to create it using different table names and guess what? It works! Gosh, why can't I create table name 'assets'?? is it because there is some leftovers for previous operation?? if so how to I clean it?? what if i said that i delete the table by deleting it's file??(frm,myd,myi)(not drop it, due to laziness).. how do i fix it?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

南风几经秋 2024-11-08 06:50:50

查看您的所有代码将会很有帮助。

根据我所看到的,你需要消除所有这些蜱虫。这应该可行:

create table assets ( 
      assetid  int unsigned not null auto_increment primary key 
);

我在 MySQL Server 5.5 中运行得很好

It would be helpful to see all your code.

Bit based on what I'm seeing, you need to eliminate all those ticks. This should work:

create table assets ( 
      assetid  int unsigned not null auto_increment primary key 
);

I ran this fine in MySQL Server 5.5

扎心 2024-11-08 06:50:50

好吧,所以我不确定这里发生了什么,但是我复制并粘贴了你的代码并得到了同样的错误,所以我逐行复制仍然在它应该有的地方损坏,所以我逐行输入它不得不稍微摆弄一下但我得到了它,除了“条件”,它可能是一个保留字,但我缩短了它,这就是我得到的

create table assets ( 
     assetid  int unsigned not null auto_increment,
    primary key(assetid),
    rfid varchar(128),
    createddate DATE,
    modifieddate DATE,
    curlocid INT(11),
    type varchar(128),
    brand varchar(128),
    name varchar(128),
    cond varchar(128)
);

ok so I'm not sure what is going hon here but I copied and pasted your code and got the same error so I copied line by line still broke in places it should have so I typed it out line by line had to fiddle a bit but I got it then except "condition' which may be a reserved word but I shortend it heres what i got

create table assets ( 
     assetid  int unsigned not null auto_increment,
    primary key(assetid),
    rfid varchar(128),
    createddate DATE,
    modifieddate DATE,
    curlocid INT(11),
    type varchar(128),
    brand varchar(128),
    name varchar(128),
    cond varchar(128)
);
无可置疑 2024-11-08 06:50:50

我认为在引用表名或列名时需要使用反引号 (`) 而不是单引号 (')。

I think you need to use back ticks (`) instead of single quotes (') when quoting table or column names.

故笙诉离歌 2024-11-08 06:50:50

这个问题很老了,但我只想告诉如何解决这个问题的答案。万一有人偶然发现它。在这种情况下,它是使用的默认引擎。直到现在我才注意到,我正在使用的服务器(Z-WAMP)将 INNODB 配置为默认引擎。当我将其更改为 MyISAM(这是 mysql 的默认引擎)后,一切都运行良好!但是,感谢那些帮助我的人..

在这个文件中 --> my.cnf,更改这一行:

default-storage-engine=MyISAM

This question is old but I just going to tell the answer on how to resolve this. In case someone stumbled upon it.. In this case, it's the default ENGINE that is used. I haven't noticed it until now, that the server i'm using (Z-WAMP) configure INNODB as it's default engine. After I changed it to MyISAM, which is the default engine for mysql, everything works perfectly!! however, thanks for the guys who are helping me out..

In this file --> my.cnf, change this line:

default-storage-engine=MyISAM
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文