Error 1064 with MySQL Workbench, with CREATE TABLE function - mysql

I'm new to MySQL and I'm trying to create tables inside a Database,
I used the 'Create a new table' function that appears on my SQL Workbench, instead of manually trying to add them. It writes this :
CREATE TABLE `Bory`.`Produits` (
`idProduits` NOT NULL,
`Marque` VARCHAR(45) NULL,
`NomProduit` VARCHAR(45) NULL,
PRIMARY KEY (`idProduits`));
So I go and click on "Apply" but I receive this message :
Operation failed: There was an error while applying the SQL script to the database.
Executing:
CREATE TABLE `Bory`.`Produits` (
`idProduits` NOT NULL,
`Marque` VARCHAR(45) NULL,
`NomProduit` VARCHAR(45) NULL,
PRIMARY KEY (`idProduits`));
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 'NOT NULL,
Marque VARCHAR(45) NULL,
NomProduit VARCHAR(45) NULL,
PRIMAR' at line 2
So now I am lost, because why is does function that is native to the Workbench itself keep making mistakes and doesn't let me add tables?

as mentioned in comments, You did't specified the data type for idProduits. for instance use int like below:
CREATE TABLE `Bory`.`Produits` (
`idProduits` int NOT NULL,
`Marque` VARCHAR(45) NULL,
`NomProduit` VARCHAR(45) NULL,
PRIMARY KEY (`idProduits`));

Related

In the MySQL WorkBench, when executing a Forward Engineering, an error 1064 appears in the log. Help me to understand

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 ') VIRTUAL,
`name` VARCHAR(1000) NULL,
`place_of_birth` VARCHAR(1000) NULL,
' at line 5
SQL Code:
-- -----------------------------------------------------
-- Table `myBank`.`Clients`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `myBank`.`Clients` (
`id` INT GENERATED ALWAYS AS () VIRTUAL,
`name` VARCHAR(1000) NULL,
`place_of_birth` VARCHAR(1000) NULL,
`date_of_birth` DATE NULL,
`address` VARCHAR(1000) NULL,
`passport` VARCHAR(100) NULL,
PRIMARY KEY (`id`))
ENGINE = InnoDB
SQL script execution finished: statements: 6 succeeded, 1 failed
Fetching back view definitions in final form.
Nothing to fetch
MySQL supports generated columns, but you must give an expression in the parentheses. It's not valid to say GENERATED ALWAYS AS ().
If you intended to use ANSI SQL:2003 syntax for an identity column, MySQL does not support that syntax.
You can't make a generated column also be auto-increment.
https://dev.mysql.com/doc/refman/8.0/en/create-table-generated-columns.html says:
The AUTO_INCREMENT attribute cannot be used in a generated column definition.
An AUTO_INCREMENT column cannot be used as a base column in a generated column definition.
For an identity primary key, you should use:
CREATE TABLE IF NOT EXISTS `myBank`.`Clients` (
`id` INT NOT NULL AUTO_INCREMENT,
`name` VARCHAR(1000) NULL,
`place_of_birth` VARCHAR(1000) NULL,
`date_of_birth` DATE NULL,
`address` VARCHAR(1000) NULL,
`passport` VARCHAR(100) NULL,
PRIMARY KEY (`id`))
ENGINE = InnoDB

How do I debug SQL query with the following error message

This is my query.
CREATE TABLE `requirements`
(
`id` INT UNSIGNED NOT NULL AUTO_INCREMENT,
`requirement_id` VARCHAR NOT NULL,
`state` VARCHAR NOT NULL,
`city` VARCHAR NOT NULL,
`salary_per_anum` FLOAT NOT NULL,
`is_closed` TINYINT(1) NOT NULL,
`created_updated` DATETIME NOT NULL,
CONSTRAINT `pk_requirements` PRIMARY KEY(`id`)
);
and this is the error message
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 'NOT NULL, `state` VARCHAR NOT NULL, `city` VARCHAR NOT NULL, `salary_per_anum` F' at line 1
how can I debug what seems to be the issue?
You need to define a length of the string colum like
`requirement_id` VARCHAR(100)
and the same with column state and city.
But since requirement_id looks like a number id column it must be of the same type as id in table requirements, probably int.
Also your constraint seems to be defined wrong. It should refer to the table requirements.

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

I am using Sequel Pro with MySQL on my Mac. I return 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 ')' " every time I attempt to run this sql query. The Database is created successfully, but the table is not. Can anyone advise where the error in my syntax is? I simply do not see it:
CREATE DATABASE bamazon
USE bamazon;
CREATE TABLE products
(
`id` int NOT NULL AUTO_INCREMENT,
`product_name` varchar(45) NOT NULL,
`department_name` varchar(45) NOT NULL,
`price` int NOT NULL,
`stock_quantity` int NOT NULL,
PRIMARY KEY (id),
);
Please remove the ',' after PRIMARY KEY (id). It should be like this
CREATE TABLE products
(
id int NOT NULL AUTO_INCREMENT,
product_name varchar(45) NOT NULL,
department_name varchar(45) NOT NULL,
price int NOT NULL,
stock_quantity int NOT NULL,
PRIMARY KEY (id)
);
The query does not work because there is an extra comma (,) at the end. Remove that and it will work. The correct syntax will be:
CREATE TABLE products
(
id int NOT NULL AUTO_INCREMENT,
product_name varchar(45) NOT NULL,
department_name varchar(45) NOT NULL,
price int NOT NULL,
stock_quantity int NOT NULL,
PRIMARY KEY (id)
);

MySQL table creation error in workbench

I'm new to MySQL and I'm running version 5.7.19-log (At least thats what I'm getting from command line client) with Workbench 6.3.9 Community edition. My problem is I'm trying to create a simple table with auto-generated id using the UI, however when I execute the generated script it throws me the following error:
Operation failed: There was an error while applying the SQL script to the database.
Executing:
CREATE TABLE `travelportaldb`.`user` (
`user_id` INT GENERATED ALWAYS AS () VIRTUAL,
`name` VARCHAR(45) NOT NULL,
`account_id` VARCHAR(15) NULL,
`account_currency` CHAR(3) NULL,
`account_balance` DECIMAL NULL,
PRIMARY KEY (`user_id`));
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 ') VIRTUAL,
`name` VARCHAR(45) NOT NULL,
`account_id` VARCHAR(15) NULL,
`ac' at line 2
SQL Statement:
CREATE TABLE `travelportaldb`.`user` (
`user_id` INT GENERATED ALWAYS AS () VIRTUAL,
`name` VARCHAR(45) NOT NULL,
`account_id` VARCHAR(15) NULL,
`account_currency` CHAR(3) NULL,
`account_balance` DECIMAL NULL,
PRIMARY KEY (`user_id`))
This is the script that it generated:
CREATE TABLE `travelportaldb`.`user` (
`user_id` INT GENERATED ALWAYS AS () VIRTUAL,
`name` VARCHAR(45) NOT NULL,
`account_id` VARCHAR(15) NULL,
`account_currency` CHAR(3) NULL,
`account_balance` DECIMAL NULL,
PRIMARY KEY (`user_id`));
I have no idea what's wrong. I'm from the oracle background and the query seems to be fine except the auto generated apart which I have no idea about.
Please help.
Thanks.
When you switch on the generated flag in MySQL Workbench the column details fields will change a bit to allow setting the required options for a generated column:
Most important here is the Expression field. For a generated column you have to specify an expression which is used for generation. Obviously you didn't do that and hence in your generated SQL the column definitions are wrong (empty parentheses, where an expression should be).
PS: You can also see the used server version in the Session tab page:

MySQL 5.6.13 not executing create table properly

I have the following SQL to create a table on a MySQL 5.6.13 instance:
CREATE TABLE 'exchange' (
'id' int NOT NULL AUTO_INCREMENT,
'abbrev' varchar(32) NOT NULL,
'name' varchar(255) NOT NULL,
'city' varchar(255) NULL,
'country' varchar(255) NULL,
'currency' varchar(128) NULL,
'time_zone_offset' time NULL,
'created_date' datetime NOT NULL,
'last_updated_date' datetime NOT NULL,
PRIMARY KEY ('id')
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8;
However, I keep getting the following unhelpful 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
''exchange' ( 'id' int NOT NULL AUTO_INCREMENT,
'abbrev' varchar(32) NOT NULL, 'n' at line 1
I must be missing something glaringly obvious...
Any ideas where I'm going wrong?
Try :
CREATE TABLE exchange (
Ref:
http://dev.mysql.com/doc/refman/5.1/en/create-table.html
Remove all quotes, this helped me on a windows machine command line