Home > database >  Error #1064 MySQL Something is wrong in your syntax near '' accesslogh '
Error #1064 MySQL Something is wrong in your syntax near '' accesslogh '

Time:11-16

I got this MySQL error 1064:

# 1064 - Something is wrong in your syntax near '' accesslogh '(
id INT (30) PRIMARY KEY AUTO_INCREMENT NOT NULL,
nam ... 'on line 1

When i ran

CREATE TABLE 'accesslogh' (
id INT(30) PRIMARY KEY AUTO_INCREMENT NOT NULL, 
name VARCHAR(255), 
result VARCHAR(255), 
type VARCHAR(255), 
code VARCHAR(255), 
epoch INT(30), 
timestamp DATE DEFAULT CURRENT_TIMESTAMP);

I know it is a syntax error but I have tried to solve it following the correct theory but I can't solve it.

CodePudding user response:

Remove quotes around table name.

CREATE TABLE accesslogh (
id INT(30) PRIMARY KEY AUTO_INCREMENT NOT NULL, 
name VARCHAR(255), 
result VARCHAR(255), 
type VARCHAR(255), 
code VARCHAR(255), 
epoch INT(30), 
timestamp DATE DEFAULT CURRENT_TIMESTAMP);

CodePudding user response:

You are confusing the backtick ` with the single quote '. In SQL the single quote is used for string literals, in specifically MySQL the backtick is used to denote a quoted identifier, to allow you to use special characters, white space and reserved words for identifiers. What you probably intended to do was this:

CREATE TABLE `accesslogh` (
id INT(30) PRIMARY KEY AUTO_INCREMENT NOT NULL, 
name VARCHAR(255), 
result VARCHAR(255), 
type VARCHAR(255), 
code VARCHAR(255), 
epoch INT(30), 
timestamp DATE DEFAULT CURRENT_TIMESTAMP);

While it's not needed for your example it's a good practice to get into if your queries are going to be generated in some other code.


This really only applies to MySQL, other SQL DBMS tend to use square brackets [ ] to enclose identifiers that use reserved words or characters not otherwise allowed.

  • Related