MySQL SQL 创建表错误
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4639788/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
SQL CREATE TABLE Error
提问by Adam M-W
The Answer was that I was using incorrect quotation marks instead of backticks. Stupid syntax hilighter tricked me.
答案是我使用了不正确的引号而不是反引号。愚蠢的语法高亮器欺骗了我。
I've been stuck on this one simple(ish) thing for the last 1/2 hour so I thought I might try to get a quick answer here.
在过去的 1/2 小时里,我一直在做这件简单(ish)的事情,所以我想我可能会尝试在这里快速得到答案。
What exactly is incorrect about my SQL syntax, assuming I'm using mysql 5.1
假设我使用的是 mysql 5.1,我的 SQL 语法到底有什么不正确
CREATE TABLE 'users' (
'id' INT(11) UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
'username' VARCHAR(20) NOT NULL,
'password' VARCHAR(40) NOT NULL,
'salt' VARCHAR(40) DEFAULT NULL,
'email' VARCHAR(80) NOT NULL,
'created_on' INT(11) UNSIGNED NOT NULL,
'last_login' INT(11) UNSIGNED DEFAULT NULL,
'active' TINYINT(1) UNSIGNED DEFAULT NULL,
)
ENGINE InnoDB;
The error I get is:
我得到的错误是:
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 ''users';
CREATE TABLE 'users' (
'id' INT(11) UNSIGNED NOT NULL AUTO_INCREMENT,' at line 3
Elapsed Time: 0 hr, 0 min, 0 sec, 0 ms.
Also, does anyone have any good tutorials about how to use Zend_Auth for complete noobs?
另外,有没有人有关于如何将 Zend_Auth 用于完整的新手的任何好的教程?
Thanks.
谢谢。
采纳答案by jasonbar
Table and column identifiers are quoted using backticks (or double quotes if you've configured them).
表和列标识符使用反引号(或双引号,如果您已配置它们)引用。
Additionally you have a comma at the end of your column list.
此外,您的列列表末尾有一个逗号。
CREATE TABLE `users` (
`id` MEDIUMINT( 8 ) UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
`username` VARCHAR( 20 ) NOT NULL,
`password` VARCHAR( 40 ) NOT NULL,
`salt` VARCHAR( 40 ) DEFAULT NULL,
`email` VARCHAR( 80 ) NOT NULL,
`created_on` INT( 11 ) UNSIGNED NOT NULL,
`last_login` INT( 11 ) UNSIGNED DEFAULT NULL,
`active` TINYINT( 1 ) UNSIGNED DEFAULT NULL
) ENGINE InnoDB
回答by BoltClock
You are using single quotes instead of backticks for your table and field names, which is wrong. There should also be an equals sign between ENGINE
and InnoDB
.
您对表和字段名称使用单引号而不是反引号,这是错误的。ENGINE
和之间也应该有一个等号InnoDB
。
Here's the fixed SQL:
这是固定的 SQL:
CREATE TABLE `users` (
`id` MEDIUMINT(8) UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
`username` VARCHAR(20) NOT NULL,
`password` VARCHAR(40) NOT NULL,
`salt` VARCHAR(40) DEFAULT NULL,
`email` VARCHAR(80) NOT NULL,
`created_on` INT(11) UNSIGNED NOT NULL,
`last_login` INT(11) UNSIGNED DEFAULT NULL,
`active` TINYINT(1) UNSIGNED DEFAULT NULL
)
ENGINE = InnoDB;