Syntax error in create table query - mysql

I cant get this syntax 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 '(id) ENGINE=MyISAM)' at line 15
CREATE TABLE IF NOT EXISTS `destination_cdr` (
`id` BIGINT( 20 ) NOT NULL AUTO_INCREMENT ,
`calldate` DATETIME NOT NULL ,
`source` VARCHAR( 80 ) NOT NULL ,
`destination` VARCHAR( 80 ) NOT NULL ,
`account_code` VARCHAR( 30 ) DEFAULT NULL ,
`pincode` VARCHAR( 45 ) NOT NULL ,
`duration_call` BIGINT( 20 ) NOT NULL DEFAULT '0',
`duration_talk` BIGINT( 20 ) NOT NULL ,
`disposition` VARCHAR( 255 ) NOT NULL ,
`clid` VARCHAR( 80 ) DEFAULT NULL ,
`cdr_id` BIGINT( 20 ) DEFAULT NULL ,
`vxcdr_id` BIGINT( 20 ) DEFAULT NULL ,
`provider` INT( 11 ) NOT NULL DEFAULT '0' PRIMARY KEY ( `id` )) ENGINE = MYISAM
;

You need a commma between provider and primary Key:
`provider` INT( 11 ) NOT NULL DEFAULT '0', PRIMARY KEY ( `id` )) ENGINE = MYISAM

Missing comma before primary key clause.
`provider` INT( 11 ) NOT NULL DEFAULT '0', PRIMARY KEY ( `id` ))

Error
SQL query:
--
-- Database: wadud
--
-- Table structure for table destination
CREATE TABLE destination (
id bigint(20) NOT NULL,
country varchar(255) NOT NULL,
photo text NOT NULL,
tours varchar(255) NOT NULL,
created_at timestamp NULL DEFAULT NULL,
updated_at timestamp NULL DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8
MySQL said: Documentation
1050 - Table 'destination' already exists

Related

When I am trying to import it to my phpmy admin am getting error #1067 - Invalid default value

Error
SQL query:
--
-- Database: gym
-- --------------------------------------------------------
-- Table structure for table admin_tbl
CREATE TABLE IF NOT EXISTS `admin_tbl` (
`adminid` int( 11 ) NOT NULL ,
`username` varchar( 20 ) NOT NULL ,
`password` varchar( 20 ) NOT NULL ,
`timestamp` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON
) ENGINE = InnoDB AUTO_INCREMENT =3 DEFAULT CHARSET = latin1;
MySQL said: Documentation
#1067 - Invalid default value for 'timestamp'
You have an extra ON which you likely copied from:
dt DATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
When you remove the ON, it works fine.
So your result should be:
CREATE TABLE IF NOT EXISTS `admin_tbl` (
`adminid` int( 11 ) NOT NULL ,
`username` varchar( 20 ) NOT NULL ,
`password` varchar( 20 ) NOT NULL ,
`timestamp` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP
) ENGINE = InnoDB AUTO_INCREMENT =3 DEFAULT CHARSET = latin1;
SQLFiddle
MySQL Documentation

Database not importing

Error
##
--
-- Database: verticalned
-- --------------------------------------------------------
-- Table structure for table announcements
CREATE TABLE `announcements` (
`id` INT( 10 ) NOT NULL ,
`description` VARCHAR( 6000 ) DEFAULT NULL ,
`links` VARCHAR( 100 ) DEFAULT NULL ,
`first` TINYINT( 1 ) DEFAULT > NULL ,
`second` TINYINT( 1 ) DEFAULT NULL ,
`third` TINYINT( 1 ) DEFAULT NULL ,
`fourth` TINYINT( 1 ) DEFAULT NULL ,
`staff` VARCHAR( 22 ) DEFAULT NULL ,
`time` DATETIME( 2 ) DEFAULT NULL ,
`subject` VARCHAR( 100 ) DEFAULT NULL
) ENGINE = INNODB DEFAULT CHARSET = latin1;
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 '(2) DEFAULT NULL, subject varchar(100) DEFAULT NULL )
ENGINE=InnoDB DEFAULT ' at line 20
version
Looks like the mysql version you are using (probably older than 5.6.4) does not accept precision (fractional seconds). You can bypass the issue by replacing ..., time DATETIME(2) DEFAULT NULL ,... with ... , time DATETIME DEFAULT NULL ,....
However, you should solve the issue by either changing the data type to timestamp or upgrading MySQL server to a version later than 5.6.4
CREATE TABLE `announcements` (
`id` INT(10) NOT NULL,
`description` VARCHAR(6000) DEFAULT NULL,
`links` VARCHAR(100) DEFAULT NULL,
`first` TINYINT( 1 ) DEFAULT NULL ,
`second` TINYINT( 1 ) DEFAULT NULL ,
`third` TINYINT( 1 ) DEFAULT NULL ,
`fourth` TINYINT( 1 ) DEFAULT NULL ,
`staff` VARCHAR( 22 ) DEFAULT NULL ,
`time` DATETIME( 2 ) DEFAULT NULL ,
`subject` VARCHAR( 100 ) DEFAULT NULL
) ENGINE = INNODB DEFAULT CHARSET = latin1;
obvoiusly theres nothing wrongn with your code. just add the slanted quotes
CREATE TABLE announcements (
id INT NOT NULL ,
description VARCHAR( 6000 ) DEFAULT NULL ,
links VARCHAR( 100 ) DEFAULT NULL ,
firstTINYINT DEFAULT NULL ,
secondTINYINT DEFAULT NULL,
thirdTINYINT DEFAULT NULL ,
fourthTINYINT DEFAULT NULL,
staffVARCHAR(22) DEFAULT NULL ,
timeDATETIME DEFAULT NULL ,
subject` VARCHAR( 100 ) DEFAULT NULL
) ENGINE = INNODB DEFAULT CHARSET = latin1;
Please remove character number from INT and TINYINT, and add the slanted quotes your code should work.

mysql syntax error why?

mysql query
CREATE TABLE IF NOT EXISTS 'sadakin'.'gcm_users' (
'id' int( 11 ) NOT NULL AUTO_INCREMENT ,
'gcm_regid' text,
'name' varchar( 50 ) NOT NULL ,
'email' varchar( 255 ) NOT NULL ,
'imei' varchar( 20 ) NOT NULL ,
'created_at' timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ,
PRIMARY KEY ( 'id' ) ,
KEY 'imei' ( 'imei' )
) ENGINE = InnoDB DEFAULT CHARSET = latin1 AUTO_INCREMENT =1;
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 ''sadakin'.'gcm_users' (
'id' int( 11 ) NOT NULL AUTO_INCREMENT ,
'gcm_' at line 1
I don't find error. Help me!
Use backticks to enclose identifiers. Quotes are just for strings:
CREATE TABLE IF NOT EXISTS `sadakin`.`gcm_users` (
`id` int( 11 ) NOT NULL AUTO_INCREMENT ,
`gcm_regid` text,
`name` varchar( 50 ) NOT NULL ,
`email` varchar( 255 ) NOT NULL ,
`imei` varchar( 20 ) NOT NULL ,
`created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ,
PRIMARY KEY ( `id` ) ,
KEY `imei` ( `imei` )
) ENGINE = InnoDB DEFAULT CHARSET = latin1 AUTO_INCREMENT =1;
There is no need of any single quotes on column names
CREATE TABLE IF NOT EXISTS sadakin.gcm_users (
id int( 11 ) NOT NULL AUTO_INCREMENT ,
gcm_regid text,
name varchar( 50 ) NOT NULL ,
email varchar( 255 ) NOT NULL ,
imei varchar( 20 ) NOT NULL ,
created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ,
PRIMARY KEY ( id ) ,
KEY imei ( imei )
) ENGINE = InnoDB DEFAULT CHARSET = latin1 AUTO_INCREMENT =1;
You have to use back-ticks instead of single quotes. Quotes are used for string literals.
Check this: http://dev.mysql.com/doc/refman/5.0/en/string-literals.html
A string is a sequence of bytes or characters, enclosed within either
single quote (“'”) or double quote (“"”)
Try:
CREATE TABLE IF NOT EXISTS `sadakin`.`gcm_users` (
`id` INT( 11 ) NOT NULL AUTO_INCREMENT ,
`gcm_regid` TEXT,
`name` VARCHAR( 50 ) NOT NULL ,
`email` VARCHAR( 255 ) NOT NULL ,
`imei` VARCHAR( 20 ) NOT NULL ,
`created_at` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ,
PRIMARY KEY ( `id` ) ,
KEY `imei` ( `imei` )
) ENGINE = INNODB DEFAULT CHARSET = latin1 AUTO_INCREMENT =1;

SQL syntax error when creating new table in MySQL

I wont to create sql tables but I receive 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
'CREATE TABLE `articles_ratings` ( `ID` INT(11) NOT NULL AUTO_INCREMENT, `a' at line 10
CREATE TABLE `articles` (
`ID` int( 11 ) NOT NULL AUTO_INCREMENT ,
`a_title` varchar( 255 ) ,
`a_subtitle` tinytext,
`a_content` text,
PRIMARY KEY ( `ID` )
)
CREATE TABLE `articles_ratings` (
`ID` INT( 11 ) NOT NULL AUTO_INCREMENT ,
`article_id` int( 11 ) NOT NULL ,
`rating_value` tinyint( 2 ) NOT NULL ,
`rater_ip` varchar( 20 ) NOT NULL ,
)
Add the primary key to your articles ratings statement or remove the last comma.
CREATE TABLE articles (
ID int( 11 ) NOT NULL AUTO_INCREMENT ,
a_title varchar( 255 ) ,
a_subtitle tinytext,
a_content text,
PRIMARY KEY ( ID )
);
CREATE TABLE articles_ratings (
ID INT( 11 ) NOT NULL AUTO_INCREMENT ,
article_id int( 11 ) NOT NULL ,
rating_value tinyint( 2 ) NOT NULL ,
rater_ip varchar( 20 ) NOT NULL ,
PRIMARY KEY ( ID )
);

Error #1064 in mysql [duplicate]

This question already has answers here:
1064 error in CREATE TABLE ... TYPE=MYISAM
(5 answers)
Closed 9 years ago.
I keep 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 'TYPE=MyISAM AUTO_INCREMENT=58' at line 11
This is my query :
CREATE TABLE `tbl_cart` (
`ct_id` int( 10 ) unsigned NOT NULL AUTO_INCREMENT ,
`pd_id` int( 10 ) unsigned NOT NULL default '0',
`ct_qty` mediumint( 8 ) unsigned NOT NULL default '1',
`ct_session_id` char( 32 ) NOT NULL default '',
`ct_date` datetime NOT NULL default '0000-00-00 00:00:00',
PRIMARY KEY ( `ct_id` ) ,
KEY `pd_id` ( `pd_id` ) ,
KEY `ct_session_id` ( `ct_session_id` )
) TYPE = MYISAM AUTO_INCREMENT =58;
Help Me What the problem is ...
The keyword TYPE is removed since MySQL 5.1, use
) ENGINE = MYISAM AUTO_INCREMENT =58;
instead.
CREATE TABLE `tbl_cart` (
`ct_id` int( 10 ) unsigned NOT NULL AUTO_INCREMENT ,
`pd_id` int( 10 ) unsigned NOT NULL default '0',
`ct_qty` mediumint( 8 ) unsigned NOT NULL default '1',
`ct_session_id` char( 32 ) NOT NULL default '',
`ct_date` datetime NOT NULL default '0000-00-00 00:00:00',
PRIMARY KEY ( `ct_id` ) ,
KEY `pd_id` ( `pd_id` ) ,
KEY `ct_session_id` ( `ct_session_id` )
) ENGINE = MYISAM AUTO_INCREMENT =58;