I'm toying around with MySQL Workbench, using its tools to create my database. When attempting to forward engineer the database, I keep getting this error.
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 '-01-01,
`PlateNum` CHAR(7) NOT NULL DEFAULT 'ABCDEFG',
`CellPhone` INT(10) U' at line 9
SQL Code:
-- -----------------------------------------------------
-- Table `MetalDelivery`.`Drivers`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `MetalDelivery`.`Drivers` (
`DriverID` INT NOT NULL AUTO_INCREMENT,
`FName` CHAR(12) NOT NULL DEFAULT 'First',
`LName` CHAR(12) NOT NULL DEFAULT 'Last',
`Sex` CHAR(1) NOT NULL DEFAULT 'M',
`DOB` DATE NOT NULL DEFAULT 1900-01-01,
`PlateNum` CHAR(7) NOT NULL DEFAULT 'ABCDEFG',
`CellPhone` INT(10) UNSIGNED NOT NULL DEFAULT 5550000000,
PRIMARY KEY (`DriverID`))
ENGINE = InnoDB
SQL script execution finished: statements: 6 succeeded, 1 failed
In the SQL script preview, it does show a semicolon after InnoDB
Any kind of date needs to be specified as if a string:
`DOB` DATE NOT NULL DEFAULT '1900-01-01'
It's also worth expanding this schema a little. Names are frequently over 12 letters long. VARCHAR(255) is a good default for "string" fields.
You may find that these defaults are a huge mistake. It's possible someone's actual last name is "Last" in which case it's like they're using a default, or they simply don't have a last name. NULL values serve a purpose, so embrace them.
Related
I am importing a database from MySQL 4.0.27-standard into a new webhost with Server version: 5.5.48-37.8 - Percona Server (GPL), Release 37.8, Revision 727, using PHPMySQL.
I am getting the following 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 '(14) NOT NULL '', PRIMARY KEY (site_id) ) ENGINE=MyISAM' at
line 14
Here is the CREATE TABLE query:
CREATE TABLE Brewing (
site_id int(5) NOT NULL auto_increment,
site_url varchar(255) NOT NULL default '',
site_name varchar(255) NOT NULL default '',
site_comment varchar(255) default NULL,
site_rating int(2) NOT NULL default '0',
site_entrydate varchar(25) NOT NULL default '',
site_lasttouched timestamp(14) NOT NULL,
PRIMARY KEY (site_id)
) ENGINE=MyISAM;
Remove the size of timestamp. It already has a default for setting up timestamp. So remove (14).
Plus added bonus, add ON UPDATE CURRENT_TIMESTAMP for auto update of timestamp.
The length argument for timestamp represents fractional seconds (see the documentation). The allowed lengths for fractional seconds are 0 to 6. 14 is too long.
I would advise you to just remove the length altogether.
everyone! I'm newbie to MySQL. I've created a new model using Workbench tools(I mean, that I haven't written any string of code by myself).
When trying to forward engineer it I get:
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 'COMMENT '')
ENGINE = InnoDB' at line 8
SQL Code:
-- -----------------------------------------------------
-- Table `university`.`CITY`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `university`.`CITY` (
`ID_CITY` INT NOT NULL COMMENT '',
`CNAME` TEXT(15) NULL COMMENT '',
`POPULATION` INT NULL COMMENT '',
PRIMARY KEY (`ID_CITY`) COMMENT '')
ENGINE = InnoDB
SQL script execution finished: statements: 5 succeeded, 1 failed
Fetching back view definitions in final form.
Nothing to fetch
Moreover, when trying to forward engineer default Workbench model "sakila_full" i get the same thing:
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 'COMMENT '',
INDEX `idx_actor_last_name` (`last_name` ASC) COMMENT '')
ENGINE ' at line 9
SQL Code:
-- -----------------------------------------------------
-- Table `sakila`.`actor`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `sakila`.`actor` (
`actor_id` SMALLINT UNSIGNED NOT NULL AUTO_INCREMENT COMMENT '',
`first_name` VARCHAR(45) NOT NULL COMMENT '',
`last_name` VARCHAR(45) NOT NULL COMMENT '',
`last_update` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '',
PRIMARY KEY (`actor_id`) COMMENT '',
INDEX `idx_actor_last_name` (`last_name` ASC) COMMENT '')
ENGINE = InnoDB
DEFAULT CHARACTER SET = utf8
SQL script execution finished: statements: 5 succeeded, 1 failed
Fetching back view definitions in final form.
Could not get definition for sakila.customer_list from server
Could not get definition for sakila.film_list from server
Could not get definition for sakila.nicer_but_slower_film_list from server
Could not get definition for sakila.staff_list from server
Could not get definition for sakila.sales_by_store from server
Could not get definition for sakila.sales_by_film_category from server
Could not get definition for sakila.actor_info from server
7 views were read back.
Thanks in advance!
Well, the BIG probleme is that Mysql Workbench adds itself indexes comments that generate an error, when using "Forward Engineer" or "Synchronize Model"
This problem did not exist when I was using version 6.0.
It looks like you've taken the COMMENT strings a little too far. According to the MySQL CREATE TABLE syntax, a COMMENT attribute is only permitted on a column definition. That means it's invalid on the INDEX or PRIMARY KEY definitions you have listed near the end of your CREATE statements.
The COMMENT '' aren't necessary and can be omitted entirely, especially since you are leaving them blank. Otherwise, they would be used for a little bit of extra human-readable metadata on your column definitions.
To get this working with what you have, remove the COMMENT attributes from your index and primary key definitions.
CREATE TABLE IF NOT EXISTS `university`.`CITY` (
`ID_CITY` INT NOT NULL COMMENT '',
`CNAME` TEXT(15) NULL COMMENT '',
`POPULATION` INT NULL COMMENT '',
-- No COMMENT on PK
PRIMARY KEY (`ID_CITY`)
) ENGINE = InnoDB;
CREATE TABLE IF NOT EXISTS `sakila`.`actor` (
`actor_id` SMALLINT UNSIGNED NOT NULL AUTO_INCREMENT COMMENT '',
`first_name` VARCHAR(45) NOT NULL COMMENT '',
`last_name` VARCHAR(45) NOT NULL COMMENT '',
`last_update` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '',
-- No COMMENT on PK or INDEX
PRIMARY KEY (`actor_id`),
INDEX `idx_actor_last_name` (`last_name` ASC)
) ENGINE = InnoDB
DEFAULT CHARACTER SET = utf8;
Or the whole thing without any blank COMMENTs:
CREATE TABLE IF NOT EXISTS `university`.`CITY` (
`ID_CITY` INT NOT NULL COMMENT 'A comment that is not blank!',
`CNAME` TEXT(15) NULL,
`POPULATION` INT NULL,
PRIMARY KEY (`ID_CITY`)
) ENGINE = InnoDB;
(Same for the other table)
MySQL is generally quite good at pointing you directly to the source of your syntax error with the error message:
check the manual that corresponds to your MySQL server version for the right syntax to use near 'COMMENT ''),
With the exception of errors occurring at the end of the statement, which get a little ambiguous, the right syntax to use near will show you exactly what's amiss. In the above case, the COMMENT '') should direct you to the only COMMENT attribute followed by a ), which was the one at PRIMARY KEY. From there, check the manual (linked above) for legal syntax in each segment of your statement.
Remove "VISIBLE" and "INVISIBLE" words from all INDEX
Just started playing with MySQL and I've already made stupid mistake which is somewhere in there; that's what I need to figure out:
CREATE TABLE `txts` (
`ID` INT NOT NULL AUTO_INCREMENT,
`name` VARCHAR(75) NOT NULL,
`content` VARCHAR(MAX) NOT NULL,
`lastupdate` DATE NOT NULL default '0000-00-00',
PRIMARY KEY (`ID`)
)ENGINE=MyISAM DEFAULT CHARSET=utf8;
It gives:
#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 'MAX) NOT NULL,
`lastupdate` DATE NOT NULL default '0000-00-00', PRIMARY KEY ' at line 4
I know it's extremely stupid but I can't see a single mistake in it.
VARCHAR(MAX)
MySQL does not support the use of MAX.
Use an real number value.
Per Google:
The length can be specified as a value from 0 to 255 before MySQL 5.0.3, and 0 to 65,535 in 5.0.3 and later versions.
Noob Alert.
Hi. I'm trying to input this event in mySQL through phpMyAdmin. I'm not sure if the table can be named using YEAR() and MONTHNAME() functions. Even before i could tackle that, this #1064 error has sprouted:
#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 'END' at line 14
Could someone please point out what i'm doing wrong?
Also is it possible to name tables the way I'm trying to?
CREATE EVENT newmonthlytable
ON SCHEDULE EVERY '1' MONTH
STARTS '2012-09-01 00:00:00'
DO
BEGIN
CREATE TABLE IF NOT EXISTS `YEAR()-MONTHNAME()-0-msgs`
(`msgid` int(11) NOT NULL AUTO_INCREMENT PRIMARY KEY,
`sender` int(11) NOT NULL,
`reciever` int(11) NOT NULL,
`sendername` varchar(64) NOT NULL,
`msg` varchar(512) NOT NULL,
`tstamp` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP)
ENGINE = MyISAM, CHARACTER SET = utf8, COLLATE = utf8_bin
END;
There is syntax error, to fix it add ';' at the end of CREATE TABLE statement.
You can name tables as you want, but do you really need it? It is better to think about the db-design, and do not create tables from routines.
SQL query:
CREATE TABLE `comment_threads` (
`comment_id` INT( 11 ) UNSIGNED NOT NULL DEFAULT '0',
`updated` TIMESTAMP NOT NULL ,
`timestamp` TIMESTAMP NOT NULL ,
) ENGINE = MYISAM ;
This is an old file that I'm trying to run on HostGator through phpMyAdmin. I get an error that says:
MySQL said: #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 ') ENGINE=MyISAM' at line 5
UPDATE:
If I change the statement to this, I still get an error:
CREATE TABLE comment_threads (
comment_id INT( 11 ) UNSIGNED NOT NULL DEFAULT '0',
updated TIMESTAMP( 14 ) NOT NULL ,
timestamp TIMESTAMP NOT NULL
PRIMARY KEY ( comment_id ) )
ENGINE = MYISAM ;
I get the 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 '( 14 ) NOT NULL ,
timestamp TIMESTAMP NOT NULL
PRIMARY KEY ( comment_id ) )
ENGI' at line 3
Your MySQL query is incorrect. Correcting it to this works.
CREATE TABLE `comment_threads` (
`comment_id` INT(11) UNSIGNED NOT NULL DEFAULT '0',
`updated` TIMESTAMP NOT NULL ,
`timestamp` TIMESTAMP NOT NULL
) ENGINE=MyISAM;
To run this in phpMyAdmin, you can use the in-built table creator or enter the corrected SQL statement in the SQL query window.
Note that I removed the comma after the last TIMESTAMP NOT NULL line (immediately before the ending ).
UPDATE:
The second statement you posted corrects to this:
CREATE TABLE `comment_threads` (
`comment_id` INT(11) UNSIGNED NOT NULL DEFAULT '0',
`updated` TIMESTAMP NOT NULL ,
`timestamp` TIMESTAMP NOT NULL,
PRIMARY KEY(`comment_id`)
) ENGINE=MyISAM;
Here are the problems you introduced in your second CREATE TABLE statement:
TIMESTAMP( 14 ) should just be TIMESTAMP (per the documentation)
You need a comma after the line TIMESTAMP NOT NULL line. The comma is necessary now because unlike in the first example, you're separated two parts of the statement: the TIMESTAMP NOT NULL line and the PRIMARY KEY declaration.
If you want more information on simple methods for debugging SQL statements, I strongly suggest you look at my answer to this question (see the section titled A bit more information on how to methodically fix errors like this).
Make sure that when you change a CREATE TABLE statement, or any piece of code, that you make changes in small enough increments that you're only "breaking at most one thing at a time." In the case of your second CREATE TABLE statement, there was no reason to change the first TIMESTAMP declaration, and doing so broke the code. That line was working; no need to change it.