Syntax error keeping me from creating a new table - mysql

I am trying to create a SQL table into which I will later import data from a csv file. I'm getting an error when I try to create the table but I have no idea what I'm doing wrong. Here is my SQL code:
CREATE TABLE `table_name`. (
`YID` INT(8) NOT NULL AUTO_INCREMENT ,
`AST` INT(4) NOT NULL ,
`KID` INT(5) NOT NULL ,
`PKD` INT(12) NULL ,
`LAT` DOUBLE(8,6) NULL ,
`LNG` DOUBLE(8,6) NULL ,
`KOGnim` VARCHAR(50) ,
`PST` INT ,
`ESI` INT ,
`PLK` VARCHAR(50),
`PRE` INT,
`LKM` INT,
PRIMARY KEY (`YID`)
) ENGINE = MyISAM;
And here is the error message:
#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 '(
`YID` INT(8) NOT NULL AUTO_INCREMENT ,
`AST` INT(4) NOT NULL ,
' at line 1
I'm running mySQL v5.7

Found it! It was the period after table_name

I think that this will do the trick
CREATE TABLE `table_name` (
`YID` INT(8) NOT NULL AUTO_INCREMENT ,
`AST` INT(4) NOT NULL ,
`KID` INT(5) NOT NULL ,
`PKD` INT(12) NULL ,
`LAT` DOUBLE(8,6) NULL ,
`LNG` DOUBLE(8,6) NULL ,
`KOGnim` VARCHAR(50) ,
`PST` INT ,
`ESI` INT ,
`PLK` VARCHAR(50),
`PRE` INT,
`LKM` INT,
PRIMARY KEY(`YID`)
) ENGINE = MyISAM;

Related

How to resolve an error near NULL when creating a table

Whenever I try to create a table
CREATE TABLE registration` (`id` INT NOT NULL , `name` VARCHAR(30) NOT NULL , `email` VARCHAR(20) NOT NULL , `password` VARCHAR(15) NOT NULL , `DOB` DATE NOT NULL , `age` INT NOT NULL , `number` BIGINT NOT NULL , `religion` VARCHAR(10) NOT NULL , `education` VARCHAR(20) NOT NULL , `profession` VARCHAR(20) NOT NULL , `gender` ENUM NOT NULL , PRIMARY KEY (`id`)) ENGINE = InnoDB;
The following error occurs
#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 , PRIMARY KEY (id)) ENGINE = InnoDB' at line 1
ENUM needs values so you need to define the values they can get
CREATE TABLE registration (
`id` INT NOT NULL
, `name` VARCHAR(30) NOT NULL
, `email` VARCHAR(20) NOT NULL
, `password` VARCHAR(15) NOT NULL
, `DOB` DATE NOT NULL
, `age` INT NOT NULL
, `number` BIGINT NOT NULL
, `religion` VARCHAR(10) NOT NULL
, `education` VARCHAR(20) NOT NULL
, `profession` VARCHAR(20) NOT NULL
, `gender` ENUM ('male','female')
, PRIMARY KEY (`id`)
) ENGINE = InnoDB;
When you declare a ENUM column (your gender column) you have to assign all possible values for the enumeration (See here for syntax)

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;

Having an error in sql while creating table

I am trying to create a table on my database. this is the 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 ') NOT NULL , `ctc` DOUBLE(5) NOT NULL , `ref` VARCHAR(50) NOT NULL , `date` D' at line 1
My query:
CREATE TABLE `job`.`form_details` (
`email_id` VARCHAR(50) NOT NULL ,
`name` VARCHAR(50) NOT NULL ,
`number` VARCHAR(14) NOT NULL ,
`city` VARCHAR(50) NOT NULL ,
`skill` VARCHAR(50) NOT NULL ,
`qualification` VARCHAR(50) NOT NULL ,
`position` VARCHAR(50) NOT NULL ,
`exp` DOUBLE(5) NOT NULL ,
`ctc` DOUBLE(5) NOT NULL ,
`ref` VARCHAR(50) NOT NULL ,
`date` DATE NOT NULL ,
`time stamp` TIMESTAMP(30) NOT NULL ) ENGINE = InnoDB;
A double's precision is specified by two arguments - (M, D) - M digits in total and D digits after the decimal point. A timestamp's precision must be no greater than 6. So:
CREATE TABLE `job`.`form_details` (
`email_id` VARCHAR(50) NOT NULL ,
`name` VARCHAR(50) NOT NULL ,
`number` VARCHAR(14) NOT NULL ,
`city` VARCHAR(50) NOT NULL ,
`skill` VARCHAR(50) NOT NULL ,
`qualification` VARCHAR(50) NOT NULL ,
`position` VARCHAR(50) NOT NULL ,
`exp` DOUBLE(5, 2) NOT NULL , -- Two arguments for the double's precision
`ctc` DOUBLE(5, 2) NOT NULL , -- Here too
`ref` VARCHAR(50) NOT NULL ,
`date` DATE NOT NULL ,
`time stamp` TIMESTAMP(6) NOT NULL -- Timestamp precision capped at 6
) ENGINE = InnoDB

What does the engine and char set means after the ()?

DROP DATABASE IF EXISTS `Database` ;
CREATE DATABASE `Database` ;
DROP TABLE IF EXISTS `Registration Form` ;
CREATE TABLE `Registration Form`
(
`ID` int(11) NOT NULL AUTO_INCREMENT ,
`Username` varchar(50) NOT NULL ,
`Password` varchar(50) NOT NULL ,
`Display Name` varchar(255) NOT NULL ,
`Question` varchar(255) NOT NULL ,
`Answer` varchar(255) NOT NULL ,
`Title` varchar(10) NOT NULL ,
`Name` varchar(255) NOT NULL ,
`Date Of Birth` date NOT NULL ,
`Gender` varchar(10) NOT NULL ,
`Address` varchar(255) NOT NULL ,
`Postal Code` int(11) NOT NULL ,
`City / Town` varchar(255) NOT NULL ,
`Federal Territory / State` varchar(255) NOT NULL ,
`Citizenship` varchar(255) NOT NULL ,
`E-mail` varchar(255) NOT NULL ,
`Contact Number` int(20) NOT NULL ,
`Registration Date` datetime NOT NULL ,
PRIMARY KEY ( `ID` )
) ENGINE=MyISAM DEFAULT CHARSET=latin1 ;
I'm just starting to work arounnd mysql and php ... so bear with me as im a newbie ...
What does ALL the code after the CREATE() mean ? Why is there a ENGINE and DEFAULT what do they do ? Is CHARSET same as collation , if yes why not put it inside the row instead ? Do you need to give a length/value for date and daetime ?
CREATE TABLE is the sql clause which is required to creating a table.
After that you have to give a table name i.e "Registration Form" .but avoid spaces in between table name
Next what ever you gave those are column name along with their datatype and size.NOT NULL means while inserting data those column can't be blank.
For more details check the below link
http://www.tutorialspoint.com/mysql/mysql-create-tables.htm