Coverting script for older SQL version to work with 5.6 - mysql

Apologies if my fundamental understanding of the issue is incorrect. I am not very experienced with SQL and am still learning.
I am attempting to generate a table for a data set and was given this script:
CREATE TABLE [dbo].[lobbying](
[uniqid] [varchar](36) NOT NULL, [registrant_raw] [varchar](110) NULL, [registrant] [varchar](50) NULL, [isfirm] [char](1) NULL,
[client_raw] [varchar](110) NULL, [client] [varchar](50) NULL,
[ultorg] [varchar](50) NULL,
[amount] [float] NULL,
[catcode] [char](5) NULL,
[source] [char] (5) NULL,
[self] [char](1) NULL,
[IncludeNSFS] [char](1) NULL,
[use] [char](1) NULL,
[ind] [char](1) NULL,
[year] [char](4) NULL,
[type] [char](4) NULL,
[typelong] [varchar](50) NULL, [affiliate] [char](1) NULL,
) ON [PRIMARY]
As you can probably tell, it doesn't work. The script was updated in 2015 so that is why I presume the issue to be the version. I tried using SQL Fiddle to figure out what was causing the issue, and found that taking the brackets out helped(which makes sense, as the tutorial I was following did not use any brackets for their tables). However, even with that, I still receive the error
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 'use char(1) NULL,
ind char(1) NULL,
year char(4) NULL,
type char(4) NULL,
typelo' at line 10
Does anybody know what the issue is here? Any help would be greatly appreciated. I've poured out about 4 hours into this project so far and have not been able to get past this roadblock.

It is enough to replace the names with brackets with backticks and also remove the brackets around the type nqames
CREATE TABLE lobbying(
`niqid`varchar(36) NOT NULL
, `egistrant_raw`varchar(110) NULL
, `egistrant` varchar(50) NULL
, `isfirm` char(1) NULL,
`client_raw` varchar(110) NULL
, `client` varchar(50) NULL,
`ultorg` varchar(50) NULL,
`amount` float NULL,
`catcode` char(5) NULL,
`source` char(5) NULL,
`self` char(1) NULL,
`IncludeNSFS` char(1) NULL,
`use` char(1) NULL,
`ind` char(1) NULL,
`year` char(4) NULL,
`type` char(4) NULL,
`typelong` varchar(50) NULL
, `affiliate` char(1) NULL
)
✓
db<>fiddle here

Related

mySQL error 1064 on Forward Engineering

Using mySQL workbench, i created an EER diagram and populated it with appropriate data for a class I am in. This is the sample of the generated code that creates the issue:
DROP TABLE IF EXISTS `bhk13`.`person` ;
SHOW WARNINGS;
CREATE TABLE IF NOT EXISTS `bhk13`.`person` (
`per_id` MEDIUMINT GENERATED ALWAYS AS () VIRTUAL,
`per_fname` VARCHAR(15) NOT NULL,
`per_lname` VARCHAR(30) NOT NULL,
`per_city` VARCHAR(45) NOT NULL,
`per_state` CHAR(2) NOT NULL,
`per_street` VARCHAR(45) NOT NULL,
`per_zip` INT NOT NULL,
`per_phone` BIGINT NOT NULL,
`per_email` VARCHAR(100) NOT NULL,
`per_ssn` INT UNSIGNED NOT NULL,
`per_gender` ENUM('m', 'f', 'o') NOT NULL,
`per_dob` DATE NOT NULL,
`per_is_emp` ENUM('y', 'n') NOT NULL,
`per_is_alm` ENUM('y', 'n') NOT NULL,
`per_is_stu` ENUM('y', 'n') NOT NULL,
`per_note` VARCHAR(255) NULL,
PRIMARY KEY (`per_id`))
ENGINE = InnoDB;
SHOW WARNINGS;
when I attempt to forward engineer the database, it generates the following error:
Thread started
Executing SQL script in server
ERROR: 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 ') VIRTUAL,
`per_fname` VARCHAR(15) NOT NULL,
`per_lname` VARCHAR(30) NOT NUL' at line 2
SQL Code:
CREATE TABLE IF NOT EXISTS `bhk13`.`person` (
`per_id` MEDIUMINT GENERATED ALWAYS AS () VIRTUAL,
`per_fname` VARCHAR(15) NOT NULL,
`per_lname` VARCHAR(30) NOT NULL,
`per_city` VARCHAR(45) NOT NULL,
`per_state` CHAR(2) NOT NULL,
`per_street` VARCHAR(45) NOT NULL,
`per_zip` INT NOT NULL,
`per_phone` BIGINT NOT NULL,
`per_email` VARCHAR(100) NOT NULL,
`per_ssn` INT UNSIGNED NOT NULL,
`per_gender` ENUM('m', 'f', 'o') NOT NULL,
`per_dob` DATE NOT NULL,
`per_is_emp` ENUM('y', 'n') NOT NULL,
`per_is_alm` ENUM('y', 'n') NOT NULL,
`per_is_stu` ENUM('y', 'n') NOT NULL,
`per_note` VARCHAR(255) NULL,
PRIMARY KEY (`per_id`))
ENGINE = InnoDB
SQL script execution finished: statements: 9 succeeded, 1 failed
Fetching back view definitions in final form.
Nothing to fetch
What is causing this issue and how can I fix it? All of the data is consistent

Sql error syntaxes with phpmyadmin

Good day,
I have an issue using the phpmyadmin for my database, I'm in new in this and this is the mysql structure from previewmysql:
CREATE TABLE `mydb`.`attendant`
(
`id` INT NOT NULL auto_increment,
`first_name` VARCHAR(20) NOT NULL,
`names` VARCHAR(50) NOT NULL,
`gender` ENUM(0) NOT NULL,
`email` VARCHAR(20) NOT NULL,
`phone` INT(15) NULL,
`marital_status` ENUM(0) NOT NULL,
`added_date` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
`membership` ENUM(0) NOT NULL,
`address` VARCHAR(20) NOT NULL,
`suburb` ENUM(0) NOT NULL,
`partner_name` VARCHAR(25) NULL,
PRIMARY KEY (`id`),
UNIQUE `email_address` (`email`)
)
engine = innodb;
The error is:
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 '0) NOT NULL , `email` VARCHAR(20) NOT NULL , `phone` INT(15) NULL , `marital_sta' at line 1
And also attached is my phpmyadmin table structure.
Will appreciate any help.
Try it.Hope errors goes boom.I just fixed your errors. But your table structure is not good enough. give time, then day by day you will also be expert on it.
CREATE TABLE `mydb`.`attendant`
(
`id` INT NOT NULL auto_increment,
`first_name` VARCHAR(20) NOT NULL,
`names` VARCHAR(50) NOT NULL,
`gender` ENUM('0','1') NOT NULL,
`email` VARCHAR(20) NOT NULL,
`phone` INT(15),
`marital_status` ENUM('0','1') NOT NULL,
`added_date` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
`membership` ENUM('0','1') NOT NULL,
`address` VARCHAR(20) NOT NULL,
`suburb` ENUM('0','1') NOT NULL,
`partner_name` VARCHAR(25) NULL,
PRIMARY KEY (`id`),
UNIQUE `email_address` (`email`)
)
engine = innodb;
Modify ENUM declaration as ENUM ('male', 'female') for gender column and others also as shown in your table. It will not accept ENUM(0).
ENUM(0) is wrong format , if you want that for gender roles then you can use :-
ENUM('Male', 'Female') i.e you can run this query :-
CREATE TABLE `mydb`.`attendant`
(
`id` INT NOT NULL auto_increment,
`first_name` VARCHAR(20) NOT NULL,
`names` VARCHAR(50) NOT NULL,
`gender` ENUM('Male', 'Female') NOT NULL,
`email` VARCHAR(20) NOT NULL,
`phone` INT(15) NULL,
`marital_status` ENUM('Single','Married','divorced') NOT NULL,
`added_date` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
`membership` ENUM('no','yes') NOT NULL,
`address` VARCHAR(20) NOT NULL,
`suburb` ENUM('Cape Town','Woodstock') NOT NULL,
`partner_name` VARCHAR(25) NULL,
PRIMARY KEY (`id`),
UNIQUE `email_address` (`email`)
)
engine = innodb;
You have used ENUM data type in your table. And provided 0 as argument but
An enumeration value must be a quoted string literal
You can refer the mySql documentation for more information
http://dev.mysql.com/doc/refman/5.7/en/enum.html

MySQL create table script with keys

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`)
)

What is wrong with my code for phpmyadmin?

I tried to make a database is phpmyadmin, but I keep getting an 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 '0) NULL,
Datum Verkocht DATE NULL,
Personeel VARCHAR(30) NULL,
`Min' at line 9
That's for this code
CREATE TABLE `veilingen`.`Veilingen`(
`Nr` INT(3) NOT NULL,
`Artikel` VARCHAR(100) NULL,
`Datum Geveild` DATE NULL,
`Tel. Verkoper` INT(10) NULL,
`Datum Ingeleverd` DATE NULL,
`Kast`
SET
(0) NULL,
`Datum Verkocht` DATE NULL,
`Personeel` VARCHAR(30) NULL,
`Minimum` DECIMAL NULL,
`Koop Nu` DECIMAL(100) NULL,
`Geveild Voor` DECIMAL(100) NULL,
`Betaald` ENUM(0) NULL,
`Cadeaubon` DECIMAL(100) NULL,
`Versturen` VARCHAR(100) NULL,
`Opmerkingen` VARCHAR(100) NULL,
PRIMARY KEY(`Nr`(1))
) ENGINE = MyISAM;
Sorry for the mess, I can't get the code span to work.
Can somebody help me?
Following is the right syntax for create table in php, you can edit this code according to your table name,column name and it's datatype.
CREATE TABLE employee (
empId int(11) NOT NULL AUTO_INCREMENT,
empName varchar(255) NOT NULL,
empDept varchar(255) NOT NULL,
PRIMARY KEY (empId)
)

How do i import a mysql dump to SQL Server database

Is it possible to import a mysql dump to a SQL Server database? I have some syntax problems with it.
I have looked through some articles and none of them had helped
Here is how the dump looks like
CREATE TABLE IF NOT EXISTS `search_by_vehicle` (
`id` int(11) NOT NULL auto_increment,
`vendor` varchar(255) NOT NULL,
`car` varchar(255) NOT NULL,
`year` varchar(255) NOT NULL,
`modification` varchar(255) NOT NULL,
`param_pcd` varchar(32) NOT NULL,
`param_dia` varchar(8) NOT NULL,
`param_nut` varchar(32) NOT NULL,
`param_bolt` varchar(32) NOT NULL,
`tyres_factory` text NOT NULL,
`tyres_replace` text NOT NULL,
`tyres_tuning` text NOT NULL,
`wheels_factory` text NOT NULL,
`wheels_replace` text NOT NULL,
`wheels_tuning` text NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
INSERT INTO search_by_vehicle (vendor, car, modification, year, tyres_factory, tyres_replace, tyres_tuning, wheels_factory, wheels_replace, wheels_tuning, param_pcd, param_nut, param_bolt, param_dia)
VALUES( 'Jaguar','S-Type','3.0i','1998','235/50 R17','245/40 R18|245/35 R19','','7.5 x 17 ET45','8 x 18 ET40|8 x 19 ET40','','5*108','12*1.5','','63.3');
You could convert it to SQL Server syntax:
CREATE TABLE search_by_vehicle (
[id] int NOT NULL identity,
[vendor] varchar(255) NOT NULL,
[car] varchar(255) NOT NULL,
[year] varchar(255) NOT NULL,
[modification] varchar(255) NOT NULL,
[param_pcd] varchar(32) NOT NULL,
[param_dia] varchar(8) NOT NULL,
[param_nut] varchar(32) NOT NULL,
[param_bolt] varchar(32) NOT NULL,
[tyres_factory] varchar(max) NOT NULL,
[tyres_replace] varchar(max) NOT NULL,
[tyres_tuning] varchar(max) NOT NULL,
[wheels_factory] varchar(max) NOT NULL,
[wheels_replace] varchar(max) NOT NULL,
[wheels_tuning] varchar(max) NOT NULL,
PRIMARY KEY ([id])
) ;
INSERT INTO search_by_vehicle (vendor, car, modification, year, tyres_factory, tyres_replace, tyres_tuning, wheels_factory, wheels_replace, wheels_tuning, param_pcd, param_nut, param_bolt, param_dia)
VALUES( 'Jaguar','S-Type','3.0i','1998','235/50 R17','245/40 R18|245/35 R19','','7.5 x 17 ET45','8 x 18 ET40|8 x 19 ET40','','5*108','12*1.5','','63.3');
SELECT *
FROM search_by_vehicle;
LiveDemo
Using:
specific tool (for this specific example I used one of online free tool / do not recommend to use online tools when you handle sensitive data)
by hand
Keep in mind that it is not always possible to do it 1:1.
It looks like that column wheels_replace has non-atomic data ('8 x 18 ET40|8 x 19 ET40').
It could cause problems when you need to get specific value or need to join.