Error on SQL insert statement - mysql

I exported a recordset from one database into a csv file, and when I try to import it into another using mysql workbench I keep this this error message:
Executing SQL script in server
ERROR: 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 ' 'Lord it Over', 'Ben', '1993-03-01', 'TRC', NULL, 1983, '1999-09-01', 'NULL', '' at line 1
INSERT INTO `TRC`.`horse`
(`horse_id`, `registered_name`, `stable_name`, `arrival_date`, `last_known_location`, `is_ex_racer`, `birth_year`, `death_date`, `horse_comments`, `sex`, `referral_date`, `horse_height`, `arrival_weight`, `passport_no`, `microchip_no`, `is_on_waiting_list`) VALUES
(, 'Lord it Over', 'Ben', '1993-03-01', 'TRC', NULL, 1983, '1999-09-01', 'NULL', 'NULL', 'NULL', NULL, NULL, 'NULL', 'NULL', 0)
SQL script execution finished: statements: 29 succeeded, 1 failed
Fetching back view definitions in final form.
Nothing to fetch
Any help would be appreciated as their appears to be no errors as far as I can see.

It's becaose of
VALUES starts with a comma.
You have missed horse_id. If it's Identity Column Then Remove horse_Id
Try like this (If horse_Id is identity)
INSERT INTO `TRC`.`horse`
(`registered_name`, `stable_name`, `arrival_date`, `last_known_location`, `is_ex_racer`, `birth_year`, `death_date`, `horse_comments`, `sex`, `referral_date`, `horse_height`, `arrival_weight`, `passport_no`, `microchip_no`, `is_on_waiting_list`) VALUES
('Lord it Over', 'Ben', '1993-03-01', 'TRC', NULL, 1983, '1999-09-01', 'NULL', 'NULL', 'NULL', NULL, NULL, 'NULL', 'NULL', 0)
Or (If Horse_id simple int then try this)
INSERT INTO `TRC`.`horse`
(`horse_id`, `registered_name`, `stable_name`, `arrival_date`, `last_known_location`, `is_ex_racer`, `birth_year`, `death_date`, `horse_comments`, `sex`, `referral_date`, `horse_height`, `arrival_weight`, `passport_no`, `microchip_no`, `is_on_waiting_list`) VALUES
('1','Lord it Over', 'Ben', '1993-03-01', 'TRC', NULL, 1983, '1999-09-01', 'NULL', 'NULL', 'NULL', NULL, NULL, 'NULL', 'NULL', 0)
^^^^ -- Here Horse_Id missing

it seems that you missing your "horse_id" value.
If that field was intended to be the Identity field, then you shouldn't mention that field on Insert Statement right?

If you want MySQL to generate an auto_increment ID for the horse_id field, you should either leave it out of the INSERT statement entirely, or specify NULL for the value in the VALUES list. You can't just leave that value empty in the list.

Your VALUES starts with a comma for some reason

Related

Error Code: 1064. Cannot insert data into database

The full error code is:
Error Code: 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 ''CPU', 'null', '0', '0', '0'")' at line 2
I'm trying to add product data from my PHP webpage, and getting this error. So I tried doing it manually on MySQL and I get the same error.
Here is a copy of the database and the code that I'm using to insert data:
INSERT INTO store_db.components (product_name, price, description, manufacturer, socket, date_added, type, form_factor, expansion_slots, sata_ports, capacity)
VALUES ('Intel Core i7 4790K','250',
'agsdfg sdfg sdfg sdfg sdfg ','Intel','LGA 1150',now()),
'CPU', 'null', '0', '0', '0'");
You have an extra parenthesis:
now()), 'CPU',
should be
now(), 'CPU',
You have a redundant ) after now(). Get rid of it and you should be OK:
INSERT INTO store_db.components (product_name, price, description, manufacturer, socket, date_added, type, form_factor, expansion_slots, sata_ports, capacity) VALUES ('Intel Core i7 4790K','250','agsdfg sdfg sdfg sdfg sdfg ','Intel','LGA 1150',now(), 'CPU', 'null', '0', '0', '0');

What is syntactically wrong with this ON DUPLICATE KEY UPDATE query?

Update: This issue was resolved in the comments and is awaiting an answer
When executing the following query in PyMySQL, I receive the error ‘1064, u"You have an error in your SQL syntax;’ (full error message below)
INSERT INTO `table_name` (`id`, `colName1`, `colName2`, `colName3`)
VALUES (820, 'string', 5, 'N')
ON DUPLICATE KEY UPDATE
`colName1`=VALUES(`colName1`),
`colName2`=VALUES(`colName2`),
`colName3`=VALUES(`colName3`)
-- Tried with and without ` surrounding column names after ON DUPLICATE KEY UPDATE
Syntax in Python:
sql = "INSERT INTO `table_name` (`id`, `colName1`, `colName2`, `colName3`) VALUES (820, 'string', 5, 'N') ON DUPLICATE KEY UPDATE `colName1`=VALUES(`colName1`),`colName2`=VALUES(`colName2`),`colName3`=VALUES(`colName3`)"
I received this error both when trying to update many rows (as suggested elsewhere, using the format of the accepted answer), and for one row at a time.
As noted in the comments, the stripped down example didn't produce an error (although it was not executed with Python). The following is the actual query. Let me know if other information is needed.
Query string executed in Python:
INSERT INTO `Listings` (`id`, `row_last_updated`, `maxBidCountPreRsvMet`, `maxBidPreRsvMet`, `minBidCountPostRsvMet`, `occupancy_status`, `waitingForHnb`, `ownItNow_price`, `high_bid`, `prop_id`, `hot_property`, `status`, `end_date`, `reserve_met`, `hours`, `backupBidSet`, `listing_type`, `low_bid`, `winning_bid`, `bids`, `days`, `high_bid_updated`, `minutes`, `lowBidIsOpt1`) VALUES (820, '2018-01-28 19:16:02', '5', '234000', None, 'N', None, 0, 234000, u'9007092665103', 'N', 'New', '2018-1-31-22-0', 'N', 7, 0, 'AUCN', 0, 0, 5, 3, '2018-01-28 14:16:02.001906', 44, 0) ON DUPLICATE KEY UPDATE `row_last_updated`=VALUES(`row_last_updated`),`maxBidCountPreRsvMet`=VALUES(`maxBidCountPreRsvMet`),`maxBidPreRsvMet`=VALUES(`maxBidPreRsvMet`),`minBidCountPostRsvMet`=VALUES(`minBidCountPostRsvMet`),`occupancy_status`=VALUES(`occupancy_status`),`waitingForHnb`=VALUES(`waitingForHnb`),`ownItNow_price`=VALUES(`ownItNow_price`),`high_bid`=VALUES(`high_bid`),`prop_id`=VALUES(`prop_id`),`hot_property`=VALUES(`hot_property`),`status`=VALUES(`status`),`end_date`=VALUES(`end_date`),`reserve_met`=VALUES(`reserve_met`),`hours`=VALUES(`hours`),`backupBidSet`=VALUES(`backupBidSet`),`listing_type`=VALUES(`listing_type`),`low_bid`=VALUES(`low_bid`),`winning_bid`=VALUES(`winning_bid`),`bids`=VALUES(`bids`),`days`=VALUES(`days`),`high_bid_updated`=VALUES(`high_bid_updated`),`minutes`=VALUES(`minutes`),`lowBidIsOpt1`=VALUES(`lowBidIsOpt1`)
The full error message:
(1064, u"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 ''9007092665103', 'N', 'New', '2018-1-31-22-0', 'N', 7, 0, 'AUCN', 0, 0, 5, 3, '2' at line 1")
Side notes: Python None values are converted to MySQL null values. The same error occurred when changing None values to strings.

Why is this my sql statement wrong in the navicat? [duplicate]

This question already has answers here:
When to use single quotes, double quotes, and backticks in MySQL
(13 answers)
Closed 6 years ago.
INSERT INTO ry_useraccount
(
'Id',
'UserId',
'FreeAmount',
'PayFrozenAmount',
'WithdrawFrozenAmount',
'CurrentAsset',
'CreateTime',
'UpdateTime'
) VALUES
(
'1',
'52501',
'600',
'0',
'0',
'0',
NOW(),
NOW()
);
If just look at the sql,it is correct,but when I run it,the navicat said
“[SQL]INSERT INTO ry_useraccount('Id', 'UserId', 'FreeAmount',
'PayFrozenAmount', 'WithdrawFrozenAmount', 'CurrentAsset',
'CreateTime', 'UpdateTime') VALUES('1', '52501', '600', '0', '0', '0',
NOW(), NOW()); [Err] 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 ''Id', 'UserId', 'FreeAmount',
'PayFrozenAmount', 'WithdrawFrozenAmount', 'Curren' at line 1”
. I cannot find the reason.I guess that maybe some white space cause the result,but after I delete all the white spaces,it still didn't work.
The single quote are for literal string not for column name (you can use backticks if you need column name with space or with reserved words )
INSERT INTO ry_useraccount(Id, UserId, FreeAmount, PayFrozenAmount, WithdrawFrozenAmount, CurrentAsset, CreateTime, UpdateTime)
VALUES(1, 52501, 600, 0, 0, 0, NOW(), NOW());

What am I doing wrong with my query syntax?

I am trying to insert a row into my table with the following query in ssms:
INSERT INTO [Reservation].[dbo].[Contacts]
([ContactID]
,[Name]
,[Phone]
,[Email]
,[QoowayUserName])
VALUES
(<"100", nvarchar(50),>
,<"Vincent Chase", nvarchar(50),>
,<"3103331234", nvarchar(50),>
,<"vincent_chase#hollywood.com", nvarchar(50),>
,<"Username", nvarchar(50),>)
GO
I get the error:
Msg 102, Level 15, State 1, Line 8
Incorrect syntax near '<'.
I've also tried using single quotes. What am I doing wrong?
INSERT INTO Reservation.dbo.Contacts
(ContactID
,Name
,Phone
,Email
,QoowayUserName)
VALUES
('100'
,'Vincent Chase'
,'3103331234'
,'vincent_chase#hollywood.com'
,'Username')
You might need to remove the "dbo", like this:
INSERT INTO Reservation.Contacts
(ContactID
,Name
,Phone
,Email
,QoowayUserName)
VALUES
('100'
,'Vincent Chase'
,'3103331234'
,'vincent_chase#hollywood.com'
,'Username')

Whats wrong with the following mysql code

Insert into hotel('fname', 'lname'...
values
('null', 'abc'....
ON DUPLICATE KEY UPDATE
fname = 'null',
lname = 'abc',.....
Solve the above mysql query.
as you can see, you didn't enclose with single quotes the values which are not numeric,
Insert into child (`CASE`,`LASTNAME`,`FIRSTNAME`,`GENDER`,
`DOB`,`SSN`,`RACE`,`STREET`,`STREET2`,`CITY`,
`STATE`,`ZIP`,`PHONE`,`WORKPHONE`,`CELLPHONE`,
`PARENT NAME`,`GR`,`ADMITDATE`,`DISCHDATE`,
`WRK`,`WFIRSTNAME`,`WRKPHONE`)
VALUES ('null', 'Sivanesh', 'Jashawn', 'Male', '2002-03-08',
'206-80-2175', 'African American', '1689 Crucible Street',
'null', 'Pittsburgh', 'PA', '15210', '(412)458-3788',
'null', '(412)377-6079', 'Latel Williams', '2nd', '2010-03-17',
'null', 'null', 'Addison', '(412)594-2545')
ON DUPLICATE KEY UPDATE
LASTNAME = 'Sivanesh',
FIRSTNAME= 'Jashawn',...
You need to quote the values in your "KEY UPDATE" clause