Question

I have looked this over and over and was going to see if I could get an extra set of eyes on it. I am trying to run a create table query, but I cannot seem to get it to work. The error I am getting is

#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 '`1`, `id_shop` int(11) NOT NULL DEFAULT `1`, `id_lang` int(10) NOT NULL DEFAUL' at line 4

here the the query I am trying to run

CREATE TABLE IF NOT EXISTS `PREFIX_quote` (
`id_quote` int(10) NOT NULL AUTO_INCREMENT,
`reference` varchar(9) DEFAULT NULL,
`id_shop_group` int(11) NOT NULL DEFAULT `1`,
`id_shop` int(11) NOT NULL DEFAULT `1`,
`id_lang` int(10) NOT NULL DEFAULT `1`,
`id_customer` int(10) NOT NULL,
`total_discounts` decimal(17,2) NOT NULL DEFAULT `0.00`,
`total_products` decimal(17,2) NOT NULL DEFAULT `0.00`,
`total_product_wt` decimal(17,2) NOT NULL DEFAULT `0.00`,
`total_shipping` decimal(17,2) NOT NULL DEFAULT `0.00`,
`quote_number` int(10) NOT NULL DEFAULT `0`,
`quote_date` datetime NOT NULL,
`valid` int(1) NOT NULL DEFAULT `1`,
`id_employee` int(11) NOT NULL,
`date_add` datetime NOT NULL,
`date_upd` datetime NOT NULL,
PRIMARY KEY (`id_quote`),
KEY `id_customer` (`id_customer`),
KEY `id_employee` (`id_employee`));
Était-ce utile?

La solution

Drop the backticks around integers. See the fiddle.

CREATE TABLE IF NOT EXISTS `PREFIX_quote` (
`id_quote` int(10) NOT NULL AUTO_INCREMENT,
`reference` varchar(9) DEFAULT NULL,
`id_shop_group` int(11) NOT NULL DEFAULT 1,
`id_shop` int(11) NOT NULL DEFAULT 1,
`id_lang` int(10) NOT NULL DEFAULT 1,
`id_customer` int(10) NOT NULL,
`total_discounts` decimal(17,2) NOT NULL DEFAULT 0.00,
`total_products` decimal(17,2) NOT NULL DEFAULT 0.00,
`total_product_wt` decimal(17,2) NOT NULL DEFAULT 0.00,
`total_shipping` decimal(17,2) NOT NULL DEFAULT 0.00,
`quote_number` int(10) NOT NULL DEFAULT 0,
`quote_date` datetime NOT NULL,
`valid` int(1) NOT NULL DEFAULT 1,
`id_employee` int(11) NOT NULL,
`date_add` datetime NOT NULL,
`date_upd` datetime NOT NULL,
PRIMARY KEY (`id_quote`),
KEY `id_customer` (`id_customer`),
KEY `id_employee` (`id_employee`));

Autres conseils

Backticks (`) are used to quote identifiers in MySQL, so that reserved words or special characters can appear in them. They are often used to enclose column names, which you're doing, even though it's often unnecessary, but not values: remove the backticks from your default values:

CREATE TABLE IF NOT EXISTS `PREFIX_quote` (
`id_quote` int(10) NOT NULL AUTO_INCREMENT,
`reference` varchar(9) DEFAULT NULL,
`id_shop_group` int(11) NOT NULL DEFAULT 1,
...

Your value is in backticks: `1`, this is incorrect. This be in quotes, or since it's a number, unquoted.

`id_shop_group` int(11) NOT NULL DEFAULT 1,

Make sure to do this for all your fields.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top