在mysql中创建新表时出错

时间:2023-01-19 18:42:03

Im creating a table in SQL but Im getting the error...

我在SQL中创建一个表但我得到错误...

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 ' pub_name VARCHAR, pub_city VARCHAR, country ' at line 2

CREATE TABLE  publisher(  
'pub_id'      varchar(8),  
'pub_name'        varchar(50),  
'pub_city'        varchar(25),  
'country'         varchar(25),  
'country_office'  varchar(25)  
'no_of_branch'    int(3),  
'estd'           date);  

3 个解决方案

#1


1  

You forgot a , after the 'country_office' line.

你忘记了'country_office'之后的行。

Btw, you should use reverse quotes : ` around each column name and not simple one !

顺便说一句,你应该使用反向引号:`围绕每个列名称而不是简单的名称!

CREATE TABLE publisher (  
`pub_id`          varchar(8),
`pub_name`        varchar(50),
`pub_city`        varchar(25),
`country`         varchar(25),
`country_office`  varchar(25),  <-
`no_of_branch`    int(3),
`estd`            date );

#2


0  

try this

CREATE TABLE  publisher(pub_id varchar(8), pub_name varchar(50),  
pub_city varchar(25), country varchar(25), country_office varchar(25) , no_of_branch  int(3), estd date);  

#3


0  

CREATE TABLE publisher
(  
`pub_id` varchar(8),  
`pub_name` varchar(50),  
`pub_city` varchar(25),  
`country` varchar(25),  
`country_office` varchar(25),  --The problem is here, You are missing a comma
`no_of_branch` int(3),
`estd` date
); 

Also you should use ` instead of '

你应该使用`而不是'

SQL FIDDLE

Thank for the Fiddle The Unlucky

感谢Fiddle The Unlucky

#1


1  

You forgot a , after the 'country_office' line.

你忘记了'country_office'之后的行。

Btw, you should use reverse quotes : ` around each column name and not simple one !

顺便说一句,你应该使用反向引号:`围绕每个列名称而不是简单的名称!

CREATE TABLE publisher (  
`pub_id`          varchar(8),
`pub_name`        varchar(50),
`pub_city`        varchar(25),
`country`         varchar(25),
`country_office`  varchar(25),  <-
`no_of_branch`    int(3),
`estd`            date );

#2


0  

try this

CREATE TABLE  publisher(pub_id varchar(8), pub_name varchar(50),  
pub_city varchar(25), country varchar(25), country_office varchar(25) , no_of_branch  int(3), estd date);  

#3


0  

CREATE TABLE publisher
(  
`pub_id` varchar(8),  
`pub_name` varchar(50),  
`pub_city` varchar(25),  
`country` varchar(25),  
`country_office` varchar(25),  --The problem is here, You are missing a comma
`no_of_branch` int(3),
`estd` date
); 

Also you should use ` instead of '

你应该使用`而不是'

SQL FIDDLE

Thank for the Fiddle The Unlucky

感谢Fiddle The Unlucky