MYSQL Error 1064 in Primary and Unique Keys - mysql

Good day. I am trying to add a suppliers table on my database and when i try to save, it throws this 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) NOT NULL , PRIMARY KEY (supp_id), UNIQUE supp_name (supp_name))' at line 1
I have attached my SQL statement.
CREATE TABLE `project_inv`.`suppliers` (
`supp_id` INT(11) NOT NULL AUTO_INCREMENT ,
`supp_name` VARCHAR(255) NOT NULL ,
`supp_addr` VARCHAR(300) NOT NULL ,
`supp_phone` INT(20) NOT NULL ,
`supp_email` VARCHAR(255) NOT NULL ,
`supp_notes` VARCHAR(1000) NOT NULL ,
`status` ENUM(0) NOT NULL ,
PRIMARY KEY (`supp_id`),
UNIQUE `supp_name` (`supp_name`)
) ENGINE = InnoDB;
I think its something with my UNIQUE key but i really can't figure out what the error is. Any form of help will be appreciated. Thanks

It is not about the PRIMARY or UNIQUE declaration, but about ENUM(): it expects string literals, so you would need to surround the values in the list with single quotes:
CREATE TABLE `project_inv`.`suppliers` (
`supp_id` INT(11) NOT NULL AUTO_INCREMENT ,
`supp_name` VARCHAR(255) NOT NULL ,
`supp_addr` VARCHAR(300) NOT NULL ,
`supp_phone` INT(20) NOT NULL ,
`supp_email` VARCHAR(255) NOT NULL ,
`supp_notes` VARCHAR(1000) NOT NULL ,
`status` ENUM('0') NOT NULL ,
PRIMARY KEY (`supp_id`),
UNIQUE `supp_name` (`supp_name`)
) ENGINE = InnoDB;
However having a non-nullable ENUM() column with just one value allowed makes little sense - basically you are forcing every row to have the same value ('0'). So either add more values to the list... or just remove the column.

try like below by using string inside enum i used 'N' instated 0
CREATE TABLE `project_inv`.`suppliers` (
`supp_id` INT(11) NOT NULL AUTO_INCREMENT ,
`supp_name` VARCHAR(255) NOT NULL ,
`supp_addr` VARCHAR(300) NOT NULL ,
`supp_phone` INT(20) NOT NULL ,
`supp_email` VARCHAR(255) NOT NULL ,
`supp_notes` VARCHAR(1000) NOT NULL ,
`status` ENUM('N') NOT NULL ,
PRIMARY KEY (`supp_id`),
UNIQUE `supp_name` (`supp_name`)
) ENGINE = InnoDB;

Related

I see similar questions but still doesn't solve mine so my question is how do i solve the following error?

code picture with an error #1064
SQL query:
CREATE TABLE `simzsy`.`membership` (
`memberid` INT NOT NULL ,
`name` TEXT NOT NULL ,
`surname` TEXT NOT NULL ,
`dateofbirth` DATE NOT NULL ,
`id` LONGTEXT NOT NULL ,
`contact` LONGTEXT NOT NULL ,
`datejoined` DATE NOT NULL ,
`membertype` ENUM NOT NULL ,
PRIMARY KEY ( `memberid` )
) ENGINE = MYISAM
MySQL said: Documentation
#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, PRIMARY KEY (memberid)) ENGINE = MyISAM' at line 1
The query should look like this:
CREATE TABLE `simzsy`.`membership` (
`memberid` INT NOT NULL ,
`name` TEXT NOT NULL ,
`surname` TEXT NOT NULL ,
`dateofbirth` DATE NOT NULL ,
`id` LONGTEXT NOT NULL ,
`contact` LONGTEXT NOT NULL ,
`datejoined` DATE NOT NULL ,
`membertype` ENUM('normal','admin','some_other_kind') default 'normal',
PRIMARY KEY ( `memberid` )
) ENGINE = MYISAM
So you enumerate all the possible values and set default value that is set if nothing is selected (instead of not null)

MYSQL Error 1064 in DateTime and TimeStamp

Good day, I'm creating some tables on my database and when i try to save, it throws this 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) NOT NULL , date_registered DATETIME NOT NULL , last_login TIMESTAMP NOT' at line 1
This sort of error has been debugged here on Stackoverflow before and the solution was to remove the length from the TIMESTAMP column. Other solutions asked the advised that quotes should be removed from column identifiers or ticks should be used instead. Unfortunately, my DATETIME and TIMESTAMP columns do not have lengths and my column identifiers have ticks around them.
Here's what my SQL statement looks like. Can someone please assist?
CREATE TABLE `inventoryman_db`.`users`
( `id` INT NOT NULL AUTO_INCREMENT ,
`full_name` VARCHAR(255) NOT NULL ,
`email` VARCHAR(255) NOT NULL ,
`password` VARCHAR(300) NOT NULL ,
`usertype` ENUM(0) NOT NULL ,
`date_registered` DATETIME NOT NULL ,
`last_login` TIMESTAMP NOT NULL ,
`notes` VARCHAR(255) NOT NULL COMMENT 'For verification and other purposes, we will store a random key here' ,
PRIMARY KEY (`id`))
ENGINE = InnoDB;
try this, you only need to add quotes in enum('0') as enum consider as string with indexing his arrays.
CREATE TABLE `percept`.`users1` ( `id` INT NOT NULL AUTO_INCREMENT ,
`full_name` VARCHAR(255) NOT NULL , `email` VARCHAR(255) NOT NULL ,
`password` VARCHAR(300) NOT NULL ,
`usertype` ENUM('0') NOT NULL ,
`date_registered` DATETIME NOT NULL ,
`last_login` TIMESTAMP NOT NULL ,
`notes` VARCHAR(255) NOT NULL COMMENT 'For verification and other purposes, we will store a random key here' ,
PRIMARY KEY (`id`)) ENGINE = InnoDB `
just add quotes in enum

I keep getting this MySQL error Incorrect prefix key #1089 [duplicate]

This question already has answers here:
I keep getting this mysql error code #1089
(4 answers)
Closed 5 years ago.
This message showing when i try to create a table.
#1089 - Incorrect prefix key; the used key part isn't a string, the used length is longer than the key part, or the storage engine doesn't support unique prefix keys
This is my query:
CREATE TABLE `xyz`.`company_info` ( `c_id` INT(10) NOT NULL AUTO_INCREMENT , `cname` VARCHAR(50) NOT NULL , `ctitle` VARCHAR(100) NOT NULL , `cestab` VARCHAR(20) NOT NULL , `cfounder` VARCHAR(50) NOT NULL , `caddress` VARCHAR(200) NOT NULL , `ccontact` VARCHAR(20) NOT NULL , `cemail` VARCHAR(50) NOT NULL , `cweb` VARCHAR(50) NOT NULL , `clogo` VARCHAR(100) NOT NULL , `status` INT(10) NOT NULL , `created_on` TIMESTAMP NOT NULL , PRIMARY KEY (`c_id`(10))) ENGINE = InnoDB;
Replace:
PRIMARY KEY (`c_id`(10))
with:
PRIMARY KEY (`c_id`)
You already give the length when you define the field, you don't need to give it again in the primary key definition.

Trying to create a table in phpmyadmin

So im trying to create this table but im getting a #1064 eroor message. Here is my code: CREATE TABLE JagBank.AccountType ( typeID INT(4) NOT NULL , type VARCHAR(15) NULL , interestRate DOUBLE(4) NULL , PRIMARY KEY (typeID)) ENGINE = InnoDB;
I'm new to php but I was pretty sure this was correct? Whats the problem?
for table jagbank.accounttype
CREATE TABLE IF NOT EXISTS `jagbank.accounttype` (
`typeID` int(11) NOT NULL,
`type` varchar(15) COLLATE latin1_general_ci DEFAULT NULL,
`interestRate` double DEFAULT NULL,
PRIMARY KEY (`typeID`)
) ENGINE=InnoDB
just remove size for double data type,
double data type not having size try query below,
CREATE TABLE JagBank.AccountType ( typeID INT(4) NOT NULL , type VARCHAR(15) NULL , interestRate DOUBLE NULL , PRIMARY KEY (typeID)) ENGINE = InnoDB;

mysql foreign keys

Hello I have two mysql tables one that holds username and password second that holds user information. Here are the tables:
CREATE TABLE IF NOT EXISTS `test`.`dbo.users` (
`userId` INT(11) NOT NULL AUTO_INCREMENT ,
`userUsername` VARCHAR(45) NULL ,
`userPassword` VARCHAR(45) NULL ,
`dbo.userProfiles_userProfileId` INT(11) NOT NULL ,
PRIMARY KEY (`userId`, `dbo.userProfiles_userProfileId`) ,
INDEX `fk_dbo.users_dbo.userProfiles` (`dbo.userProfiles_userProfileId` ASC) ,
CONSTRAINT `fk_dbo.users_dbo.userProfiles`
FOREIGN KEY (`dbo.userProfiles_userProfileId` )
REFERENCES `test`.`dbo.userProfiles` (`userId` )
ON DELETE CASCADE
ON UPDATE CASCADE)
ENGINE = InnoDB;
CREATE TABLE IF NOT EXISTS `test`.`dbo.userProfiles` (
`userProfileId` INT(11) NOT NULL AUTO_INCREMENT ,
`userId` INT(11) NOT NULL ,
`userFirstName` VARCHAR(45) NULL ,
`userMidleName` VARCHAR(45) NULL ,
`userLastName` VARCHAR(45) NULL ,
`userBirthDate` VARCHAR(45) NULL ,
`userCountry` VARCHAR(45) NULL ,
`userState` VARCHAR(45) NULL ,
`userCity` VARCHAR(45) NULL ,
`userZipCode` VARCHAR(45) NULL ,
`userPrimaryAddress` VARCHAR(45) NULL ,
`userSecondaryAddress` VARCHAR(45) NULL ,
`userThirdAddress` VARCHAR(45) NULL ,
`userFirstPhone` VARCHAR(45) NULL ,
`userSecondaryPhone` VARCHAR(45) NULL ,
`userThirdPhone` VARCHAR(45) NULL ,
`userFirstEmail` VARCHAR(45) NULL ,
`userSecondaryEmail` VARCHAR(45) NULL ,
`userThirdEmail` VARCHAR(45) NULL ,
`userDescription` VARCHAR(45) NULL ,
PRIMARY KEY (`userProfileId`, `userId`) )
ENGINE = InnoDB;
My problem with this tables is that the fk key doesn't work and I'm not sure why I'm missing something here.. ( I haven't used foreign keys much).
Error:
Executing SQL script in server
ERROR: Error 1005: Can't create table 'test.dbo.users' (errno: 150)
Can you please help fixing this so I can use fk on this tables and others? and if you got some time to spare to explain me how fk keys work exactly (using mysql workbench to create them on a diagram then forward engineer). thank you for your help
You have to create the root tables first (userProfiles). You can temporarily bypass this restriction by disabling foreign key checks with set foreign_key_checks=0. This must be done if you're creating multiple tables with circular references.