在mysql中创建表时出错

时间:2015-11-03 06:32:32

标签: 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)
);

错误1103(42000):表名称'Avg'

不正确

3 个答案:

答案 0 :(得分:1)

请尝试以下查询:

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));

答案 1 :(得分:0)

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
);                              

答案 2 :(得分:0)

您的查询存在多个问题。

  • 您不能在名称中使用点(或MySQL称之为的标识符)
  • 您不能在标识符中使用空格
  • 最好使用下划线名称,并避免在标识符中使用大写,因为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, # 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)
);