New MySQL version breaking queries - mysql

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.

Related

Create Table mySql syntax error (working on other versions)

When creating a table in MySQL Version 5.7.21 on a Linux server I get the following error message:
" 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 arbeitstageprowocheab date DEFAULT NULL,
urlaubstageprojahr int(3) DEFAULT '"
when creating the following table:
CREATE TABLE arbeitsvertragsdaten (
personalnummer int(11) NOT NULL,
mailadresse varchar(50) DEFAULT NULL,
handynummerxenium varchar(50) DEFAULT NULL,
status varchar(20) DEFAULT NULL,
position varchar(50) DEFAULT NULL,
probezeitende date DEFAULT NULL,
wochenarbeitszeit int(11) DEFAULT NULL,
wochenarbeitszeitab date DEFAULT NULL,
teilzeitbefristet tinyint(1) DEFAULT NULL,
teilzeitende date DEFAULT NULL,
ueberstundenquotient double DEFAULT NULL,
arbeitstageprowoche int(11) DEFAULT NULL,
arbeitstageprowocheab date DEFAULT NULL,
urlaubstageprojahr int(3) DEFAULT NULL,
urlaubstageprojahrab date DEFAULT NULL,
mutterschutzbeginn date DEFAULT NULL,
mutterschutzende date DEFAULT NULL,
elternzeitbeginn date DEFAULT NULL,
elternzeitende date DEFAULT NULL);
It did work on my local machine for development on Version 8.0.16 (Community Server)
Any ideas whats wrong with my syntax?
There is syntax issue.
CREATE TABLE `arbeitsvertragsdaten` (
`personalnummer` int(11) NOT NULL,
`mailadresse` varchar(50) DEFAULT NULL,
`handynummerxenium` varchar(50) DEFAULT NULL,
`status` varchar(20) DEFAULT NULL,
`position` varchar(50) DEFAULT NULL,
`probezeitende` date DEFAULT NULL,
`wochenarbeitszeit` int(11) DEFAULT NULL,
`wochenarbeitszeitab` date DEFAULT NULL,
`teilzeitbefristet` tinyint(1) DEFAULT NULL,
`teilzeitende` date DEFAULT NULL,
`ueberstundenquotient` double DEFAULT NULL,
`arbeitstageprowoche` int(11) DEFAULT NULL,
`arbeitstageprowocheab` date DEFAULT NULL,
`urlaubstageprojahr` int(3) DEFAULT NULL,
`urlaubstageprojahrab` date DEFAULT NULL,
`mutterschutzbeginn` date DEFAULT NULL,
`mutterschutzende` date DEFAULT NULL,
`elternzeitbeginn` date DEFAULT NULL,
`elternzeitende` date DEFAULT NULL
); ----- here ) is missing.

Not getting expected Output while trying to alter a column default value

Problem:
I have created a table with a given structure:
CREATE TABLE `X` (
`ID` int(11) NOT NULL AUTO_INCREMENT,
`MSISDN` varchar(25) DEFAULT NULL,
`subservice_id` varchar(25) DEFAULT NULL,
`SUB_START_DATE` datetime DEFAULT NULL,
`START_DATE` datetime DEFAULT NULL,
`END_DATE` datetime DEFAULT NULL,
`scheduler_renewal_status` varchar(25) NOT NULL DEFAULT 'scheduled',
`STATUS` varchar(20) DEFAULT NULL,
`LAST_RENEW_DATE` datetime DEFAULT NULL,
`LAST_CALL_DATE` datetime DEFAULT NULL,
`TRANSACTION_STATUS` varchar(15) DEFAULT NULL,
`CIRCLE` varchar(3) DEFAULT NULL,
`COUNTRY` varchar(3) DEFAULT NULL,
`LANGUAGE` varchar(3) DEFAULT NULL,
`price` float DEFAULT '0',
`CALL_ATTEMPTS` int(3) DEFAULT NULL,
`PRIMARY_ACT_MODE` varchar(25) DEFAULT NULL,
`SECONDARY_ACT_MODE` varchar(25) DEFAULT NULL,
`ERROR_MSG` varchar(25) DEFAULT NULL,
`SUB_TYPE` varchar(10) DEFAULT NULL,
`SUB_TIME_LEFT` int(3) DEFAULT '0',
`SUB_SERVICE_NAME` varchar(25) DEFAULT NULL,
`OPERATOR` varchar(25) DEFAULT NULL,
`GIFT_ID` varchar(25) DEFAULT NULL,
`service_id` varchar(25) DEFAULT NULL,
`RETRY_COUNT` int(2) NOT NULL DEFAULT '0',
`NEXT_RETRY_DATE` datetime DEFAULT NULL,
`CPID` int(11) DEFAULT NULL,
`SCHEDULER_RETRY_STATUS` varchar(25) DEFAULT 'scheduled',
`scheduler_statechanger_status` varchar(25) DEFAULT 'scheduled',
`scheduler_subs_msgs_status` varchar(25) DEFAULT 'scheduled',
`serviceName` varchar(25) DEFAULT NULL,
`transactionId` varchar(25) DEFAULT NULL,
`nextAction` varchar(25) DEFAULT NULL,
`topUpPrice` int(3) DEFAULT NULL,
`topUp_time_left` int(5) NOT NULL DEFAULT '0',
`autoRenew` varchar(10) DEFAULT NULL,
`option1` varchar(25) DEFAULT NULL,
`callBackRecvFlag` varchar(10) DEFAULT NULL,
`last_msg_date` date DEFAULT NULL,
`accountType` varchar(10) DEFAULT 'prepaid',
`optkey` varchar(20) DEFAULT NULL,
`successCallCount` int(3) DEFAULT '0',
PRIMARY KEY (`ID`),
UNIQUE KEY `UK_3` (`MSISDN`,`subservice_id`)
) ENGINE=InnoDB AUTO_INCREMENT=27793 DEFAULT CHARSET=utf8
I want to change the column SUB_START_DATE default type from NULL to TIMESTAMP.
Can anyone guide me the proper syntax for this
Solution:
I am running the following Command:
ALTER TABLE `X` MODIFY COLUMN SUB_START_DATE TIMESTAMP NOT NULL DEFAULT current_timestamp;
It is affecting the rows of the table.
But,if I want to have column datatype datetime only and change the default value to current_timestamp.
I ran the following command:
ALTER TABLE `X` MODIFY COLUMN SUB_START_DATE datetime DEFAULT current_timestamp;
OutputShown:
Error Code : 1067
Invalid default value for 'SUB_START_DATE'
In this case my SQL server does not allow to modify existing default constraint value. So to change the default value we need to delete the existing system generated or user generated default constraint. And after that default value can be set for a particular column.
Follow some steps :
List all existing default value constraints for columns.
Execute this system database procedure, it takes table name as a parameter. It returns list of all constrains for all columns within table.
execute [dbo].[sp_helpconstraint] 'table_name'
Drop existing default constraint for a column.
Syntax:
alter table 'table_name' drop constraint 'constraint_name'
Add new default value constraint for that column:
Syntax:
alter table 'table_name' add default 'current_timestamp' for 'SUB_START_DATE '

Search invisible characters in mysql

There are some columns in my mysql table which contain values such as "Sbeed Pharmaceuticals åÊ" . Two questions:
How do I prevent getting these characters from getting into the table in the first place ?
How do I find rows containing these characters ?
Here is the table:
CREATE TABLE `drugs` (
`drug-id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`th-class` varchar(512) DEFAULT NULL,
`division` varchar(512) DEFAULT NULL,
`name` varchar(512) DEFAULT NULL,
`brand-name` varchar(64) DEFAULT NULL,
`pack` varchar(512) DEFAULT NULL,
`rx-type` varchar(16) DEFAULT NULL,
`pack-form` varchar(128) DEFAULT NULL,
`available-in` varchar(512) DEFAULT NULL,
`mrp` double DEFAULT '-1',
`mrp-per-unit` double DEFAULT NULL,
`manufacturer` varchar(512) DEFAULT NULL,
`schemes` text,
`drug-status` varchar(64) DEFAULT 'new',
`created-by` varchar(512) DEFAULT NULL,
`created-at` datetime DEFAULT CURRENT_TIMESTAMP,
`approved-at` datetime DEFAULT NULL,
`approved-by` varchar(512) DEFAULT NULL,
`dosage` varchar(64) DEFAULT NULL,
`manufacturer-id` int(10) DEFAULT NULL,
PRIMARY KEY (`drug-id`),
UNIQUE KEY `name` (`name`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

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 remove uuid function from table

I have a table that was inherited from a different system and one of the fields has the UUID function enabled so no matter what ID I generate and try to insert, the table creates a completely different one automatically.
I would like to use a PHP function to create the ID instead but I can't workout how to remove the UUID function from the field.
I am not sure what information will be needed to help you so please feel free to ask.
The field in question is
id, char(36)
Table definaition is..
CREATE TABLE `users` (
`id` char(36) NOT NULL,
`user_name` varchar(60) default NULL,
`user_hash` varchar(32) default NULL,
`diary_weekly_view` varchar(500) NOT NULL,
`week_start` date NOT NULL,
`diary_monthly_view` varchar(300) NOT NULL,
`diary_view` int(1) NOT NULL default '1',
`account_search` varchar(1000) NOT NULL,
`cases_search` varchar(500) NOT NULL,
`serials_search` varchar(500) NOT NULL,
`type` varchar(8) NOT NULL,
`email` varchar(255) NOT NULL,
`notes` varchar(3000) NOT NULL,
`authenticate_id` varchar(100) default NULL,
`sugar_login` tinyint(1) default '1',
`first_name` varchar(30) default NULL,
`last_name` varchar(30) default NULL,
`reports_to_id` char(36) default NULL,
`is_admin` tinyint(1) default '0',
`receive_notifications` tinyint(1) default '1',
`date_entered` datetime NOT NULL,
`date_modified` datetime NOT NULL,
`modified_user_id` char(36) default NULL,
`created_by` char(36) default NULL,
`phone_office` varchar(50) default NULL,
`phone_mobile` varchar(50) default NULL,
`status` varchar(25) default NULL,
`address_street` varchar(150) default NULL,
`address_city` varchar(100) default NULL,
`address_state` varchar(100) default NULL,
`address_country` varchar(25) default NULL,
`address_postalcode` varchar(9) default NULL,
`user_preferences` text,
`deleted` tinyint(1) NOT NULL default '0',
`portal_only` tinyint(1) default '0',
`employee_status` varchar(25) default NULL,
`is_group` tinyint(1) default '0',
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf
OK, sussed it, I removed the index and then recreated the index with INDEX