MySQL error while trying to create table, - mysql

I'm using PHPMyAdmin, hosted with hostgator, to add a table to a database, but I keep 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 ') NOT NULL , note TEXT NOT NULL , cardNumber BIGINT(20) NOT NULL , `nameC' at line 1
Here's what I have:
and here's the preview of the SQL
CREATE TABLE `nightwin_mark-inn`.`guests` (
`id` INT(3) NOT NULL AUTO_INCREMENT ,
`dateIn` DATE NOT NULL ,
`dateOut` DATE NOT NULL ,
`email` TEXT NOT NULL ,
`phone` INT(10) NOT NULL ,
`room` TINYINT(2) NOT NULL ,
`price` DOUBLE(6) NOT NULL ,
`note` TEXT NOT NULL ,
`cardNumber` BIGINT(20) NOT NULL ,
`nameCard` TEXT NOT NULL ,
`expDate` TEXT NOT NULL ,
`cvc` TINYINT(3) NOT NULL ,
PRIMARY KEY (`id`)
)
What's causing this issue? Do I have the length of one of the fields wrong?

Try to use this
price` DOUBLE(6,2) NOT NULL //9999.99 max value stored
instead of
price` DOUBLE(6) NOT NULL
Note: for price field use datatype DECIMAL more preferable. In FLOAT or DOUBLE datatype you will get rounding number issue
Reference

You can try below - DOUBLE(6) should be only DOUBLE
CREATE TABLE `nightwin_mark-inn`.`guests` ( `id` INT(3) NOT NULL AUTO_INCREMENT ,
`dateIn` DATE NOT NULL , `dateOut` DATE NOT NULL , `email` TEXT NOT NULL ,
`phone` INT(10) NOT NULL , `room` TINYINT(2) NOT NULL , `price` DOUBLE NOT NULL ,
`note` TEXT NOT NULL , `cardNumber` BIGINT(20) NOT NULL , `nameCard` TEXT NOT NULL ,
`expDate` TEXT NOT NULL , `cvc` TINYINT(3) NOT NULL , PRIMARY KEY (`id`))

please try using this MySQL statement
CREATE TABLE `guests` ( `id` INT(3) NOT NULL AUTO_INCREMENT , `dateIn` DATE NOT NULL , `dateOut` DATE NOT NULL , `email` TEXT NOT NULL , `phone` INT(10) NOT NULL , `room` TINYINT(2) NOT NULL , `price` DOUBLE(6,2) NOT NULL , `note` TEXT NOT NULL , `cardNumber` BIGINT(20) NOT NULL , `nameCard` TEXT NOT NULL , `expDate` TEXT NOT NULL , `cvc` TINYINT(3) NOT NULL , PRIMARY KEY (`id`));

please try using this MySQL statement
CREATE TABLE guests ( id INT(3) NOT NULL AUTO_INCREMENT , dateIn DATE NOT NULL , dateOut DATE NOT NULL , email TEXT NOT NULL , phone INT(10) NOT NULL , room TINYINT(2) NOT NULL , price DOUBLE(6,2) NOT NULL , note TEXT NOT NULL , cardNumber BIGINT(20) NOT NULL , nameCard TEXT NOT NULL , expDate TEXT NOT NULL , cvc TINYINT(3) NOT NULL , PRIMARY KEY (id));

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)

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

SQL Error when creating a table

I have a problem when I run this SQL query:
CREATE TABLE `softwaredb`.`profile`
( `id` INT(11) NOT NULL AUTO_INCREMENT ,
`user_id` INT(11) NOT NULL ,
`gender` VARCHAR(255) NOT NULL ,
`height` INT(4) NOT NULL ,
`weight` INT(4) NOT NULL ,
`bodytype` INT(1) NOT NULL )
The error I keep running into is the following:
Incorrect table definition;
there can be only one auto column and it must be defined as a key
Try this
CREATE TABLE `softwaredb`.`profile`
( `id` INT(11) NOT NULL AUTO_INCREMENT ,
`user_id` INT(11) NOT NULL ,
`gender` VARCHAR(255) NOT NULL ,
`height` INT(4) NOT NULL ,
`weight` INT(4) NOT NULL ,
`bodytype` INT(1) NOT NULL ,
primary key (id) //specify id as primary key will sort out the error..try
)
OR Try
CREATE TABLE `softwaredb`.`profile`
( `id` INT(11) NOT NULL PRIMARY KEY AUTO_INCREMENT ,
`user_id` INT(11) NOT NULL ,
`gender` VARCHAR(255) NOT NULL ,
`height` INT(4) NOT NULL ,
`weight` INT(4) NOT NULL ,
`bodytype` INT(1) NOT NULL
)

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

The maximum row size for the used table type, not counting BLOBs, is 65535. You have to change some columns to TEXT or BLOBs

I am getting the below message on a table I am trying to create.
The maximum row size for the used table type, not counting BLOBs, is 65535. You have to change some columns to TEXT or BLOBs
Anyone know the answer to this please?
-- Table `warrington_central`.`job`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `warrington_central`.`job` (
`id` MEDIUMINT(8) UNSIGNED NOT NULL AUTO_INCREMENT ,
`alias_title` VARCHAR(255) NOT NULL ,
`reference_number` VARCHAR(100) NOT NULL ,
`title` VARCHAR(255) NOT NULL ,
`primary_category` SMALLINT(5) UNSIGNED NOT NULL ,
`secondary_category` SMALLINT(5) UNSIGNED NOT NULL ,
`tertiary_category` SMALLINT(5) UNSIGNED NULL ,
`address_id` BIGINT(20) UNSIGNED NOT NULL ,
`geolocation_id` BIGINT(20) UNSIGNED NULL ,
`company` VARCHAR(255) NOT NULL ,
`description` VARCHAR(10000) NOT NULL ,
`skills_required` VARCHAR(10000) NOT NULL ,
`job_type` TINYINT(2) UNSIGNED NOT NULL ,
`experience_months_required` TINYINT(2) UNSIGNED NOT NULL ,
`experience_years_required` TINYINT(2) UNSIGNED NOT NULL ,
`salary_range` VARCHAR(30) NOT NULL ,
`extra_benefits_above_salary` VARCHAR(500) NOT NULL ,
`available_from` DATE NULL ,
`available_to` DATE NULL ,
`extra_location_details` VARCHAR(1000) NOT NULL ,
`contact_email` VARCHAR(100) NOT NULL ,
`contact_phone_number` VARCHAR(20) NOT NULL ,
`contact_mobile_number` VARCHAR(20) NOT NULL ,
`terms_conditions_application` VARCHAR(5000) NOT NULL ,
`link_to_profile` ENUM('0','1') NOT NULL ,
`created_on` DATETIME NOT NULL ,
`updated_on` DATETIME NOT NULL ,
`updated_by` BIGINT(20) UNSIGNED NOT NULL ,
`add_contact_form` ENUM('0','1') NOT NULL ,
`admin_package_id` TINYINT(1) UNSIGNED NOT NULL ,
`package_start_date` DATETIME NOT NULL ,
`package_end_date` DATETIME NULL ,
`package_comment` VARCHAR(500) NOT NULL ,
`viewable_to_members_only` ENUM('0','1') NOT NULL ,
`advertise_to` DATETIME NULL ,
`show_comment` ENUM('0','1') NOT NULL ,
`hits` BIGINT(20) UNSIGNED NOT NULL DEFAULT 0 ,
`visible` ENUM('0','1') NOT NULL DEFAULT '0' ,
`approved` ENUM('I/* large SQL query (3.9 KB), snipped at 2,000 characters */
/* SQL Error (1118): Row size too large. The maximum row size for the used table type, not counting BLOBs, is 65535. You have to change some columns to TEXT or BLOBs */
SHOW WARNINGS;
Change description and skills_required to be type text
You are getting that message because the sum of all the fields is > 65k