简体   繁体   English

尝试在 phpMyAdmin 中创建表时出现“应有符号名称”错误

[英]“a symbol name was expected” error trying to create a table in phpMyAdmin

I am trying to create a table in a database in phpMyAdmin and I keep getting the "a symbol name was expected" error and I cannot figure out what is going on.我正在尝试在 phpMyAdmin 的数据库中创建一个表,但我不断收到“预期的符号名称”错误,我无法弄清楚发生了什么。 Is my syntax wrong?我的语法错了吗? I am new to this and I'm at a loss.我是新手,我很茫然。

创建表查询

You used ' ' sign in your column properties.您在列属性中使用了' '符号。 But mySQL allow you to use `` sign.但是mySQL允许你使用``符号。

CREATE TABLE IF NOT EXISTS `sales` (
        `id` int(11) NOT NULL AUTO_INCREMENT,
        `name` varchar(50) NOT NULL,
        `item` varchar(50) NOT NULL,
        `date` varchar(50) NOT NULL,
        `amount` int(11) NOT NULL,
        PRIMARY KEY (`id`)
    );

Column names, table names should be surrounded by backticks( `` )列名、表名用反引号( `` )包围

CREATE TABLE IF NOT EXISTS `sales` (
    `id` int(11) NOT NULL AUTO_INCREMENT,
    `name` varchar(50) NOT NULL,
    `item` varchar(50) NOT NULL,
    `date` varchar(50) NOT NULL,
    `amount` int(11) NOT NULL,
    PRIMARY KEY (`id`)
)

Or you can go without backticks as well:或者您也可以不使用反引号 go :

CREATE TABLE IF NOT EXISTS sales (
    id int(11) NOT NULL AUTO_INCREMENT,
    name varchar(50) NOT NULL,
    item varchar(50) NOT NULL,
   date varchar(50) NOT NULL,
   amount int(11) NOT NULL,
   PRIMARY KEY (id)
)

Your code is wrong, So here is the correct Code:你的代码是错误的,所以这里是正确的代码:

CREATE TABLE IF NOT EXISTS `sales` (
    `id` INT(11) NOT NULL AUTO_INCREMENT PRIMARY KEY,
    `name` VARCHAR(50) CHARACTER SET utf8 NOT NULL,
    `item` VARCHAR(50) CHARACTER SET utf8 NOT NULL,
    `date` VARCHAR(50) NOT NULL,
    `amount` int(11) NOT NULL
) 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM