MYSQL Error 1064 in DateTime and TimeStamp - mysql

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

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 Primary and Unique Keys

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;

what is my syntax error here in mySQL query?

CREATE TABLE IF NOT EXISTS `creditors` (
`id` int(10) NOT NULL AUTO_INCREMENT PRIMARY KEY,
`name` varchar(50) NOT NULL,
`route` varchar(255) NOT NULL,
`mobile` int(10) NOT NULL,
`credit_amount` double(100) NOT NULL,
`start_date` date NOT NULL,
`due_date` date NOT NULL,
UNIQUE KEY `idUnique` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1
MySQL said: Documentation
#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 ') NOT NULL,
start_date date NOT NULL,
due_date date NOT NULL, ' at line 6
What is my syntax error in this SQL query?
If you set a Column to primary key, it consists only Unique value. Then why did you try to made the same to UNIQUE KEY?
And also Delete the RANGE for Double.
SQLFiddle Example
CREATE TABLE `creditors` (
`id` int NOT NULL AUTO_INCREMENT PRIMARY KEY,
`name` varchar(50) NOT NULL,
`route` varchar(255) NOT NULL,
`mobile` int NOT NULL,
`credit_amount` double NOT NULL,
`start_date` date NOT NULL,
`due_date` date NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1;
The error is with this statement:
`credit_amount` double(100) NOT NULL
Give precision after 100 in double data type.
Solution:
`credit_amount` double(100,0) NOT NULL
Instead of 0 after 100 give number of digits after decimal point.
If you want to use double you must specify both M and D where
M is number digits in total, of which D digits may be after the decimal point, i.e. double(10,0). Otherwise use float which which allows syntax like float(10).
Also, unless you really benefit from this, do not use latin1 charset, but rather UTF-8

create table error in mysql. 1071 error

hi all can some one plz help me,
while creating table in mysql i am getting the following error
MySQL error 1071: Specified key was too long; max key length is 767 bytes
my table definition is as follows.
CREATE TABLE oauth_consumer (id char(36) NOT NULL ,
name varchar(255) NULL ,
date_entered datetime NULL ,
date_modified datetime NULL ,
modified_user_id char(36) NULL ,
created_by char(36) NULL ,
description text NULL ,
deleted bool DEFAULT '0' NULL ,
assigned_user_id char(36) NULL ,
c_key varchar(255) NULL ,
c_secret varchar(255) NULL,
PRIMARY KEY (id),
UNIQUE ckey (c_key)
);
No problem in your query. May be you are running old version of MySql. Use new version. If you are using new version try to use following query to create table
CREATE TABLE `oauth_consumer` (
`id` CHAR(36) NOT NULL,
`name` VARCHAR(255) NULL DEFAULT NULL,
`date_entered` DATETIME NULL DEFAULT NULL,
`date_modified` DATETIME NULL DEFAULT NULL,
`modified_user_id` CHAR(36) NULL DEFAULT NULL,
`created_by` CHAR(36) NULL DEFAULT NULL,
`description` TEXT NULL,
`deleted` TINYINT(1) NULL DEFAULT '0',
`assigned_user_id` CHAR(36) NULL DEFAULT NULL,
`c_key` VARCHAR(255) NULL DEFAULT NULL,
`c_secret` VARCHAR(255) NULL DEFAULT NULL,
PRIMARY KEY (`id`),
UNIQUE INDEX `ckey` (`c_key`)
)
COLLATE='latin1_swedish_ci'
ENGINE=InnoDB;
First of all, your database character set is most likely set to utf8, so your 255 characters get blown up to 765 characters; though close, that's not greater than the imposed limit of 767, but it gives an idea of why you're hitting that limit nonetheless.
Regardless, it's not recommended to use such a wide key; you could calculate an md5 or sha1 of the value and use that for the unique key instead (btw, you should use the binary representation of the hash).

what's wrong with the mysql command?

when i run the following command in phpmyadmin.
CREATE TABLE subscribers (
'subscriber_id' int(11) NOT NULL auto_increment,
'customers_id' int(11) default NULL,
'email_address' varchar(96) NOT NULL default '',
'email_format' varchar(4) NOT NULL default 'TEXT',
PRIMARY KEY ('subscriber_id')
) TYPE=MyISAM;
it shows me #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 ''subscriber_id' int(11) NOT NULL auto_increment, 'customers_id' int(11) defaul' at line 2
INSERT INTO query_builder (query_id, query_category, query_name, query_description, query_string, query_keys_list) VALUES (6, 'email,newsletters', 'All Newsletter Subscribers', 'Returns name and email address of all Customer Account subscribers and all Newsletter-Only subscribers.', 'select c.customers_firstname, c.customers_lastname, s.email_address as customers_email_address from TABLE_SUBSCRIBERS as s left join TABLE_CUSTOMERS as c on c.customers_id = s.customers_id ', '')
it shows :
1062 - Duplicate entry '6' for key 1
i fell the command is right. i don't know how to correct it? thank you.
You don't need the single quote around the column name. Remove that.
This should be
CREATE TABLE subscribers (
subscriber_id int(11) NOT NULL auto_increment,
customers_id int(11) default NULL,
email_address varchar(96) NOT NULL default '',
email_format varchar(4) NOT NULL default 'TEXT',
PRIMARY KEY (subscriber_id)
) TYPE=MyISAM;
Although, You can enclose the column name in backticks if that is conflicting with the mysql reserved words.
You should not use strings as column names. Also it is ENGINE not TYPE.
It should look like:
CREATE TABLE subscribers (
subscriber_id int(11) NOT NULL auto_increment,
customers_id int(11) default NULL,
email_address varchar(96) NOT NULL default '',
email_format varchar(4) NOT NULL default 'TEXT',
PRIMARY KEY (subscriber_id)
) ENGINE=MyISAM;
Just removing the quotes around the column name, and changing the last bit to Engine=MyISAM worked for me:
CREATE TABLE subscribers (
subscriber_id int(11) NOT NULL auto_increment,
customers_id int(11) default NULL,
email_address varchar(96) NOT NULL default '',
email_format varchar(4) NOT NULL default 'TEXT',
PRIMARY KEY (subscriber_id)
) Engine=MyISAM;