MySQL Workbench create table generates SQL that throws an error - mysql

I am using MySQL version 5.7.18 and MySQL Workbench is targeting version 5.6.20. However, when I try and create a table using the table generator it produces the following sql statement:
CREATE TABLE `sys`.`annotations` (
`id` INT GENERATED ALWAYS AS () VIRTUAL,
`annotation` LONGTEXT NOT NULL,
PRIMARY KEY (`id`));
But this produces the following error message:
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 ') STORED',
`annotation` LONGTEXT NOT NULL,
PRIMARY KEY (`id`))' at line 2
SQL Statement:
CREATE TABLE `sys`.`annotations` (
`id` INT GENERATED ALWAYS AS () STORED,
`annotation` LONGTEXT NOT NULL,
PRIMARY KEY (`id`))
Why would this be happening and how would I go about fixing this?

I have no idea what an empty expression means for a computed column. Nor do I understand a VIRTUAL column being a primary key. I would use:
CREATE TABLE sys.`annotations` (
`id` INT AUTO_INCREMENT PRIMARY KEY,
`annotation` LONGTEXT NOT NULL
);

Related

MYSQL (WAMP SERVER): Error 1064 when using AUTO_INCREMENT=1000 to create table column?

I have this code:
CREATE TABLE Company ( Comp_Code INT(5) NOT NULL AUTO_INCREMENT=1000, Comp_Name VARCHAR(15) NOT NULL, PRIMARY KEY (Comp_Code) );
but when i run it in MYSQL from WAMPServer it gives an 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 '=1000,
Comp_Name VARCHAR(15) NOT NULL,
PRIMARY KEY (Comp_Code)
)' at line 2
Why is this happening? I can't seem to find any solution to this particular issuer.
AUTO_INCREMENT is column option.
Initial AUTO_INCREMENT=1000 value is table option.
CREATE TABLE Company (
Comp_Code INT(5) NOT NULL AUTO_INCREMENT, -- specify that the column is AI
Comp_Name VARCHAR(15) NOT NULL,
PRIMARY KEY (Comp_Code)
) AUTO_INCREMENT=1000; -- specify initial AI value

Error 1064 when importing SQL generated from MySQL Workbench forward engineering

I am trying to import a schema into MySQL (MariaDB 10.1.36) and I am getting the above error. I also tried direct forward engineering in MySQL Workbench but the results are the same.
ERROR 1064 (42000): 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 ')
ENGINE = InnoDB
Sample code that fails is:
CREATE TABLE IF NOT EXISTS `example`.`adhere` (
`adhere_id` BIGINT(20) NOT NULL AUTO_INCREMENT,
`description` VARCHAR(100) NOT NULL,
`id_uuid` VARCHAR(36) NULL,
PRIMARY KEY (`adhere_id`),
INDEX `ix_tmp_autoinc` (`adhere_id` ASC) VISIBLE)
ENGINE = InnoDB
AUTO_INCREMENT = 19
DEFAULT CHARACTER SET = latin1;
I tried changing the backticks into single quotes in vain, I later removed them to same result. The expectation is to have the table created so do the rest structured like so.
remove the VISIBLE word
DEMO
CREATE TABLE IF NOT EXISTS `example`.`adhere`
(
`adhere_id` BIGINT(20) NOT NULL AUTO_INCREMENT,
`description` VARCHAR(100) NOT NULL,
`id_uuid` VARCHAR(36) NULL,
PRIMARY KEY (`adhere_id`),
INDEX `ix_tmp_autoinc` (`adhere_id` ASC)
)
Check that your version of mariadb supports invisible/visible indexes here https://mariadb.com/kb/en/library/invisible-columns/ and if not turn off the option in mysql workbench here https://dev.mysql.com/doc/workbench/en/wb-table-editor-indexes-tab.html

PhPMyAdmin Error #1064; Syntax Error

I'm trying to put together a MySQL database for a forum, And when I try to make a section table I keep encountering a problem
#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 'TYPE = INNODB' at line 7
Here's the code:
CREATE TABLE sections (
sect_id INT(8) NOT NULL AUTO_INCREMENT,
sect_name VARCHAR(255) NOT NULL,
sect_desc VARCHAR(255) NOT NULL,
UNIQUE INDEX sect_name_unique (sect_name),
PRIMARY KEY (sect_id)
) TYPE=INNODB;
Use the following query
CREATE TABLE IF NOT EXISTS sections (
sect_id INT(8) NOT NULL AUTO_INCREMENT,
sect_name VARCHAR(255) NOT NULL,
sect_desc VARCHAR(255) NOT NULL,
UNIQUE INDEX sect_name_unique (sect_name),
PRIMARY KEY (sect_id)
) ENGINE=InnoDB
To mention the type of engine use ENGINE keyword.

Running SQL script gives syntax error

I have written an sql script with the following contents :
CREATE DATABASE IF NOT EXISTS stock_trading;
USE stock_trading;
CREATE TABLE IF NOT EXISTS transactions(
user_name VARCHAR(30) NOT NULL,
passwrd BINARY(64) NOT NULL,
balance_cash BIGINT NOT NULL DEFAULT 100000,
PRIMARY KEY (user_name,passwrd),
)ENGINE=InnoDB;
and every time I try to run it in the SQL command prompt it keeps giving away the error as:
ERROR 1064 (42000) at line 5 in file: 'db_script.sql': 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 ')ENGINE=InnoDB' at line 5
the script appears to be correct but I don't know why it keeps giving this error.
Additional information:
Operating System : Arch Linux
Database : MariaDB
You have a stray comma at the end of your table definition:
PRIMARY KEY (user_name,passwrd),
^^^ remove this
Your full table definition:
CREATE TABLE IF NOT EXISTS transactions(
user_name VARCHAR(30) NOT NULL,
passwrd BINARY(64) NOT NULL,
balance_cash BIGINT NOT NULL DEFAULT 100000,
PRIMARY KEY (user_name, passwrd)
) ENGINE=InnoDB;

#1064, xammp, phpMyAdmin, MYSQL - Why have I an error in mySQL syntax?

#1064 - 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 ') VIRTUAL,
`title_type` VARCHAR(45) NULL DEFAULT null,
PRIMARY KEY (`id`))' at line 2
Here is a part of script:
CREATE TABLE IF NOT EXISTS `sggis`.`maps_type` (
`id` INT GENERATED ALWAYS AS () VIRTUAL,
`title_type` VARCHAR(45) NULL DEFAULT 'yandex',
PRIMARY KEY (`id`))
ENGINE = InnoDB;
SQL says that problem is in the 2nd line, but i can't find it.
Code generated by MySQL Workbench.
When using VIRTUAL columns you need to specify the expression
Any legal, deterministic expression which can be calculated is
permitted, with the following exceptions:
Your expression is blank.