I have following table:
CREATE TABLE `test123`.`orders` (
`o_id` varchar(12) NOT NULL DEFAULT '',
`p_id` varchar(10) NOT NULL DEFAULT '',
`p_qty` int(11) DEFAULT NULL,
`p_price` decimal(15,2) DEFAULT NULL,
`o_price` decimal(15,2) DEFAULT NULL,
`c_charge` decimal(15,2) DEFAULT NULL,
`total_price` decimal(15,2) DEFAULT NULL,
`c_name` varchar(100) NOT NULL DEFAULT '',
`c_address` text NOT NULL,
`c_pin` varchar(11) DEFAULT NULL,
`c_mobile` varchar(11) NOT NULL DEFAULT '',
`c_email` varchar(100) DEFAULT NULL,
`o_dt` date NOT NULL,
`o_delivery_dt` date DEFAULT NULL,
`o_remarks` varchar(500) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
Trying to execute below Insert query:
insert into [orders] ([o_id],[p_id],[p_qty],[p_price],[o_price],[c_charge],[total_price],[c_name],[c_address],[c_pin],[c_mobile],[c_email],[o_dt],[o_delivery_dt],[o_remarks])
values('2016020002','PA001','1','900.00','900.00','','900.00','ABCD','my full address','123456','12345678','myabcd@abcd.com','2016-02-28 17:04:29','','');
On execution of this insert query getting error as "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 '[o_id],[p_id],[p_qty],[p_price],[o_price],[c_charge],[total_price],[c_name],[c_a' at line 1" error no: 1064.
Please help, unable find any syntax error here.
SQLFiddle I have made some changes and now the schema runs. You were inserting ''
in c_charge which is not correct. Also []
tags are not required. Check out the link.
Query is for Mysql db as the question tagged mysql.
CREATE TABLE orders (
o_id varchar(12) NOT NULL DEFAULT '',
p_id varchar(10) NOT NULL DEFAULT '',
p_qty int(11) DEFAULT NULL,
p_price decimal(15,2) DEFAULT NULL,
o_price decimal(15,2) DEFAULT NULL,
c_charge decimal(15,2) DEFAULT NULL,
total_price decimal(15,2) DEFAULT NULL,
c_name varchar(100) NOT NULL DEFAULT '',
c_address text NOT NULL,
c_pin varchar(11) DEFAULT NULL,
c_mobile varchar(11) NOT NULL DEFAULT '',
c_email varchar(100) DEFAULT NULL,
o_dt date NOT NULL,
o_delivery_dt date DEFAULT NULL,
o_remarks varchar(500) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
insert into orders(o_id,p_id,p_qty,p_price,o_price,c_charge,total_price,c_name,c_address,c_pin,c_mobile,c_email,o_dt,o_delivery_dt,o_remarks)
values('2016020002','PA001','1','900.00','900.00',null,'900.00','ABCD','my full address','123456','12345678','myabcd@abcd.com','2016-02-28 17:04:29',null,'');