mySQL error 1064 on Forward Engineering - mysql

Using mySQL workbench, i created an EER diagram and populated it with appropriate data for a class I am in. This is the sample of the generated code that creates the issue:
DROP TABLE IF EXISTS `bhk13`.`person` ;
SHOW WARNINGS;
CREATE TABLE IF NOT EXISTS `bhk13`.`person` (
`per_id` MEDIUMINT GENERATED ALWAYS AS () VIRTUAL,
`per_fname` VARCHAR(15) NOT NULL,
`per_lname` VARCHAR(30) NOT NULL,
`per_city` VARCHAR(45) NOT NULL,
`per_state` CHAR(2) NOT NULL,
`per_street` VARCHAR(45) NOT NULL,
`per_zip` INT NOT NULL,
`per_phone` BIGINT NOT NULL,
`per_email` VARCHAR(100) NOT NULL,
`per_ssn` INT UNSIGNED NOT NULL,
`per_gender` ENUM('m', 'f', 'o') NOT NULL,
`per_dob` DATE NOT NULL,
`per_is_emp` ENUM('y', 'n') NOT NULL,
`per_is_alm` ENUM('y', 'n') NOT NULL,
`per_is_stu` ENUM('y', 'n') NOT NULL,
`per_note` VARCHAR(255) NULL,
PRIMARY KEY (`per_id`))
ENGINE = InnoDB;
SHOW WARNINGS;
when I attempt to forward engineer the database, it generates the following error:
Thread started
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,
`per_fname` VARCHAR(15) NOT NULL,
`per_lname` VARCHAR(30) NOT NUL' at line 2
SQL Code:
CREATE TABLE IF NOT EXISTS `bhk13`.`person` (
`per_id` MEDIUMINT GENERATED ALWAYS AS () VIRTUAL,
`per_fname` VARCHAR(15) NOT NULL,
`per_lname` VARCHAR(30) NOT NULL,
`per_city` VARCHAR(45) NOT NULL,
`per_state` CHAR(2) NOT NULL,
`per_street` VARCHAR(45) NOT NULL,
`per_zip` INT NOT NULL,
`per_phone` BIGINT NOT NULL,
`per_email` VARCHAR(100) NOT NULL,
`per_ssn` INT UNSIGNED NOT NULL,
`per_gender` ENUM('m', 'f', 'o') NOT NULL,
`per_dob` DATE NOT NULL,
`per_is_emp` ENUM('y', 'n') NOT NULL,
`per_is_alm` ENUM('y', 'n') NOT NULL,
`per_is_stu` ENUM('y', 'n') NOT NULL,
`per_note` VARCHAR(255) NULL,
PRIMARY KEY (`per_id`))
ENGINE = InnoDB
SQL script execution finished: statements: 9 succeeded, 1 failed
Fetching back view definitions in final form.
Nothing to fetch
What is causing this issue and how can I fix it? All of the data is consistent

Related

Coverting script for older SQL version to work with 5.6

Apologies if my fundamental understanding of the issue is incorrect. I am not very experienced with SQL and am still learning.
I am attempting to generate a table for a data set and was given this script:
CREATE TABLE [dbo].[lobbying](
[uniqid] [varchar](36) NOT NULL, [registrant_raw] [varchar](110) NULL, [registrant] [varchar](50) NULL, [isfirm] [char](1) NULL,
[client_raw] [varchar](110) NULL, [client] [varchar](50) NULL,
[ultorg] [varchar](50) NULL,
[amount] [float] NULL,
[catcode] [char](5) NULL,
[source] [char] (5) NULL,
[self] [char](1) NULL,
[IncludeNSFS] [char](1) NULL,
[use] [char](1) NULL,
[ind] [char](1) NULL,
[year] [char](4) NULL,
[type] [char](4) NULL,
[typelong] [varchar](50) NULL, [affiliate] [char](1) NULL,
) ON [PRIMARY]
As you can probably tell, it doesn't work. The script was updated in 2015 so that is why I presume the issue to be the version. I tried using SQL Fiddle to figure out what was causing the issue, and found that taking the brackets out helped(which makes sense, as the tutorial I was following did not use any brackets for their tables). However, even with that, I still receive 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 'use char(1) NULL,
ind char(1) NULL,
year char(4) NULL,
type char(4) NULL,
typelo' at line 10
Does anybody know what the issue is here? Any help would be greatly appreciated. I've poured out about 4 hours into this project so far and have not been able to get past this roadblock.
It is enough to replace the names with brackets with backticks and also remove the brackets around the type nqames
CREATE TABLE lobbying(
`niqid`varchar(36) NOT NULL
, `egistrant_raw`varchar(110) NULL
, `egistrant` varchar(50) NULL
, `isfirm` char(1) NULL,
`client_raw` varchar(110) NULL
, `client` varchar(50) NULL,
`ultorg` varchar(50) NULL,
`amount` float NULL,
`catcode` char(5) NULL,
`source` char(5) NULL,
`self` char(1) NULL,
`IncludeNSFS` char(1) NULL,
`use` char(1) NULL,
`ind` char(1) NULL,
`year` char(4) NULL,
`type` char(4) NULL,
`typelong` varchar(50) NULL
, `affiliate` char(1) NULL
)
✓
db<>fiddle here

Mysql syntax Error when creating a table #1064

When I create a table in my localhost and it says
#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,
register_date DATETIME NOT NULL,
last_login DATETIME NOT NUL' at line 6"
(WampServer v 3.0.6 64bit, Apache 2.4.23 - MySql 5.7.14)
I've already try to change DB engine into InnoDB but the error was still appear.
Here is my Query
CREATE TABLE `inventry`.`users` (
`id` INT NOT NULL AUTO_INCREMENT,
`username` VARCHAR(225) NOT NULL,
`email` VARCHAR(225) NOT NULL,
`password` VARCHAR(300) NOT NULL,
`usertype` ENUM(0) NOT NULL,
`register_date` DATETIME NOT NULL,
`last_login` DATETIME NOT NULL,
`notes` VARCHAR(225) NOT NULL,
PRIMARY KEY(`id`)
) ENGINE = InnoDB;
U P D A T E D******
I want store data in this field. but when i save this it getting error. How can i fix this.?
Try below -
CREATE TABLE users(
id INT NOT NULL AUTO_INCREMENT,
username VARCHAR(225) NOT NULL,
email VARCHAR(225) NOT NULL,
password VARCHAR(300) NOT NULL,
usertype ENUM('0') NOT NULL,
register_date DATETIME NOT NULL,
last_login DATETIME NOT NULL,
notes VARCHAR(225) NOT NULL,
primary key (id)
)
just put, ENUM values, in quotes
CREATE TABLEinventry.users(
id INT NOT NULL AUTO_INCREMENT,
username VARCHAR(225) NOT NULL,
email VARCHAR(225) NOT NULL,
password VARCHAR(300) NOT NULL,
usertype ENUM(**'0'**) NOT NULL,
register_dateDATETIME NOT NULL,
last_loginDATETIME NOT NULL,
notesVARCHAR(225) NOT NULL,
PRIMARY KEY(id)
) ENGINE = InnoDB;

What is wrong with my code for phpmyadmin?

I tried to make a database is phpmyadmin, but I keep getting an 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 '0) NULL,
Datum Verkocht DATE NULL,
Personeel VARCHAR(30) NULL,
`Min' at line 9
That's for this code
CREATE TABLE `veilingen`.`Veilingen`(
`Nr` INT(3) NOT NULL,
`Artikel` VARCHAR(100) NULL,
`Datum Geveild` DATE NULL,
`Tel. Verkoper` INT(10) NULL,
`Datum Ingeleverd` DATE NULL,
`Kast`
SET
(0) NULL,
`Datum Verkocht` DATE NULL,
`Personeel` VARCHAR(30) NULL,
`Minimum` DECIMAL NULL,
`Koop Nu` DECIMAL(100) NULL,
`Geveild Voor` DECIMAL(100) NULL,
`Betaald` ENUM(0) NULL,
`Cadeaubon` DECIMAL(100) NULL,
`Versturen` VARCHAR(100) NULL,
`Opmerkingen` VARCHAR(100) NULL,
PRIMARY KEY(`Nr`(1))
) ENGINE = MyISAM;
Sorry for the mess, I can't get the code span to work.
Can somebody help me?
Following is the right syntax for create table in php, you can edit this code according to your table name,column name and it's datatype.
CREATE TABLE employee (
empId int(11) NOT NULL AUTO_INCREMENT,
empName varchar(255) NOT NULL,
empDept varchar(255) NOT NULL,
PRIMARY KEY (empId)
)

Error trying to create table in MySQL via terminal

I am trying to create a table in my database via terminal.
Here is my syntax:
CREATE TABLE `users` (
PRIMARY KEY(id) NOT NULL AUTO_INCREMENT,
`last_name` VARCHAR NOT NULL,
`first_name` VARCHAR NOT NULL,
`gender` VARCHAR NOT NULL,
`fav_color` VARCHAR NOT NULL,
`birthdate` DATE NOT NULL
);
I am getting this 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 'NOT NULL AUTO_INCREMENT,
`last_name` VARCHAR NOT NULL,
`first_name` VARCHA' at line 2
What am i dong wrong here?
Besides the issues that Jens and Marc pointed out, You have to declare the length of your Varchar fields in order for this statement to work, like so:
CREATE TABLE `test`.`users` (
`id` INT NOT NULL AUTO_INCREMENT,
`last_name` VARCHAR(45) NOT NULL,
`first_name` VARCHAR(45) NOT NULL,
`gender` VARCHAR(45) NOT NULL,
`fav_color` VARCHAR(45) NOT NULL,
`birthdate` DATE NOT NULL,
PRIMARY KEY (`id`));
the syntax of your create statement is wrong:
the correct one is this:
CREATE TABLE `users` (
`id` int NOT NULL AUTO_INCREMENT,
`last_name` VARCHAR(255) NOT NULL,
`first_name` VARCHAR(255) NOT NULL,
`gender` VARCHAR(255) NOT NULL,
`fav_color` VARCHAR(255) NOT NULL,
`birthdate` DATE NOT NULL,
PRIMARY KEY(`id`)
);
For more Information see the offical documentation.
it should be
id int primary key auto_increment not null
You're trying to define a primary key on a field that doesn't exist. Keys cannot be "not null" and definitely cannot be "auto_increment".

Throwing MySQLSyntaxErrorException regarding syntax of SQL in Struts

I am making a project on Struts framework.
I am getting a exception from server while inserting data in a table using SQL and I am unable to find the solution.
The error is as following:
javax.servlet.ServletException: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException:
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 ',,,,,,,'yes','yes',,,,'admin')' at line 1
My code which is generating the error is as following:
sql="Insert into field_visit_details (visit_date,block,village,flw_category,
flw_name,flw_contact_no,aware_zinc,
aware_ors,past_zinc,past_ors,qty_avail_zinc_ten,qty_avail_zinc_twe,qty_avail_zinc_syr,
qty_avail_ors,qty_disp_zinc_ten,qty_disp_zinc_twe,qty_disp_zinc_syr,qty_disp_ors,
stockout_zinc,stockout_ors,diar_cases_seen,diar_cases_reff,diar_deaths_less_than_five,
added_by)
values
('"+field_visit_date+"','"+block_row_one+"','"+village_row_one+"','"+flw_category_row_one
+"','"+flw_name_row_one+"','"+flw_contact_no_row_one+"','"+aware_zinc_row_one+"','"+
aware_ors_row_one+"','"+past_zinc_row_one+"','"+past_ors_row_one+"','"+
qty_avail_zinc_ten_row_one+"','"+qty_avail_zinc_twe_row_one+"','"+
qty_avail_zinc_syr_row_one+"','"+qty_avail_ors_row_one+"','"+qty_disp_zinc_ten_row_one
+"','"+qty_disp_zinc_twe_row_one+"','"+qty_disp_zinc_syr_row_one+"','"+
qty_disp_ors_row_one+"','"+stockout_zinc_row_one+"','"+stockout_ors_row_one+
"','"+diar_cases_seen_row_one+"','"+diar_cases_reff_row_one+"','"+diar_deaths_row_one
+"','"+loginid+"')";
System.out.println(sql);
int x=stmt.executeUpdate(sql);
if(x>0)
SUCCESS="admin";
Table Structure is as following:
CREATE TABLE IF NOT EXISTS `field_visit_details` (
`field_visit_id` int(11) NOT NULL auto_increment,
`visit_date` date NOT NULL,
`block` varchar(100) NOT NULL,
`village` varchar(100) NOT NULL,
`flw_category` varchar(45) NOT NULL,
`flw_name` varchar(100) NOT NULL,
`flw_contact_no` varchar(13) NOT NULL,
`aware_zinc` varchar(10) NOT NULL,
`aware_ors` varchar(10) NOT NULL,
`past_zinc` varchar(10) NOT NULL,
`past_ors` varchar(10) NOT NULL,
`qty_avail_zinc_ten` int(11) NOT NULL,
`qty_avail_zinc_twe` int(11) NOT NULL,
`qty_avail_zinc_syr` int(11) NOT NULL,
`qty_avail_ors` int(11) NOT NULL,
`qty_disp_zinc_ten` int(11) NOT NULL,
`qty_disp_zinc_twe` int(11) NOT NULL,
`qty_disp_zinc_syr` int(11) NOT NULL,
`qty_disp_ors` int(11) NOT NULL,
`stockout_zinc` varchar(11) NOT NULL,
`stockout_ors` varchar(11) NOT NULL,
`diar_cases_seen` int(11) NOT NULL,
`diar_cases_reff` int(11) NOT NULL,
`diar_deaths_less_than_five` int(11) NOT NULL,
`added_by` varchar(100) NOT NULL,
PRIMARY KEY (`field_visit_id`) )
ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;
The query when I printed in the console was :
Insert into field_visit_details (visit_date,block,village,flw_category,flw_name,
flw_contact_no,aware_zinc,aware_ors,past_zinc,past_ors,qty_avail_zinc_ten,
qty_avail_zinc_twe,qty_avail_zinc_syr,qty_avail_ors,
qty_disp_zinc_ten,qty_disp_zinc_twe,qty_disp_zinc_syr,qty_disp_ors,stockout_zinc,
stockout_ors,diar_cases_seen,diar_cases_reff,diar_deaths_less_than_five,added_by)
values
('2014-07-02','ASDASD','','asha','asd+','99','yes','yes','yes','yes',
'12','12','12','12','12','12','12','12','yes','yes','12','12','12','admin')
But the thing is that the query is inserting the data successfully in the table but still server is showing the above error.
I even used the above printed query directly in phpmyadmin and worked well without any problem.
You have a syntax exception in the SQL statement. The error message you have posted point to it.
So, you need to change SQL statement and fix syntax errors. For this purpose you should rewrite it to use PraparedStatement like in the example JDBC PreparedStatement example – Insert a record.
And use appropriate to the database column types set methods when setting parameters to the prepared statement.