Raghul PR
Raghul PR

Reputation: 47

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'

Upvotes: 2

Views: 162

Answers (3)

Kaushik Maheta
Kaushik Maheta

Reputation: 1891

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

Upvotes: 0

Musa Haidari
Musa Haidari

Reputation: 2267

There are multiple problems with your query.

  • You cannot use dots in the names (or identifiers as MySQL calls them)
  • 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.

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

Upvotes: 0

Ashish Detroja
Ashish Detroja

Reputation: 1082

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

Upvotes: 1

Related Questions