trouble with import query to database - mysql

I have this query and I tried to import it to phpmyadmin. Can you tell me how to fix this? Thank you.
DROP TABLE IF EXISTS `dp_confirms`;
CREATE TABLE `dp_confirms` (
`id` int(11) NOT NULL auto_increment,
`newuser` varchar(32) NOT NULL default '',
`newpass` varchar(32) NOT NULL default '',
`newquestion` varchar(255) NOT NULL default '',
`newanswer` varchar(255) NOT NULL default '',
`newmail` varchar(255) NOT NULL default '',
`newfname` varchar(32) NOT NULL default '',
`newlname` varchar(32) NOT NULL default '',
`newcompany` varchar(128) NOT NULL default '',
`newregnum` varchar(32) NOT NULL default '',
`newdrvnum` varchar(32) NOT NULL default '',
`newaddress` varchar(128) NOT NULL default '',
`newcity` varchar(64) NOT NULL default '',
`newcountry` char(2) NOT NULL default '',
`newstate` varchar(32) NOT NULL default '',
`newzip` varchar(32) NOT NULL default '',
`newphone` varchar(64) NOT NULL default '',
`newfax` varchar(64) NOT NULL default '',
`sponsor` int(11) NOT NULL default '0',
`confirm` varchar(255) NOT NULL default '',
`cdate` timestamp(14) NOT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `newuser` (`newuser`),
KEY `newmail` (`newmail`)
) ENGINE=MyISAM AUTO_INCREMENT=1 ;
Error I get:
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 '(14) NOT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `newuser` (`newuser`),
K' at line 22

Specifying the length for a timestamp such as timestamp(14) was deprecated in MySQL 5.1, and is no longer supported from MySQL 5.5.
This is easily fixed by removing the length specification:
`cdate` timestamp NOT NULL,

Related

MariaDB How to avoid error NOT NULL DEFAULT

i m trying to load a DB in my local server XAMPP but it keeps giving me this error.
My table
CREATE TABLE `transactions_client_view` (
`name` VARCHAR(255) NOT NULL DEFAULT '',
`surname` VARCHAR(255) NOT NULL DEFAULT '',
`actualcredit` DOUBLE(10) NOT NULL DEFAULT '0.00000',
`amount` DOUBLE(10) NOT NULL DEFAULT '0.00000',
`date` DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00',
`error` VARCHAR(255) NOT NULL DEFAULT '',
`client_id` INT(11) UNSIGNED NOT NULL DEFAULT '0'
) ENGINE=MyISAM;
ERROR
ERROR 1064 (42000) at line 361239: 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 DEFAULT '',
amount DOUBLE(10) NOT NULL DEFAULT '', `date' at line 4
try this
CREATE TABLE `transactions_client_view` (
`name` VARCHAR(255) NOT NULL DEFAULT '',
`surname` VARCHAR(255) NOT NULL DEFAULT '',
`actualcredit` DOUBLE NOT NULL DEFAULT '0.00000',
`amount` DOUBLE NOT NULL DEFAULT '0.00000',
`date` DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00',
`error` VARCHAR(255) NOT NULL DEFAULT '',
`client_id` INT(11) UNSIGNED NOT NULL DEFAULT '0'
) ENGINE=MyISAM;

MySQL #1064 - You have an error in your SQL syntax at line 2

What's wrong on this code? I receive that message when try to import this sql:
#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 ''codigo' int(11) unsigned NOT NULL auto_increment, 'razao_social' varchar(11) N' at line 2
CREATE TABLE IF NOT EXISTS `char` (
'codigo' int(11) unsigned NOT NULL auto_increment,
'razao_social' varchar(11) NOT NULL DEFAULT '',
'fantasia' varchar(11) NOT NULL DEFAULT '',
'data_de_cadastro' datetime NOT NULL DEFAULT '',
'cep' varchar(11) NOT NULL DEFAULT '',
'logradouro' varchar(11) NOT NULL DEFAULT '',
'numero' varchar(11) NOT NULL DEFAULT '',
'complemento' varchar(11) NOT NULL DEFAULT '',
'bairro' varchar(11) NOT NULL DEFAULT '',
'cidade' varchar(11) NOT NULL DEFAULT '',
'uf' varchar(11) NOT NULL DEFAULT '',
'cnpj' varchar(11) NOT NULL DEFAULT '',
'insc_estadual' varchar(11) NOT NULL DEFAULT '',
'incs_municipal' varchar(11) NOT NULL DEFAULT '',
'telefone01' varchar(11) NOT NULL DEFAULT '',
'telefone02' varchar(11) NOT NULL DEFAULT '',
'contato' varchar(11) NOT NULL DEFAULT '',
'associados' varchar(11) NOT NULL DEFAULT '',
'funcionários' varchar(11) NOT NULL DEFAULT '',
'data_socio' datatime NOT NULL DEFAULT '',
'data_desligamento' datatime NOT NULL DEFAULT '',
'email' varchar(11) NOT NULL DEFAULT '',
'website' varchar(11) NOT NULL DEFAULT '',
'situacao' int(11) NOT NULL DEFAULT '',
PRIMARY KEY (`codigo`),
UNIQUE KEY `razao_social` (`razao_social`),
KEY `fantasia` (`account_id`),
KEY `cnpj` (`cnpj`),
KEY `insc_estadual` (`insc_estadual`),
KEY `incs_municipal` (`incs_municipal`)
) ENGINE=MySQL;
you should use backticks ` in MySQL to escape column name identifiers, not single quotes ' (actually, all identifiers, just like you've done with you table name);
you provide datatime as the datatype for data_socio and
data_desligamento, which is invalid (because it doesn't exist, I think you've meant datetime);
MySQL is not a valid engine option (maybe you've meant MyISAM?), here is a list of storage engines;
'' is not a valid default value for the datetime datatype (data_desligamento, data_socio and data_de_cadastro);
you are creating an index fantasia using a key for the column account_id that doesn't even exist in your table (or it is just a typo and either fantasia column should be called account_id or vice versa? - just guessing here).
SQLFiddle
Do not use single quotes(') in column names, instead use tild symbol (`).
For example:
this column 'razao_social' should be write as `razao_social`

correct mysql syntax error

please could someone tell me the problem with this syntax because mysql 5.5.32 keeps tell me about an error
CREATE TABLE `clients` (
`ID` tinyint(11) NOT NULL auto_increment,
`title` varchar(10) NOT NULL default '',
`firstName` varchar(30) NOT NULL default '',
`lastName` varchar(30) NOT NULL default '',
`address1` varchar(100) NOT NULL default '',
`address2` varchar(100) NOT NULL default '',
`town` varchar(100) NOT NULL default '',
`province` varchar(100) NOT NULL default '',
`country` varchar(40) NOT NULL default '',
`postCode` varchar(20) NOT NULL default '',
`telephone` varchar(20) NOT NULL default '',
`email` varchar(100) NOT NULL default '',
`cardNo` varchar(16) NOT NULL default '0000-00-00',
`expiryDate` date NOT NULL default '0000-00-00',
PRIMARY KEY (`ID`)
) TYPE=MyISAM COMMENT='customer table' AUTO_INCREMENT=1 ;
The keyword TYPE has been replaced by ENGINE as in
ENGINE=MyISAM
change TYPE to ENGINE like this:
CREATE TABLE `clients` (
`ID` tinyint(11) NOT NULL auto_increment,
`title` varchar(10) NOT NULL default '',
`firstName` varchar(30) NOT NULL default '',
`lastName` varchar(30) NOT NULL default '',
`address1` varchar(100) NOT NULL default '',
`address2` varchar(100) NOT NULL default '',
`town` varchar(100) NOT NULL default '',
`province` varchar(100) NOT NULL default '',
`country` varchar(40) NOT NULL default '',
`postCode` varchar(20) NOT NULL default '',
`telephone` varchar(20) NOT NULL default '',
`email` varchar(100) NOT NULL default '',
`cardNo` varchar(16) NOT NULL default '0000-00-00',
`expiryDate` date NOT NULL default '0000-00-00',
PRIMARY KEY (`ID`)
) ENGINE=MyISAM COMMENT='customer table' AUTO_INCREMENT=1 ;
MySQL 5.0 accepts TYPE or ENGINE, but above MySQL 5.1, Only ENGINE is allowed.

MySQL Version Related Syntax Errors

When uploading a SQL script using MySQL version 5.5.23-55 and importing using phpMyadmin version 3.4.11.1, I am getting the following goofy errors:
SQL query:
CREATE TABLE `dp_banks` (
`id` int(11) NOT NULL auto_increment,
`owner` int(11) NOT NULL default '0',
`bname` varchar(128) NOT NULL default '',
`baddress` varchar(128) NOT NULL default '',
`bcity` varchar(64) NOT NULL default '',
`bzip` varchar(16) NOT NULL default '',
`bcountry` char(2) NOT NULL default '',
`bstate` varchar(32) NOT NULL default '',
`bphone` varchar(32) NOT NULL default '',
`bnameacc` varchar(128) NOT NULL default '',
`baccount` varchar(32) NOT NULL default '',
`btype` char(2) NOT NULL default '',
`brtgnum` varchar(9) NOT NULL default '',
`bswift` varchar(32) NOT NULL default '',
`status` tinyint(1) NOT NULL default '0',
`default` tinyint(1) NOT NULL default '0',
PRIMARY KEY (`id`)
) TYPE=MyISAM AUTO_INCREMENT=1 ;
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 'TYPE=MyISAM AUTO_INCREMENT=1' at line 19
Researching on the net, I found an article that recommended changing TYPE=MyISAM to ENGINE=MyISAM. Making this change now gives the following errors:
SQL query:
CREATE TABLE `dp_confirms` (
`id` int(11) NOT NULL auto_increment,
`newuser` varchar(32) NOT NULL default '',
`newpass` varchar(32) NOT NULL default '',
`newquestion` varchar(255) NOT NULL default '',
`newanswer` varchar(255) NOT NULL default '',
`newmail` varchar(255) NOT NULL default '',
`newfname` varchar(32) NOT NULL default '',
`newlname` varchar(32) NOT NULL default '',
`newcompany` varchar(128) NOT NULL default '',
`newregnum` varchar(32) NOT NULL default '',
`newdrvnum` varchar(32) NOT NULL default '',
`newaddress` varchar(128) NOT NULL default '',
`newcity` varchar(64) NOT NULL default '',
`newcountry` char(2) NOT NULL default '',
`newstate` varchar(32) NOT NULL default '',
`newzip` varchar(32) NOT NULL default '',
`newphone` varchar(64) NOT NULL default '',
`newfax` varchar(64) NOT NULL default '',
`sponsor` int(11) NOT NULL default '0',
`confirm` varchar(255) NOT NULL default '',
`cdate` timestamp(14) NOT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `newuser` (`newuser`),
KEY `newmail` (`newmail`)
) ENGINE=MyISAM AUTO_INCREMENT=1 ;
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 '(14) NOT NULL, PRIMARY KEY (id), UNIQUE KEYnewuser(newuser), KEY ' at line 22
Thanks in advance for all help.
Other than changing TYPE to ENGINE change
`cdate` timestamp(14) NOT NULL,
^^^^
to
`cdate` timestamp NOT NULL,
Here is SQLFiddle demo
) TYPE=MyISAM AUTO_INCREMENT=1 ;
Replace this with
) ENGINE = MYISAM AUTO_INCREMENT =1;
Type has been replaced with engine.
TYPE keyword is depreciated (since 5.0) and not supported in MySQL5.5 (and I think even 5.1). Instead of TYPE keyword use ENGINE keyword.
My experience was that i had to change two things:
TYPE=MyISAM AUTO_INCREMENT=1 ;
Replace this with
ENGINE=MyISAM AUTO_INCREMENT=1;
AND
cdate timestamp(14) NOT NULL,
to
cdate timestamp NOT NULL,
That worked for me

Using slash in MySQL database

I am using mysql with php Yii framework.When doing data modelling I came accross some doubt.I have a table for user details like this.
CREATE TABLE IF NOT EXISTS `tbl_users` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`firstname` varchar(80) NOT NULL DEFAULT '',
`lastname` varchar(80) NOT NULL DEFAULT '',
`gender` varchar(6) NOT NULL DEFAULT '',
`email` varchar(45) NOT NULL DEFAULT '',
`company_name` varchar(80) NOT NULL DEFAULT '',
`contact_no` varchar(45) NOT NULL DEFAULT '',
`address` varchar(120) NOT NULL DEFAULT '',
`state` varchar(45) NOT NULL DEFAULT '',
`country` varchar(45) NOT NULL DEFAULT '',
`created_by` int(11) DEFAULT NULL,
`updated_by` int(11) DEFAULT NULL,
`created_at` datetime DEFAULT NULL,
`updated_at` datetime DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=98 ;
Here my problem is I want the state,country should be like this so that I can use the fields like state/city
`state/city` varchar(45) NOT NULL DEFAULT '',
`state/province` varchar(45) NOT NULL DEFAULT '',
So is it safe to use like this or I have to use only one option there?Any help and suggestions will be highly appriciable.
Yes, it's valid. But you will always need to quote it with backticks.
See http://dev.mysql.com/doc/refman/5.5/en/identifiers.html for full details on what's allowed.