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