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)
Related
I am not able to find out what is the exact issue. When I remove index param from below mentioned query and try to insert the data it works fine, but trying to add index cause an error.
Here is my table schema:
CREATE TABLE IF NOT EXISTS `address_list` (
`email` varchar(100) NOT NULL,
`currency_name` varchar(50) NOT NULL,
`address` varchar(50) NOT NULL,
`label` varchar(100) NOT NULL,
`index` int DEFAULT 0,
`address_type` varchar(50) NOT NULL,
`balance` varchar(500) DEFAULT "0.0",
`timestamp` TIMESTAMP default CURRENT_TIMESTAMP
)
and here is my insert query :
insert into address_list (email,currency_name,address,label,index,address_type) Values ('abc#gmail.com','bitcoin','mgbtUQt7ppCEhxWmvicxrbEDYSom5kNk8X','test address',3,'wallet');
error :
ERROR 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 'index) Values ('abc#gmail.com','bitcoin','mgbtUQt7ppCEhxWmvicxrbEDYSom5kNk8X'' at line 1
index is a reserved word in mysql; rename your column to something else, or else place it in backticks where you want to use it:
insert into address_list (email,currency_name,address,label,`index`,address_type) Values ('abc#gmail.com','bitcoin','mgbtUQt7ppCEhxWmvicxrbEDYSom5kNk8X','test address',3,'wallet');
See https://dev.mysql.com/doc/refman/8.0/en/keywords.html
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')
Table schema:
CREATE TABLE IF NOT EXISTS `movie` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`name` text NOT NULL,
`desc` text NOT NULL,
`review` text NOT NULL,
`image_url` text NOT NULL,
`promo_url` text NOT NULL,
`created_on` datetime NOT NULL,
`modified_on` datetime NOT NULL,
PRIMARY KEY (`id`)
)
Insert statement:
INSERT INTO movie (name, desc, review, image_url, promo_url, created_on, modified_on) VALUES ('?p0', '?p1', '?p2', '?p3', '?p4', '?p5', '?p6')
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 'desc, review, image_url, promo_url, created_on, modified_on) VALUES ('?p0', '?p1' at line 1
I am not able to figure out error source, can anyone please point it out?
desc is a reserved word. Either wrap it in ticks or change it to "description" or any other non-reserved name.
For me the code works. Perhaps the "desc" makes a problem (though you have it in backticks)?
DESC is a reserved word in MySQL.
You can still use it in the table definition, though. Just wrap it in backticks:
(name, `desc`, ...
INSERT INTO `comments`
( `id`, `pid`, `comment`, `user`, `date`, `active`)
VALUES
('23','3','Most Excellent! I am using it right now as you can see and would never even consider different shopping cart software... I''ve tried them all and found them lacking the freedom to do it my way ;)','Admin','2010-12-08 21:00:07','1');
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 ''Most Excellent! I am using it right now as you can see and would never even co' at line 1
It's got me baffled?! I replaced the single quote for "I've" and I still get the error
PHP 5.3.6
Mysql 5.5.10
DROP TABLE IF EXISTS `comments`;
CREATE TABLE `comments` (
`id` int(11) NOT NULL auto_increment,
`pid` int(11) NOT NULL,
`comment` varchar(255) NOT NULL,
`user` varchar(25) DEFAULT '0',
`date` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP,
`active` tinyint(1) NOT NULL DEFAULT '0',
PRIMARY KEY (id)
);
I can get the exact same error if I break the query this way:
INSERT INTO `comments` ( `id`, `pid`, `comment`, `user`, `date`, `active`) VALUES ('23','3','Most Excellent! I am using it right now as you can see and would never even co
(Tested on MySql 5.1.41.)
I guess the string which contains the query is being broken at position 179~180. Try inspect the query string in your PHP code right before the query execution.
This question already has an answer here:
Syntax error due to using a reserved word as a table or column name in MySQL
(1 answer)
Closed 8 years ago.
im tearing my hair out over this one. A query is throwing an 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 'FROM, SUBJECT, DATE, READ, MAIL ) VALUES ( 'EJackson', 'dfdf', '1270974101', 'fa' at line 1
I printed out the query to see what could be the problem:
INSERT INTO db.tablename ( FROM, SUBJECT, DATE, READ, MAIL ) VALUES ( 'EJackson', 'dfdf', '1270974299', 'false', 'dfdsfdsfd' )
and finaly the structure consists of:
CREATE TABLE db.tablename (
`ID` int(12) NOT NULL auto_increment,
`FROM` varchar(255) NOT NULL,
`SUBJECT` varchar(255) NOT NULL,
`DATE` varchar(255) NOT NULL,
`READ` varchar(255) NOT NULL,
`MAIL` varchar(255) NOT NULL,
PRIMARY KEY (`ID`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;
I can't find anything wrong. Any help would be much appreciated.
In the insert statement, "FROM" is a keyword in SQL so you need to enclose it in backquotes like you have in your create table statement.
So it'll be like:
INSERT INTO db.tablename (`FROM`, `SUBJECT`, `DATE`, `READ`, `MAIL` ) VALUES ( 'EJackson', 'dfdf', '1270974299', 'false', 'dfdsfdsfd' )
Isn't FROM a reserved word in MySQL?