Search code examples
mysqlmysql-error-1064create-table

What is wrong with this mysql create table query?


I have a database in my production server and it works fine... What i did is took a dump of that DB and executed in my local system.. All the other tables are created except one table... So i manually inserted it,

CREATE TABLE `contact` (
  `contactId` int(11) NOT NULL AUTO_INCREMENT,
  `cRefId` int(20) DEFAULT '0',
  `contactFirstName` varchar(100) DEFAULT NULL,
  `contactLastName` varchar(100) DEFAULT NULL,
  `contactPhone` varchar(35) DEFAULT NULL,
  `contactEmail` varchar(150) DEFAULT NULL,
  `organizationid` int(11) NOT NULL,
  `mobileNo` varchar(35) DEFAULT NULL,
  `dor` datetime DEFAULT NULL,
  `doe` datetime DEFAULT NULL,
  `dod` datetime DEFAULT NULL,
  `designation` varchar(50) DEFAULT NULL,
  `income` double DEFAULT NULL,
  `homeloan` tinyint(1) DEFAULT NULL,
  `companyName` varchar(200) DEFAULT NULL,
  `isDeleted` tinyint(1) DEFAULT '0',
  `addressId` int(11) DEFAULT NULL,
  `accgroupid` int(11) DEFAULT NULL,
  `createdBy` int(11) DEFAULT NULL,
  `editedBy` int(11) DEFAULT NULL,
  `deletedBy` int(11) DEFAULT NULL,
  `assignedto` int(11) DEFAULT NULL,
  `industryid` int(11) DEFAULT NULL,
  `note` varchar(150) DEFAULT NULL,
  `twirrerId` varchar(150) DEFAULT NULL,
  `linkedinId` varchar(150) DEFAULT NULL,
  PRIMARY KEY (`contactId`),
  KEY `aa` (`organizationid`),
  KEY `add_id` (`addressId`),
  KEY `idx_contactid` (`contactId`),
  KEY `FK_contact` (`industryid`),
  KEY `fk_contacteditedby_user` (`editedBy`),
  KEY `fk_contactaccount_account` (`accgroupid`,`contactId`),
  KEY `contact_First_Name` (`contactFirstName`) USING BTREE
) ENGINE=MyISAM AUTO_INCREMENT=2 DEFAULT CHARSET=latin1;

But when i execute this i get the following error,

Error Code : 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 'USING BTREE
) ENGINE=MyISAM AUTO_INCREMENT=2 DEFAULT CHARSET=latin1' at line 35

Solution

  • I'm pretty certain you have to specify the using before the index column that you're using:

    ... KEY `contact_First_Name` USING BTREE (`contactFirstName`)
    

    The doco referenced in that link states (MySQL 5.1):

    {INDEX|KEY} [index_name] [index_type] (index_col_name,...) [index_option] ...
    

    and [index_type] is the using btree bit.

    Failing that, check that you have compatible versions on the source and destination server. There was a patch which made the interpretation of that command a little more robust in terms of what order they should be in.

    Or you could remove the using btree altogether and use the server default method though you should understand the ramifications of that before choosing it as an option.