MySQL create table script with keys - mysql

I'm trying to execute this script on MySQL Server (installed on a VM with Ubuntu Server 64bit)
CREATE TABLE `MAINTABLEPARTS` (
`NAME_PARTS` varchar(300) NOT NULL,
`BRAND` varchar(60) NOT NULL,
`CODE_PART` varchar(105) NOT NULL,
`CODE_PARTS_ADVANCED` varchar(150) NOT NULL,
`CODE_PARTS_USERNUMBER` varchar(150) NOT NULL,
`EAN` varchar(13) DEFAULT NULL,
`STATUSPRODUCT` varchar(300) DEFAULT NULL,
`NAME_IMAGE` varchar(300) DEFAULT NULL,
`TTC_ART_ID` int(11) NOT NULL,
`ADDITIONAL_DATA` text,
PRIMARY KEY (`TTC_ART_ID`),
KEY (`BRAND`, `CODE_PART`, `EAN`)
KEY (`BRAND`, `CODE_PARTS_USERNUMBER`)
)
The problem is that I get an error in the query when I execute it...(something about the sql version).... the script above is automatically generated so I did not write it myself. Any ideas what might could be wrong ? If you need any further information please let me know...(MySQL version 5.7.15, query executed from MySQL Front v5.4 - build 4.148)

You are missing a comma here
CREATE TABLE `MAINTABLEPARTS` (
`NAME_PARTS` varchar(300) NOT NULL,
`BRAND` varchar(60) NOT NULL,
`CODE_PART` varchar(105) NOT NULL,
`CODE_PARTS_ADVANCED` varchar(150) NOT NULL,
`CODE_PARTS_USERNUMBER` varchar(150) NOT NULL,
`EAN` varchar(13) DEFAULT NULL,
`STATUSPRODUCT` varchar(300) DEFAULT NULL,
`NAME_IMAGE` varchar(300) DEFAULT NULL,
`TTC_ART_ID` int(11) NOT NULL,
`ADDITIONAL_DATA` text,
PRIMARY KEY (`TTC_ART_ID`),
KEY (`BRAND`, `CODE_PART`, `EAN`),
---------------------------------^
KEY (`BRAND`, `CODE_PARTS_USERNUMBER`)
)

Related

New MySQL version breaking queries

I moved a MySQL database from a server using MySQL 5.1.36 to a server using MySQL 5.7.11 and most of the INSERT statements now don't work. A previous developer created this app, and I'm trying to fix this query.
Here is an example:
INSERT INTO arts.tblmainrequest
select UUID(),'Aetna','Test','Test','555555','20160921','\\Base Folder\',
NULL,'testdoc.doc',NULL,NULL,NULL,NULL,NULL,
NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,
NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,
'20160920','test record','Y','400889', now()
Here is the create table script:
CREATE TABLE `tblmainrequest` (
`reqUUID` varchar(100) NOT NULL,
`company` varchar(200) DEFAULT NULL,
`patientlname` varchar(200) DEFAULT NULL,
`patientfname` varchar(200) DEFAULT NULL,
`MRN` char(6) DEFAULT NULL,
`DischargeDate` date DEFAULT NULL,
`BaseFolder` varchar(100) DEFAULT NULL,
`RecordsMailed` date DEFAULT NULL,
`OriginalReqFileName` varchar(100) DEFAULT NULL,
`SHHURCommitteeLetter` date DEFAULT NULL,
`SHHURCommitteeLetterFileName` varchar(100) DEFAULT NULL,
`MedRecsDeliveryMethod` varchar(50) DEFAULT NULL,
`TrackingNumber` varchar(50) DEFAULT NULL,
`PrelimFindings` date DEFAULT NULL,
`PrelimFindingsFileName` varchar(100) DEFAULT NULL,
`SHHPrelimResponseUM` date DEFAULT NULL,
`SHHPrelimResponseUMFileName` varchar(100) DEFAULT NULL,
`SHHPrelimResponseMR` date DEFAULT NULL,
`SHHPrelimResponseMRFileName` varchar(100) DEFAULT NULL,
`FinalReviewFindings` date DEFAULT NULL,
`FinalReviewFindingsFileName` varchar(100) DEFAULT NULL,
`FinalResponseSHH` date DEFAULT NULL,
`FinalResponseSHHFileName` varchar(100) DEFAULT NULL,
`HearingRequestSHH` date DEFAULT NULL,
`HearingRequestSHHFileName` varchar(100) DEFAULT NULL,
`HearingCorrespondenceUnnamed` date DEFAULT NULL,
`HearingCorrespondenceUnnamedFileName` varchar(100) DEFAULT NULL,
`HearingDateScheduled` date DEFAULT NULL,
`HearingDateScheduledFileName` varchar(100) DEFAULT NULL,
`HearingDecision` date DEFAULT NULL,
`HearingDecisionFileName` varchar(100) DEFAULT NULL,
`EmailedBusOffice` date DEFAULT NULL,
`Comments` longtext,
`Active` char(1) DEFAULT NULL,
`UpdatedBy` int(11) DEFAULT NULL,
`UpdatedOn` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
PRIMARY KEY (`reqUUID`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
You need to escape the second \ for the folder, \Base Folder****
Otherwise, mysql takes **** to as escape char and the following ' becomes the value of the field, and cause the following syntax are wrong.

#1067 - Invalid default value for 'LastUpdated'

I made my ER diagram via MySQL WorkBench and exported it as a sql. Below is code for one table.
CREATE TABLE IF NOT EXISTS `xxx`.`Agent` (
`idAgent` INT NOT NULL AUTO_INCREMENT,
`Name` VARCHAR(100) NOT NULL,
`RegistrationNumber` VARCHAR(45) NOT NULL,
`RegistrationDate` DATE NULL,
`DateOfDealStart` DATE NULL,
`AddressLine1` VARCHAR(100) NULL,
`AddressLine2` VARCHAR(100) NULL,
`Country` VARCHAR(45) NULL,
`CurrentStatus` TINYINT(1) NOT NULL,
`DateCreated` TIMESTAMP NOT NULL,
`LastUpdated` TIMESTAMP NOT NULL,
PRIMARY KEY (`idAgent`))
ENGINE = InnoDB;
However when I am trying to import the script into MySQL via PhpMyAdmin, it says below.
#1067 - Invalid default value for 'LastUpdated'
I have not provided any default value, so how can it could be "Invalid"?

uses of federated table doesn't work

I wanted to create a federated table so I have the following statement:
CREATE TABLE `ldap` (
`Key_Id` varchar(35) DEFAULT NULL,
`distinguishedName` varchar(250) DEFAULT NULL,
`name` varchar(50) DEFAULT NULL,
`givenName` varchar(50) DEFAULT NULL,
`sn` varchar(50) DEFAULT NULL,
`employeeID` varchar(7) DEFAULT NULL,
`employeeType` varchar(1) DEFAULT NULL,
`title` varchar(100) DEFAULT NULL,
`description` varchar(250) DEFAULT NULL,
`department` varchar(100) DEFAULT NULL,
`company` varchar(50) DEFAULT NULL,
`telephoneNumber` varchar(50) DEFAULT NULL,
`facsimileTelephoneNumber` varchar(30) DEFAULT NULL,
`homePhone` varchar(30) DEFAULT NULL,
`mobile` varchar(30) DEFAULT NULL,
`otherTelephone` varchar(250) DEFAULT NULL,
`otherMobile` varchar(30) DEFAULT NULL,
`otherHomePhone` varchar(30) DEFAULT NULL,
`ST` varchar(50) DEFAULT NULL,
`Mail` varchar(50) DEFAULT NULL,
`physicalDeliveryOfficeName` varchar(50) DEFAULT NULL,
`streetAddress` varchar(250) DEFAULT NULL,
`postalCode` varchar(50) DEFAULT NULL,
`L` varchar(50) DEFAULT NULL,
`sAMAccountName` varchar(50) DEFAULT NULL,
`houseIdentifier` varchar(100) DEFAULT NULL,
`info` varchar(250) DEFAULT NULL,
`showInAddressBook` tinyint(1) DEFAULT NULL,
`displayName` varchar(150) DEFAULT NULL,
KEY `IX_LDAP_distinguishedName` (`distinguishedName`),
KEY `IX_LDAP_employeeID` (`employeeID`)
)
ENGINE=FEDERATED
DEFAULT CHARSET=latin1
CONNECTION='mysql://admin:xxx#cdmysql:3305/node/ldap';
I have in the ldap table more then 1000 rows. I want to recreate this table on the other db and I thought I have to use federated table. But when I use the code above, the ldap table is created, but with no rows. I don't have any errors. what can be the problem?
My version of MySQL is 5.1.73
look at this Post
how can i enable federated engine in mysql after installation?
There is the answer, I had the same issue than you and to solve it I had to Enabled Federated engine in Mysql.
Saludos! :)

MySQL - Querying Large table in MySQL -

This surely seems like poor design of the college_major table.
CREATE TABLE `college_majors` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`date_time` datetime DEFAULT NULL,
`UNITID` varchar(255) DEFAULT NULL,
`CIPCODE` varchar(255) DEFAULT NULL,
`AWLEVEL` varchar(255) DEFAULT NULL,
`CTOTALT` varchar(255) DEFAULT NULL,
`CTOTALM` varchar(255) DEFAULT NULL,
`CTOTALW` varchar(255) DEFAULT NULL,
`CAIANT` varchar(255) DEFAULT NULL,
`CASIAT` varchar(255) DEFAULT NULL,
`CBKAAT` varchar(255) DEFAULT NULL,
`CHISPT` varchar(255) DEFAULT NULL,
`CNHPIT` varchar(255) DEFAULT NULL,
`CWHITT` varchar(255) DEFAULT NULL,
`C2MORT` varchar(255) DEFAULT NULL,
`CUNKNT` varchar(255) DEFAULT NULL,
`CNRALT` varchar(255) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM AUTO_INCREMENT=270167 DEFAULT CHARSET=utf8;
I can reduce this table to three columns - id, CIPCODE and UNITID. But the problem is even simple queries like *select * FROM college_majors* is taking too long to execute and sometime not even executing.
I increased the query execution to 6000.00 sec, but still the query won't run.
Any suggestion on how to improve the design, create a new table and insert the data from this table (college_majors).
Thanks,
A
If field 'codevalue' in college_majors_mapping is unique you can indexed it and increase join performance.

MySQL delete data without query?

I have a client that is describing an occurrence when they are adding new data from a web form. If the submitted data matches any existing database entries, the system deletes the existing entry.
I've checked the scripts and I don't see a DELETE query that would affect the related table. There are UPDATE queries, none of which affect a field in the DB indicating a deletion or marked as deleted.
Are there ways data could be lost without the execution of a DELETE query?
As asked for, here's the "create table" statement:
CREATE TABLE `msp_zip_codes`
(
`zip_code` varchar(5) DEFAULT NULL,
`city` varchar(35) DEFAULT NULL,
`state_prefix` varchar(2) DEFAULT NULL,
`county` varchar(45) DEFAULT NULL,
`area_code` varchar(45) DEFAULT NULL,
`CityType` varchar(1) DEFAULT NULL,
`CityAliasAbbreviation` varchar(13) DEFAULT NULL,
`CityAliasName` varchar(35) DEFAULT NULL,
`lat` decimal(18,6) DEFAULT NULL,
`lon` decimal(18,6) DEFAULT NULL,
`time_zone` varchar(7) DEFAULT NULL,
`Elevation` int(10) DEFAULT NULL,
`CountyFIPS` varchar(5) DEFAULT NULL,
`DayLightSaving` varchar(1) DEFAULT NULL,
`PreferredLastLineKey` varchar(25) DEFAULT NULL,
`ClassificationCode` varchar(2) DEFAULT NULL,
`MultiCounty` varchar(1) DEFAULT NULL,
`StateFIPS` varchar(2) DEFAULT NULL,
`CityStateKey` varchar(6) DEFAULT NULL,
`CityAliasCode` varchar(5) DEFAULT NULL,
`PrimaryRecord` varchar(50) DEFAULT NULL,
`CityMixedCase` varchar(50) DEFAULT NULL,
`CityAliasMixedCase` varchar(50) DEFAULT NULL,
KEY `AreaCode` (`area_code`),
KEY `CityAliasCode` (`CityAliasCode`),
KEY `CityStateKey` (`CityStateKey`),
KEY `ClassificationCode` (`ClassificationCode`),
KEY `PreferredLastLineKey` (`PreferredLastLineKey`),
KEY `ZipCode` (`zip_code`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8
One of the possibilities is that the table has an UPDATE TRIGGER set which fires every time there's an update. Or the other one, there's an Event Scheduler running on the server.
Code to show all triggers on the database:
SELECT *
FROM INFORMATION_SCHEMA.TRIGGERS a
WHERE a.TRIGGER_SCHEMA LIKE CONCAT('%', 'databaseNameHERE', '%')
Code to show all events on the database:
SHOW EVENTS FROM databaseNameHERE;