What's wrong with this MySQL query -- db won't accept? - mysql

I have the following MySQL query:
INSERT INTO 12:12:12:12:12(timestamp,niceTime,temperature,relative_humidity,wind_speed,gust_speed,rain_mm_per_hour,nsew,str,ip) VALUES(1361707978,'2013-02-24T12:12:58+00:00',0.0,0,0.0,0.0,0.0,0,'1010101010101010','0')
The name of the table is "12:12:12:12:12".
Here is the schema:
"CREATE TABLE IF NOT EXISTS `$mac` (
`timestamp` int(11) NOT NULL,
`niceTime` varchar(20) NOT NULL,
`temperature` float NOT NULL,
`relative_humidity` int(11) NOT NULL,
`wind_speed` float NOT NULL,
`gust_speed` float NOT NULL,
`rain_mm_per_hour` float NOT NULL,
`nsew` int(11) NOT NULL,
`str` varchar(1000) NOT NULL,
`ip` varchar(20) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;"
No matter what I do, I cannot get the query to be accepted ;(
Query failed: 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 '12:12:12:12:12(timestamp,niceTime,temperature,relative_humidity,wind_speed,gust_' at line 1
Many thanks in advance,

you will use backticks like that to your table name
12:12:12:12:12
try this
INSERT INTO `12:12:12:12:12`(timestamp,niceTime,temperature,relative_humidity,wind_speed,gust_speed,rain_mm_per_hour,nsew,str,ip) VALUES(1361707978,'2013-02-24T12:12:58+00:00',0.0,0,0.0,0.0,0.0,0,'1010101010101010','0'
EDIT.
Rules for naming objects, including tables in MySql:
http://dev.mysql.com/doc/refman/5.1/en/identifiers.html
Identifiers may begin with a digit but
unless quoted may not consist solely
of digits.
The identifier quote character is the backtick (“`”):

Use backticks around identifiers, especially when using such unconventional table names:
INSERT INTO `12:12:12:12:12`(timestamp,niceTime,temperature,relative_humidity,wind_speed,gust_speed,rain_mm_per_hour,nsew,str,ip)
VALUES(1361707978,'2013-02-24T12:12:58+00:00',0.0,0,0.0,0.0,0.0,0,'1010101010101010','0')

Related

MariaDB INSERT INTO FROM SELECT

Below is the block I am trying to execute, the documentation says this should work but instead I am met with an error that states "You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'INSERT INTO Location_Inventory_Column (Aisle, Name)
SELECT Aisle, Name ' at line 2"
~Any help would be highly appreciated!
START TRANSACTION
INSERT INTO Location_Inventory_Column (`Aisle`, `Name`)
SELECT `Aisle`, `Name` FROM TMPTableImport
Table Inserting Into:
CREATE TABLE `Location_Inventory_Column` (
`id` INT(11) NOT NULL AUTO_INCREMENT,
`Aisle` INT(11) NOT NULL DEFAULT 0,
`Name` VARCHAR(50) NOT NULL,
`Description` VARCHAR(50) NULL DEFAULT NULL,
`Disabled` INT(11) NULL DEFAULT NULL,
PRIMARY KEY (`id`)
)
TMPTable contains only Aisle and Name columns (See image)
TMPTABLE Image
As mentioned by #Akina the statement "START TRANSACTION" was the cause as it did not have a delimiter following the semicolon.
You must remove the single quotes in the Location_Inventory_Column (Aisle, Name) like this:
Location_Inventory_Column (Aisle, Name)

I obtain a error syntax when I exceute one query

I need to create table and I do this:
CREATE TABLE "home" (
"id" int(11) NOT NULL AUTO_INCREMENT,
"address" varchar(200) CHARACTER SET latin1 COLLATE latin1_general_ci NOT NULL,
PRIMARY KEY ("id")
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=latin1 COLLATE=latin1_bin;
when I execute this query I obtain this error:
Errore SQL [1064] [42000]: 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 '"causali" (
"id" int(11) NOT NULL AUTO_INCREMENT,
"address" va' at line 1
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 '"home" (
"id" int(11) NOT NULL AUTO_INCREMENT,
"adddress" va' at line 1
Anyone can help me?
MySQL does not like double quotes on the table / column / alias names, until we enable ANSI_QUOTES mode.
Treat " as an identifier quote character (like the ` quote character)
and not as a string quote character. You can still use backticks to quote
identifiers with this mode enabled. With ANSI_QUOTES enabled, you
cannot use double quotation marks to quote literal strings because
they are interpreted as identifiers.
This mode is by default Disabled. Now, you can either use backticks around them, or use without double quotes (except when it is a Reserved keyword, then you will have to use backticks around it).
CREATE TABLE home (
id int(11) NOT NULL AUTO_INCREMENT,
address varchar(200) CHARACTER SET latin1 COLLATE latin1_general_ci NOT NULL,
PRIMARY KEY (id)
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=latin1 COLLATE=latin1_bin;

SQL query syntax error while creating a table

I am getting a SQL query syntax error while creating a table. Here is the SQL query:
CREATE TABLE ACCOUNT (
ACCNO NUMBER(5) NOT NULL,
NAME VARCHAR(20) NOT NULL,
BA L NUMBER(8,2) NOT NULL,
CREATION-DT DATE NOT NULL,
PRIMARY KEY ( ACCNO )
);
Here is the error:
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 'NUMBER(5) NOT NULL.
What is wrong with my syntax?
Using SQLfiddle you can see this is not valid.
You have multiple problems with your syntax; invalid data types, invalid column names, etc. You can encapsulate the invalid names in backticks but then you will have to remember to encapsulate them later.
Instead of Number you probably meant numeric but i would suggest trying Integer instead.
Or just try this:
CREATE TABLE ACCOUNT (
ACCNO INTEGER(5) NOT NULL,
NAME VARCHAR(20) NOT NULL,
BAL INTEGER(8) NOT NULL,
CREATIONDT DATE NOT NULL,
PRIMARY KEY ( ACCNO )
);
NUMBER is not a valid datatype in MySQL, you should choose the one from the list (maybe you've meant NUMERIC).
You should also escape some identifiers (in your case, column names BA L, which includes a space within it, and CREATION-DT, which includes a dash) with backticks ` in MySQL:
CREATE TABLE `ACCOUNT` (
`ACCNO` NUMERIC(5) NOT NULL,
`NAME` VARCHAR(20) NOT NULL,
`BA L` NUMERIC(8,2) NOT NULL,
`CREATION-DT` DATE NOT NULL,
PRIMARY KEY ( `ACCNO` )
);
SQLFiddle

MySql Error no 1064

My table format is
CREATE TABLE IF NOT EXISTS `clinicReg` (
`clinicRegId` varchar(10) NOT NULL,
`clinicName` varchar(20) NOT NULL,
`clinicAddress` varchar(500) NOT NULL,
`clinicContactNo` int(20) NOT NULL,
`clinicContactNO1` int(20) NOT NULL,
`clinicMobileNo` int(20) NOT NULL,
`clinicMobileNo1` int(20) NOT NULL,
`clinicCatagories` varchar(50) NOT NULL,
`clinicServices` varchar(500) NOT NULL,
`clinicLogo` longblob NOT NULL,
`ownerName` varchar(20) NOT NULL,
`clinicEmailId` varchar(20) NOT NULL,
`clinicEmailId1` varchar(20) NOT NULL,
`loginTimeStamp` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
PRIMARY KEY (`clinicRegId`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
my insert query is
insert into 'harshal.clinicreg' (clinicRegId,clinicName,
clinicAddress,clinicContactNo,clinicContactNO1,
clinicMobileNo,clinicMobileNo1,clinicCatagories,
clinicServices,clinicLogo,ownerName,clinicEmailId,
clinicEmailId1,loginTimeStamp)
Values
('ORCCli1','Smile Clinic','Mulund',
3456,544,234,567,'Gen','ABC',
load_file(C:\Users\harshal420\Pictures\Camera Roll\Capture.jpg),
'Smile','abc#xyz.com','def#pqr.com', CURDATE());
It is giving me error 1064 can any one help me???
Your INSERT statement has two issues that I can see upfront:
insert into 'harshal.clinicreg'
You have to wrap the db/table name with backticks, not single-quotes:
insert into `harshal`.`clinicreg`
After this, the load_file() function takes a string-input, but you're passing a literal. Try updating the full query to:
INSERT INTO `harshal`.`clinicreg`
(clinicRegId,clinicName, clinicAddress,clinicContactNo,clinicContactNO1,clinicMobileNo,clinicMobileNo1,clinicCatagories,clinicServices,clinicLogo,ownerName,clinicEmailId, clinicEmailId1,loginTimeStamp)
VALUES
('ORCCli1','Smile Clinic','Mulund', 3456,544,234,567,'Gen','ABC',
load_file('C:\\Users\\harshal420\\Pictures\\Camera Roll\\Capture.jpg'),
'Smile','abc#xyz.com','def#pqr.com', CURDATE()
);
You have 2 errors in your insert query.
1 -
Your table name is wrong it should be
insert into clinicReg
you can also put dbname.clinicReg
2- in your query load_file(C:\Users\harshal420\Pictures\Camera Roll\Capture.jpg)
this gives error
It is happening because you have an error in your SQL syntax. More specifically it is because you have used the incorrect quoting character when quoting your database/table name; you should be using backticks (`) or no quotes when specifying a database name, table name or field name.
You also need to quote the path to your data using single or double quotes. See my example below.
insert into `harshal`.`clinicreg` (clinicRegId,clinicName,clinicAddress,clinicContactNo,clinicContactNO1,clinicMobileNo,clinicMobileNo1,clinicCatagories,clinicServices,clinicLogo,ownerName,clinicEmailId,clinicEmailId1,loginTimeStamp) Values ('ORCCli1','Smile Clinic','Mulund',3456,544,234,567,'Gen','ABC',load_file('C:\Users\harshal420\Pictures\Camera Roll\Capture.jpg'),'Smile','abc#xyz.com','def#pqr.com', CURDATE());
You probably want to do
insert into `harshal`.`clinicreg` (...)
instead of
insert into 'harshal.clinicreg' (...)
In your example MySQL gets a string instead of table identifier which is what it excepts here.
You can also miss backticks here at all.
There also second syntax error in your query. You should quote path string passed to load_file function as parameter. Should be:
load_file('C:\Users\harshal420\Pictures\Camera Roll\Capture.jpg') ,

What am I missing? MySQL syntax error

I am having this error:
#1064 - 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 ''tablename'(
'id'MEDIUMINT NOT NULL AUTO_INCREMENT,
'content'TEXT NOT NULL,
'd' at line 1
From this statement:
CREATE TABLE 'tablename'(
'id'MEDIUMINT NOT NULL AUTO_INCREMENT,
'content'TEXT NOT NULL,
'date_added' DATETIME NOT NULL,
'user' VARCHAR (16) NOT NULL,
PRIMARY KEY ('id'),
UNIQUE ('id')
); ENGINE=MyISAM;
Why?
You need the backtick instead of the single quote ('). The backtick is this character:
`
Better yet - don't bother with either:
CREATE TABLE tablename (
id MEDIUMINT ...
Important: also see the comments below from tadman; they round out this answer nicely by explaining the backticks and pointing out another syntax issue.
You are using incorrect notation.
In your create table statement, you are using the single quote ( ').
You can't use that here for table names and column names.
Alternatives would be the tick mark (`). Or just completely remove all notation altogether.
Here is your code, fully functional:
CREATE TABLE tablename (
`id` MEDIUMINT NOT NULL,
`content`TEXT NOT NULL,
`date_added` DATETIME NOT NULL,
`user` VARCHAR (16) NOT NULL,
PRIMARY KEY (`id`),
UNIQUE (`id`)
);
You are missing a space between the columnname and the type of the first two columns. Also, you have a ; to many at the end
CREATE TABLE 'tablename'(
'id' MEDIUMINT NOT NULL AUTO_INCREMENT,
'content' TEXT NOT NULL,
'date_added' DATETIME NOT NULL,
'user' VARCHAR (16) NOT NULL,
PRIMARY KEY ('id'),
UNIQUE ('id')
) ENGINE=MyISAM;