Having an error in sql while creating table - mysql

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

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)

MySQL error while trying to create table,

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));

Mysql Large SQL query, snipped at 2,000 characters

With the HeidiSQL db client, I am getting a large SQL query (4.0 KB), snipped at 2,000 characters error. Anyone know why this is the case and what i would need to change on the below table
Please let me know which sections of the code would need updating
-- -----------------------------------------------------
-- Table `warrington_central`.`business`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `warrington_central`.`business` (
`id` MEDIUMINT(8) UNSIGNED NOT NULL AUTO_INCREMENT ,
`user_id` BIGINT(20) UNSIGNED NOT NULL ,
`alias_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 ,
`title` VARCHAR(255) NOT NULL ,
`premisis_name` VARCHAR(50) NOT NULL ,
`address_id` BIGINT(20) UNSIGNED NOT NULL ,
`geolocation_id` BIGINT(20) UNSIGNED NULL ,
`logo_path` VARCHAR(100) NOT NULL ,
`telephone_number` VARCHAR(25) NOT NULL ,
`mobile` VARCHAR(25) NOT NULL ,
`fax_no` VARCHAR(25) NOT NULL ,
`website` VARCHAR(100) NOT NULL ,
`email` VARCHAR(60) NOT NULL ,
`opening_times` VARCHAR(5000) NOT NULL ,
`history_experience` VARCHAR(5000) NOT NULL ,
`description` TEXT NOT NULL ,
`no_of_employees` MEDIUMINT(8) UNSIGNED NOT NULL ,
`date_establised` DATE NULL ,
`show_google_map` ENUM('0','1') NOT NULL ,
`show_street_view` ENUM('0','1') NOT NULL ,
`show_comment` ENUM('0','1') NOT NULL ,
`add_contact_form` ENUM('0','1') NOT NULL ,
`viewable_to_members_only` ENUM('0','1') NOT NULL ,
`link_to_user_profile` 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 ,
`created_on` DATETIME NOT NULL ,
`updated_by` BIGINT(20) UNSIGNED NOT NULL ,
`updated_on` DATETIME NOT NULL ,
`approved` ENUM('Inprocess','Yes','No') NOT NULL DEFAULT 'Inprocess' ,
`visible` ENUM('0','1') NOT NULL DEFAULT '0' ,
`hits` BIGINT(20) UNSIGNED NOT NULL DEFAULT 0 ,
`advertise_to` DATETIME NULL ,
PRIMARY KEY (`id`) ,
UNIQUE INDEX `alias_title` (`alias_title` ASC/* large SQL query (4.0 KB), snipped at 2,000 characters */
SHOW WARNINGS;
Well, you can also just go to Tools > Preferences > Logging, and set the "lines in SQL log" setting to another value.
But as #doublesharp said, that's just a cosmetic thing. The query sent to the server is certainly not cut.
This seems to be a function of HeidiSQL and does not actually affect your query running. If it were generating errors or warnings, you would see them after the comment about your query being snipped at 2,000 characters.
See the source code here: http://code.google.com/p/heidisql/source/browse/trunk/source/main.pas?r=4127
prefLogSqlWidth := GetRegValue(REGNAME_LOGSQLWIDTH, DEFAULT_LOGSQLWIDTH);
Then the message is generate with this code
// Shorten very long messages
Len := Length(Msg);
snip := (prefLogSqlWidth > 0) and (Len > prefLogSqlWidth);
IsSQL := Category in [lcSQL, lcUserFiredSQL]; if snip then begin
Msg :=
Copy(Msg, 0, prefLogSqlWidth) +
'/* large SQL query ('+FormatByteNumber(Len)+'), snipped at ' +
FormatNumber(prefLogSqlWidth) +
' characters */';
end else if (not snip) and IsSQL then
Msg := Msg + Delimiter;
if not IsSQL then
Msg := '/* ' + Msg + ' */';
Seems like you can change this value in the registry (http://code.google.com/p/heidisql/source/browse/trunk/source/const.inc?r=4133)
REGNAME_LOGSQLWIDTH = 'logsqlwidth';
DEFAULT_LOGSQLWIDTH = 2000;
The key is probably located here HKEY_CURRENT_USER\Software\HeidiSQL\Servers

SQL syntax error

CREATE TABLE `users` (
`id` INT UNSIGNED NOT NULL AUTO_INCREMENT ,
`type` ENUM( `member` , `admin` ) NOT NULL ,
`username` VARCHAR( 30 ) NOT NULL ,
`email` VARCHAR( 80 ) NOT NULL ,
`pass` VARBINARY( 32 ) NOT NULL ,
`first_name` VARCHAR( 20 ) NOT NULL ,
`last_name` VARCHAR( 40 ) NOT NULL ,
`date_expires` DATE NOT NULL ,
`date_created` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ,
`date_modified` TIMESTAMP NOT NULL DEFAULT `0000-00-00 00:00:00` ,
PRIMARY KEY ( `id` ) ,
UNIQUE KEY `username` ( `username` ) ,
UNIQUE KEY `email` ( `email` )
) ENGINE = MYISAM DEFAULT CHARSET = utf8;
MySQL said:
#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 'member,admin) NOT NULL, username VARCHAR(30) NOT NULL,
email VARCHAR(80)' at line 3
The shared server I am using, uses 4.4. Thanks for reading. I am an absolute novice, having only been learning php/mysql for one month, so please speak in layman's terms.
You need to quote ENUM values
type ENUM( 'member' , 'admin' ) NOT NULL ,
not backtick them as you do now
Same thing for this line
`date_modified` TIMESTAMP NOT NULL DEFAULT `0000-00-00 00:00:00`
should be
`date_modified` TIMESTAMP NOT NULL DEFAULT '0000-00-00 00:00:00'
This page indicates that your ENUM values should be strings, so need to be surrounded by single quotes.
type ENUM( 'member' , 'admin' ) NOT NULL
okey fixed it here is it :)
CREATE TABLE `users` (
`id` INT UNSIGNED NOT NULL AUTO_INCREMENT ,
type ENUM( 'member' , 'admin' ) NOT NULL ,
`username` varchar(30) NOT NULL default '',
`password` varchar(255) NOT NULL default '',
`first_name` varchar (15) NOT NULL,
`last_name` varchar (30) NOT NULL,
`gender` ENUM('male', 'female') NOT NULL default 'male',
`email` varchar(50) NOT NULL default '',
`skype` varchar(50) NOT NULL default 'Not Specified',
`facebook` varchar(150) NOT NULL default 'Not Specified',
`location` varchar(100) NOT NULL default 'Not Specified',
PRIMARY KEY (`id`),
UNIQUE KEY (`email`),
KEY (`email`, `password`)
) ENGINE = MYISAM DEFAULT CHARSET = utf8;

MySQL scheme for opengeocode.org database COW

I want to import the "Countries of the World" database of opengeocode.org into a MySQL database to extend it by postal addressing format information. Is there a database scheme public available?
http://opengeocode.org/download/cow.php
It's a great database of information, would be great if they had it in MySQL format.
Anyway just in case anyone else comes across this page, here's what I did to import the data. I didn't spend hours on this, so might need some tweaking but should get you well on the way. You might need to tweak the number of header lines if they change the comments in the future.
DROP TABLE IF EXISTS countries_of_the_world ;
CREATE TABLE IF NOT EXISTS countries_of_the_world (
id INT NOT NULL AUTO_INCREMENT,
ISO3166a2 CHAR(2) NOT NULL ,
ISO3166a3 CHAR(3) NULL ,
ISO3166n3 INT(3) NULL ,
FIPS104 CHAR(2) NULL ,
ISOen_name VARCHAR(255) NOT NULL ,
ISOen_proper VARCHAR(255) NOT NULL ,
ISOen_ro_name VARCHAR(255) NULL ,
ISOen_ro_proper VARCHAR(255) NULL ,
ISOfr_name VARCHAR(255) NULL ,
ISOfr_proper VARCHAR(255) NULL ,
ISOes_name VARCHAR(255) NULL ,
UNGEGNen_name VARCHAR(255) NULL ,
UNGEGNen_longname VARCHAR(255) NULL ,
UNGEGNfr_name VARCHAR(255) NULL ,
UNGEGNfr_longname VARCHAR(255) NULL ,
UNGEGNes_name VARCHAR(255) NULL ,
UNGEGNes_longname VARCHAR(255) NULL ,
UNGEGNru_name VARCHAR(255) NULL ,
UNGEGNru_longname VARCHAR(255) NULL ,
UNGEGNlc_ro_name VARCHAR(255) NULL ,
UNGEGNlc_ro_longname VARCHAR(255) NULL ,
BGN_name VARCHAR(255) NULL ,
BGN_proper VARCHAR(255) NULL ,
BGN_longname VARCHAR(255) NULL ,
BGNlc_longname VARCHAR(255) NULL ,
BGNlc_name VARCHAR(255) NULL ,
PCGN_name VARCHAR(255) NULL ,
PCGN_proper VARCHAR(255) NULL ,
PCGN_longname VARCHAR(255) NULL ,
FAOit_name VARCHAR(255) NULL ,
FAOit_proper VARCHAR(255) NULL ,
FAOit_longname VARCHAR(255) NULL ,
EKI_name VARCHAR(255) NULL ,
EKI_longname VARCHAR(255) NULL ,
conabbr VARCHAR(45) NULL ,
HasCapital TINYINT NULL ,
BGN_capital VARCHAR(255) NULL ,
UNGEGNlc_capital VARCHAR(255) NULL ,
UNen_capital VARCHAR(255) NULL ,
UNfr_capital VARCHAR(255) NULL ,
UNes_capital VARCHAR(255) NULL ,
UNru_capital VARCHAR(255) NULL ,
EKI_capital VARCHAR(255) NULL ,
BGNc_latitude DOUBLE NULL ,
BGNc_longitude DOUBLE NULL ,
UNc_latitude DOUBLE NULL ,
UNc_longitude DOUBLE NULL ,
continent CHAR(2) NULL ,
subcontinent CHAR(2) NULL ,
ISOregion SMALLINT NULL ,
ISOsubregion SMALLINT NULL ,
language VARCHAR(45) NULL ,
population INT NULL ,
year SMALLINT NULL ,
BGN_demonym VARCHAR(255) NULL ,
BGN_demonym_adj VARCHAR(255) NULL ,
ITU SMALLINT NULL ,
IVC VARCHAR(3) NULL ,
land INT NULL ,
water INT NULL ,
land_total INT NULL ,
latitude DOUBLE NULL ,
longitude DOUBLE NULL ,
maxlatitude DOUBLE NULL ,
minlatitude DOUBLE NULL ,
minlongitude DOUBLE NULL ,
maxlongitude DOUBLE NULL ,
url_gov VARCHAR(255) NULL ,
url_stats VARCHAR(255) NULL ,
url_gis VARCHAR(255) NULL ,
url_post VARCHAR(255) NULL ,
PRIMARY KEY (id) )
ENGINE = InnoDB DEFAULT CHARSET=utf8;
LOAD DATA INFILE '/tmp/cow.txt'
INTO TABLE countries_of_the_world
FIELDS TERMINATED BY '; ' LINES TERMINATED BY '\r\n' IGNORE 29 LINES
(
ISO3166a2,
ISO3166a3,
ISO3166n3,
FIPS104,
ISOen_name,
ISOen_proper,
ISOen_ro_name,
ISOen_ro_proper,
ISOfr_name,
ISOfr_proper,
ISOes_name,
UNGEGNen_name,
UNGEGNen_longname,
UNGEGNfr_name,
UNGEGNfr_longname,
UNGEGNes_name,
UNGEGNes_longname,
UNGEGNru_name,
UNGEGNru_longname,
UNGEGNlc_ro_name,
UNGEGNlc_ro_longname,
BGN_name,
BGN_proper,
BGN_longname,
BGNlc_longname,
BGNlc_name,
PCGN_name,
PCGN_proper,
PCGN_longname,
FAOit_name,
FAOit_proper,
FAOit_longname,
EKI_name,
EKI_longname,
conabbr,
HasCapital,
BGN_capital,
UNGEGNlc_capital,
UNen_capital,
UNfr_capital,
UNes_capital,
UNru_capital,
EKI_capital,
BGNc_latitude,
BGNc_longitude,
UNc_latitude,
UNc_longitude,
continent,
subcontinent,
ISOregion,
ISOsubregion,
language,
population,
year,
BGN_demonym,
BGN_demonym_adj,
ITU,
IVC,
land,
water,
land_total,
latitude,
longitude,
maxlatitude,
minlatitude,
minlongitude,
maxlongitude,
url_gov,
url_stats,
url_gis,
url_post
);