MySQL error 1064 on creating a table query - php

CREATE TABLE `chuchutvlogin`. (
`id` INT NOT NULL AUTO_INCREMENT ,
`username` VARCHAR(20) NOT NULL ,
`gender` CHAR(1) NOT NULL ,
`email` VARCHAR(50) NOT NULL ,
`password` VARCHAR(20) NOT NULL ,
`number` BIGINT(10) NOT NULL ,
PRIMARY KEY (`id`)
) ENGINE = InnoDB;
what's issue?
i was creating a login databse and error #1064 came syntax error in localhost phpmyadmnin

Fix syntax error in your query, remove dot char after table name:
CREATE TABLE chuchutvlogin (
id INT NOT NULL AUTO_INCREMENT,
username VARCHAR(20) NOT NULL,
gender CHAR(1) NOT NULL,
email VARCHAR(50) NOT NULL,
password VARCHAR(20) NOT NULL,
number BIGINT(10) NOT NULL,
PRIMARY KEY (id)
) ENGINE = InnoDB;
dbfiddle

Related

"a symbol name was expected" error trying to create a table in phpMyAdmin

I am trying to create a table in a database in phpMyAdmin and I keep getting the "a symbol name was expected" error and I cannot figure out what is going on. Is my syntax wrong? I am new to this and I'm at a loss.
Column names, table names should be surrounded by backticks(``)
CREATE TABLE IF NOT EXISTS `sales` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(50) NOT NULL,
`item` varchar(50) NOT NULL,
`date` varchar(50) NOT NULL,
`amount` int(11) NOT NULL,
PRIMARY KEY (`id`)
)
Or you can go without backticks as well:
CREATE TABLE IF NOT EXISTS sales (
id int(11) NOT NULL AUTO_INCREMENT,
name varchar(50) NOT NULL,
item varchar(50) NOT NULL,
date varchar(50) NOT NULL,
amount int(11) NOT NULL,
PRIMARY KEY (id)
)
Your code is wrong , So here is the correct Code :
CREATE TABLE IF NOT EXISTS `sales` (
`id` INT(11) NOT NULL AUTO_INCREMENT PRIMARY KEY,
`name` VARCHAR(50) CHARACTER SET utf8 NOT NULL,
`item` VARCHAR(50) CHARACTER SET utf8 NOT NULL,
`date` VARCHAR(50) NOT NULL,
`amount` int(11) NOT NULL
)
You used ' ' sign in your column properties. But mySQL allow you to use `` sign.
CREATE TABLE IF NOT EXISTS `sales` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(50) NOT NULL,
`item` varchar(50) NOT NULL,
`date` varchar(50) NOT NULL,
`amount` int(11) NOT NULL,
PRIMARY KEY (`id`)
);

Dynamic table using parameter or variable in table name cakephp

I am creating a dynamic table using mysql query table name should be unique that's why i have added user id to table name.
In Controller:
$last_id = $this->User->getLastInsertID();
//$table_name = 'hello_'.$last_id.'_tutors';
// debug($table_name);
$this->User->query("CREATE TABLE IF NOT EXISTS `post_`.$last_id.`_tutors` (
`id` int(8) NOT NULL AUTO_INCREMENT,
`user_id` int(8) NOT NULL,
`tutor_name` varchar(50) NOT NULL,
`tutor_email` varchar(50) NOT NULL,
`tutor_number` varchar(50) NOT NULL,
`tutor_gender` varchar(50) NOT NULL,
`tutor_address` varchar(100) NOT NULL,
`city_id` int(11) NOT NULL,
`area_id` int(11) NOT NULL,
`matric` varchar(200) NOT NULL,
`inter` varchar(200) NOT NULL,
`graduation` varchar(200) NOT NULL,
`masters` varchar(200) NOT NULL,
`diploma` varchar(200) NOT NULL,
`other_education` varchar(200) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=67 ;
");
it gave syntax error like:
Syntax error or access violation: 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 '.75._tutors ( tutor_name
varchar(50) NOT NULL, tutor_email var' at line 1
if anyone may help. Thanks in advance.
Try using
$this->User->query("CREATE TABLE IF NOT EXISTS `post_".$last_id."_tutors` (

Incorrect prefix key MySQL [duplicate]

This question already has answers here:
What is wrong with my SQL here? #1089 - Incorrect prefix key
(15 answers)
Closed 7 years ago.
I have a problem creating a table with phpmyadmin, which gives me the following error:
#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 the query that I do:
CREATE TABLE `b2b`.`users` ( `id` BIGINT NOT NULL AUTO_INCREMENT ,
`name` VARCHAR(30) NOT NULL ,
`surnames` VARCHAR(80) NOT NULL ,
`birthdate` DATE NOT NULL ,
`drivingdoc` VARCHAR(20) NOT NULL ,
`acdate` DATE NOT NULL ,
`countrydoc` VARCHAR(20) NOT NULL ,
`province` VARCHAR(20) NOT NULL ,
`locality` VARCHAR(35) NOT NULL ,
`address` VARCHAR(150) NOT NULL ,
`number` VARCHAR(20) NOT NULL ,
`flat` VARCHAR(20) NOT NULL ,
`door` VARCHAR(20) NOT NULL ,
`description` VARCHAR(2000) NOT NULL ,
PRIMARY KEY (`id`(7))) ENGINE = InnoDB;
Using MariaDB in ubuntu minimal.
The problem is:
PRIMARY KEY (`id`(7))
You cannot use part of a number as a key, you have to use the whole thing. Also, specifying lengths for numeric types is useless at best, and damaging at worst.
Change to:
PRIMARY KEY (`id`)
That Primary Key syntax is nothing I've ever seen before. Try this:
CREATE TABLE `b2b`.`users` (
`id` BIGINT NOT NULL AUTO_INCREMENT PRIMARY KEY,
....
) ENGINE = InnoDB;
Or if you want
CREATE TABLE `b2b`.`users` (
`id` BIGINT NOT NULL AUTO_INCREMENT,
....
PRIMARY KEY (id)
) ENGINE = InnoDB;
You have several errors in your sql, so try to find the difference with this sql
CREATE TABLE `b2b`.`users` ( `id` INT(7) NOT NULL AUTO_INCREMENT ,
`name` VARCHAR(30) NOT NULL ,
`surnames` VARCHAR(80) NOT NULL ,
`birthdate` DATE NOT NULL ,
`drivingdoc` VARCHAR(20) NOT NULL ,
`acdate` DATE NOT NULL ,
`countrydoc` VARCHAR(20) NOT NULL ,
`province` VARCHAR(20) NOT NULL ,
`locality` VARCHAR(35) NOT NULL ,
`address` VARCHAR(150) NOT NULL ,
`number` VARCHAR(20) NOT NULL ,
`flat` VARCHAR(20) NOT NULL ,
`door` VARCHAR(20) NOT NULL ,
`description` VARCHAR(255) NOT NULL ,
PRIMARY KEY (`id`)) ENGINE = InnoDB;

I got error while entering the primary key in database

Right now, i've created database with having 10 columns in my database but i can't create the database table and i got "#1067 - Invalid default value for 'primary_key" error.
Here is my sql code:
CREATE TABLE `quiz`.`user_details` ( `primary_key` INT(6) UNSIGNED NOT NULL DEFAULT '1' AUTO_INCREMENT , `foreign_key` INT(6) UNSIGNED NOT NULL DEFAULT '1' AUTO_INCREMENT , `firstname` VARCHAR(20) NOT NULL , `lastname` VARCHAR(20) NOT NULL , `username` VARCHAR(20) NOT NULL , `password` VARCHAR(20) NOT NULL , `email` VARCHAR(20) NOT NULL , `phone_number` INT(10) NOT NULL , `address` CHAR(50) NOT NULL , `exam_taking` INT(3) NOT NULL AUTO_INCREMENT , PRIMARY KEY (`primary_key`(6)), UNIQUE `foreign_key` (`foreign_key`)) ENGINE = InnoDB;
Don't add DEFAULT value because you already defined primary key as AUTO INCREMENT.
Possible duplicate.
#1067 - Invalid default value for 'bonusid' how can i fix this error?
You cannot have a default value for auto incrementing fields. Simply change the definition to:
CREATE TABLE `quiz`.`user_details`
(`primary_key` INT(6) UNSIGNED NOT NULL AUTO_INCREMENT,
`foreign_key` INT(6) UNSIGNED NOT NULL AUTO_INCREMENT ,
`firstname` VARCHAR(20) NOT NULL ,
`lastname` VARCHAR(20) NOT NULL ,
`username` VARCHAR(20) NOT NULL ,
`password` VARCHAR(20) NOT NULL ,
`email` VARCHAR(20) NOT NULL ,
`phone_number` INT(10) NOT NULL ,
`address` CHAR(50) NOT NULL ,
`exam_taking` INT(3) NOT NULL AUTO_INCREMENT ,
PRIMARY KEY (`primary_key`),
UNIQUE `foreign_key` (`foreign_key`)) ENGINE = InnoDB;
Note also that a name foreign_key for an attribute which is not a foreign key is really misleading.

Mysql error #1064

I am trying to create some tables on phpMyAdmin, but when I use the code below I am getting 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 '(32) NOT NULL,
activated enum(0,1) NOT NULL,
PRIMARY KEY (id)
) E' at line 8
Here is my code:
CREATE TABLE IF NOT EXISTS `users` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`username` varchar(255) NOT NULL,
`first_name` varchar(255) NOT NULL,
`last_name` varchar(255) NOT NULL,
`email` varchar(255) NOT NULL,
`password` varchar(255) NOT NULL,
`sign_up_date` date(32) NOT NULL,
`activated` enum(`0`,`1`) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=1atin1 AUTO_INCREMENT=1 ;
Try following code. I have resolved your mistakes in code
CREATE TABLE IF NOT EXISTS `users` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`username` varchar(255) NOT NULL,
`first_name` varchar(255) NOT NULL,
`last_name` varchar(255) NOT NULL,
`email` varchar(255) NOT NULL,
`password` varchar(255) NOT NULL,
`sign_up_date` date NOT NULL,
`activated` enum('0','1') NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;
DATE data type takes no length
`sign_up_date` DATE NOT NULL

Categories