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.
Related
This is the code
CREATE TABLE `church` (
`ID` int(10) UNSIGNED NOT NULL,
`StudentID` int(11) NOT NULL,
`semesterID` int(11) NOT NULL,
`attendedWed` int(11) NOT NULL,
`attendedFri` int(11) NOT NULL,
`attendedSabM` int(11) NOT NULL,
`attendedSabE` int(11) NOT NULL,
`ChurchScore` double(10,2) GENERATED ALWAYS AS ((((((`attendedWed` + `attendedFri`) + `attendedSabM`) + `attendedSabE`) * 100) / 60)) STORED
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
This is the error
Operation failed: There was an error while applying the SQL script to
the database. Executing: ALTER TABLE citizenshipgroup3.church
CHANGE COLUMN ChurchScore ChurchScore DOUBLE(10,2) NULL DEFAULT
attendedWed ;
ERROR 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 'attendedWed' at line 2 SQL Statement: ALTER TABLE
citizenshipgroup3.church CHANGE COLUMN ChurchScore
ChurchScore DOUBLE(10,2) NULL DEFAULT attendedWed
Your syntax is fine. The problem is that MySQL does not support generated columns until 5.7. You are presumably using an earlier version.
Probably the simplest solution is to use a view for the calculation.
The error appears at the time of ALTER TABLE, when you are trying to modify the column ChurchScore setting the DEFAULT value to an expression involving another Column attendedWed.
Also, your error message seems to be originating from MariaDB, not MySQL.
From Mariadb Documentation:
From MariaDB 10.2.1 you can use most functions in DEFAULT. Expressions
should have parentheses around them. If you use a non deterministic
function in DEFAULT then all inserts to the table will be replicated
in row mode. You can even refer to earlier columns in the DEFAULT
expression:
CREATE TABLE t1 (a int DEFAULT (1+1), b int DEFAULT (a+1));
CREATE TABLE t2 (a bigint primary key DEFAULT UUID_SHORT());
So you need to ensure couple of things:
Upgrade your MariaDB version to 10.2.1 and above. Preferably, upgrade to current latest version (it is 10.3+ right now).
You need to use parentheses around the expression specified in the DEFAULT clause.
So the ALTER TABLE statement would look like:
ALTER TABLE `citizenshipgroup3`.`church`
CHANGE COLUMN `ChurchScore` `ChurchScore` DOUBLE(10,2) NULL
DEFAULT (attendedWed) ;
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.
Please have a look in below SQL code
DROP TABLE IF EXISTS `xxx`.`reminder` ;
CREATE TABLE IF NOT EXISTS `xxx`.`reminder` (
`idreminder` INT NOT NULL AUTO_INCREMENT,
`patient_idpatient` INT NOT NULL,
`remind_about` TEXT NOT NULL,
`reminder_time` TIME NOT NULL,
`reminder_date` DATE NOT NULL,
`active` TINYINT(1) NOT NULL,
`repeat_action` TINYINT(1) NOT NULL,
`date_created` TIMESTAMP NULL,
`last_updated` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (`idreminder`),
INDEX `fk_Reminder_patient1_idx` (`patient_idpatient` ASC),
CONSTRAINT `fk_Reminder_patient1`
FOREIGN KEY (`patient_idpatient`)
REFERENCES `myglukose`.`patient` (`idpatient`)
ON DELETE CASCADE
ON UPDATE NO ACTION)
ENGINE = InnoDB;
When I copy this into PhpMyAdmin, I get 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 '`
I have 2 questions.
I really don't spot the error, what is it?
Important thing is that these auto generated SQL code from MySQL Work Bench!! All of these worked very well in Windows with XAMPP and all these issues are with Ubuntu running LAMP.Not only this error,in some tables I am also getting the error #1293 - Incorrect table definition; there can be only one TIMESTAMP column with CURRENT_TIMESTAMP in DEFAULT or ON UPDATE clause
Why all of this with Ubuntu (14.04)? I installed LAMP by following this - http://devoncmather.com/setting-aws-ec2-instance-lamp-git/
How to fix this, if any issue with installation, any recommended alternate tutorial?
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.
would really like some help trying to figure out what I am doing wrong here. I have searched through several other questions but could not find anything wrong in my CREATE statement that others had.
CREATE TABLE Client(
'Client_ID' INT NOT NULL AUTO_INCREMENT,
'Client_Name' VARCHAR(30) NOT NULL,
'Class' VARCHAR(50) NOT NULL,
'Pre-Billing' BOOLEAN NOT NULL DEFAULT 0,
'Email' VARCHAR(100),
'Phone_Number' VARCHAR(30) NOT NULL,
'Address' VARCHAR(150) NOT NULL,
'Last_Updated' timestamp default now() on update now(),
'Date_Added' timestamp default now(),
PRIMARY KEY ('Client_ID')
);
The error I am getting is
Error Code: 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 ''Client_ID' INT NOT NULL AUTO_INCREMENT, 'Client_Name' VARCHAR (30) NOT NULL, ' at line 2
If you could please advise that would be greatly appreciated, thank you.
If you remove the single quotes around the column names and change the hyphen in "Pre-Billing" to an underscore "Pre_Billing", this should fix it.