简体   繁体   English

在mysql中创建表时出错

[英]Error in creating table in mysql

CREATE TABLE test(ID_NO INT NOT NULL AUTO_INCREMENT, 
    Account varchar(20)NOT NULL, 
    Day DATE NOT NULL, 
    Customer BIGINT(20) NOT NULL, 
    Clicks INT(10) NOT NULL,
    Impression INT(20) NOT NULL, 
    CTR FLOAT(10) NOT NULL, 
    Avg. CPC FLOAT(10) NOT NULL, 
    Cost FLOAT(10) NOT NULL, 
    Avg. position FLOAT(10) NOT NULL, 
    Converted clicks INT(10) NOT NULL, 
    Conversions INT(10) NOT NULL,
    Conv. rate FLOAT(10) NOT NULL,
    PRIMARY KEY(ID_NO)
);

ERROR 1103 (42000): Incorrect table name 'Avg'错误 1103 (42000):不正确的表名 'Avg'

Please try below query :请尝试以下查询:

CREATE TABLE test
(ID_NO INT NOT NULL AUTO_INCREMENT, 
Account varchar(20)NOT NULL, 
Day DATE NOT NULL,
Customer BIGINT(20) NOT NULL,  
Impression INT(20) NOT NULL, 
CTR FLOAT(10) NOT NULL, 
CPC FLOAT(10) NOT NULL, 
Cost FLOAT(10) NOT NULL,  
position FLOAT(10) NOT NULL, 
clicks INT(10) NOT NULL, 
Conversions INT(10) NOT NULL,
rate FLOAT(10) NOT NULL, 
PRIMARY KEY(ID_NO));
mysql> CREATE TABLE test(ID_NO INT NOT NULL AUTO_INCREMENT PRIMARY KEY, 
Account varchar(20)NOT NULL, 
Day DATE NOT NULL, 
Customer BIGINT(20) NOT NULL, 
Clicks INT(10) NOT NULL,
Impression INT(20) NOT NULL, 
CTR FLOAT(10) NOT NULL, 
Avg_CPC FLOAT(10) NOT NULL, 
Cost FLOAT(10) NOT NULL, 
Avg_position FLOAT(10) NOT NULL, 
Converted clicks INT(10) NOT NULL, 
Conversions INT(10) NOT NULL,
Conv_rate FLOAT(10) NOT NULL
);                              

There are multiple problems with your query.您的查询存在多个问题。

  • You cannot use dots in the names (or identifiers as MySQL calls them)您不能在名称中使用点(或 MySQL 所称的标识符)
  • You cannot use spaces in identifiers您不能在标识符中使用空格
  • It is better to use underscored names rather, and avoid using the upper case in identifiers, since MySQL is not case sensitive.最好使用带下划线的名称,并避免在标识符中使用大写,因为 MySQL 不区分大小写。

The final code comes to be:最终代码变成了:

CREATE TABLE test(
    id_no INT NOT NULL AUTO_INCREMENT, 
    account varchar(20)NOT NULL, 
    day DATE NOT NULL, 
    customer BIGINT(20) NOT NULL, 
    clicks INT(10) NOT NULL,
    impression INT(20) NOT NULL, 
    ctr FLOAT(10) NOT NULL, 
    avg_cpc FLOAT(10) NOT NULL, # there was a dot in the name
    cost FLOAT(10) NOT NULL, 
    avg_position FLOAT(10) NOT NULL, # there was a dot in the name
    converted_clicks INT(10) NOT NULL, # there was an extra space
    conversions INT(10) NOT NULL,
    conv_rate FLOAT(10) NOT NULL, # there was a dot in the name
    PRIMARY KEY(ID_NO)
);

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

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