MySQL MariaDB syntax error - mysql

#1064 - 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 ''Nr_analizes' int NOT NULL, 'AnPacienti_id' int NOT NULL,
This is what I get when I run SQL code in mySQL. What is happening? The sintax looks fine to me.
CREATE TABLE Analiza_laboratorike(
'Nr_analizes' int NOT NULL,
'AnPacienti_id' int NOT NULL,
'Lloji_analizes' varchar(15) NOT NULL,
'Kategoria_pacientit' varchar(15) NOT NULL,
PRIMARY KEY(Nr_analizes),
FOREIGN KEY(AnMjeku_id) REFERENCES Mjeku(Mjeku_id),
Foreign KEY(AnPacienti_id) REFERENCES Pacienti(Pacienti_id))

Column or tables names shouldn't be enclosed in apostrophes:
CREATE TABLE Analiza_laboratorike(
Nr_analizes int NOT NULL,
AnPacienti_id int NOT NULL,
Lloji_analizes varchar(15) NOT NULL,
Kategoria_pacientit varchar(15) NOT NULL,
PRIMARY KEY(Nr_analizes),
FOREIGN KEY(AnMjeku_id) REFERENCES Mjeku(Mjeku_id),
Foreign KEY(AnPacienti_id) REFERENCES Pacienti(Pacienti_id))

Here the CREATE with back Ticks:
CREATE TABLE Analiza_laboratorike(
`Nr_analizes` INT NOT NULL,
`AnPacienti_id INT NOT NULL,
`Lloji_analizes` VARCHAR(15) NOT NULL,
`Kategoria_pacientit` VARCHAR(15) NOT NULL,
PRIMARY KEY(Nr_analizes),
FOREIGN KEY(AnMjeku_id) REFERENCES Mjeku(Mjeku_id),
FOREIGN KEY(AnPacienti_id) REFERENCES Pacienti(Pacienti_id))

Related

Ways to resolve mysql #1064 error in the following code?

I tried using EVERSQL to validate the following code but its also showing error
You have an error in your SQL syntax; it seems the error is around: 'NOT NULL, DepartmentID int NOT NULL, CategoryID int NOT NULL, CourseName V' at line 2
this is my SQL query,
CREATE TABLE Course (
CourseID varchar NOT NULL,
deptID int NOT NULL,
catID int NOT NULL,
CourseName Varchar NOT NULL,
Credit varchar NOT NULL,
PRIMARY KEY (CourseID),
FOREIGN KEY (deptID) REFERENCES department(deptID),
FOREIGN KEY (catID) REFERENCES coursecategory(catID)
);
and this is the error I'm getting
#1064 - 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,
deptID int NOT NULL,
catID int NOT NULL,
CourseName ...' at line 2
You need to specify the lengths of your varchar columns. E.g.:
CREATE TABLE Course (
CourseID varchar(10) NOT NULL,
deptID int NOT NULL,
catID int NOT NULL,
CourseName varchar(10) NOT NULL,
Credit varchar(10) NOT NULL,
PRIMARY KEY (CourseID),
FOREIGN KEY (deptID) REFERENCES department(deptID),
FOREIGN KEY (catID) REFERENCES coursecategory(catID)
);

MySql CONSTRAINT issues

Fetching back view definitions in final form.
Nothing to fetch
Executing SQL script in server results in:
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 'CONSTRAINT `fk_employee_department`
FOREIGN KEY (`dpt_id`)
REFERENCES `r' at line 16
SQL Code:
CREATE TABLE IF NOT EXISTS `rrm17b`.`employee` (
`emp_id` INT UNSIGNED NOT NULL AUTO_INCREMENT,
`dpt_id` INT UNSIGNED NULL,
`emp_first` VARCHAR(20) NOT NULL,
`emp_last` VARCHAR(20) NOT NULL,
`emp_type` ENUM('f', 'p') NOT NULL,
`emp_street` VARCHAR(30) NOT NULL,
`emp_city` VARCHAR(20) NOT NULL,
`emp_state` CHAR(2) NOT NULL,
`emp_zip` INT UNSIGNED NOT NULL,
`emp_phone` BIGINT UNSIGNED NOT NULL,
`emp_email` VARCHAR(45) NOT NULL,
`emp_notes` VARCHAR(100) NULL,
PRIMARY KEY (`emp_id`),
INDEX `fk_employee_department_idx` (`dpt_id` ASC)
CONSTRAINT `fk_employee_department`
FOREIGN KEY (`dpt_id`)
REFERENCES `rrm17b`.`department` (`dpt_id`)
ON DELETE NO ACTION
ON UPDATE NO ACTION)
ENGINE = InnoDB
SQL script execution finished: statements: 9 succeeded, 1 failed
Fetching back view definitions in final form.
Nothing to fetch
Please try this:
CREATE TABLE IF NOT EXISTS rrm17b.employee(
emp_id INT UNSIGNED NOT NULL AUTO_INCREMENT,
dpt_id INT UNSIGNED NULL,
emp_first VARCHAR(20) NOT NULL,
emp_last VARCHAR(20) NOT NULL,
emp_type ENUM('f', 'p') NOT NULL,
emp_street VARCHAR(30) NOT NULL,
emp_city VARCHAR(20) NOT NULL,
emp_state CHAR(2) NOT NULL,
emp_zip INT UNSIGNED NOT NULL,
emp_phone BIGINT UNSIGNED NOT NULL,
emp_email VARCHAR(45) NOT NULL,
emp_notes VARCHAR(100) NULL,
PRIMARY KEY (emp_id),
INDEX fk_employee_department_idx(dpt_id ASC),
CONSTRAINT fk_employee_department
FOREIGN KEY (dpt_id)
REFERENCES rrm17b.department(dpt_id) ON DELETE NO ACTION ON UPDATE NO ACTION) ENGINE = InnoDB
Fixed multiple things:
--Added comma after INDEX
--Removed "`" after dpt_id

MySQL workbench data importing, foreign key error

Im workin in mySQL workbench 8.0CE, i've created two tables, one for person and another one for persons direction, i'm trying to export data, but it throws and error
ERROR 1064 (42000) at line 67: 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 '
CONSTRAINT `fk_PersonaDireccion`
FOREIGN KEY (`idPersona`)
REFERENCES' at line 8
Operation failed with exitcode 1
This is the sql code
CREATE TABLE IF NOT EXISTS `dinSchema`.`Personas` (
`nombre` VARCHAR(20) NOT NULL,
`apellidoP` VARCHAR(20) NOT NULL,
`apellidoM` VARCHAR(20) NOT NULL,
`foto` MEDIUMBLOB NULL,
`fechaCaptura` TIMESTAMP(6) NOT NULL,
`escolaridad` VARCHAR(25) NOT NULL,
`carrera` VARCHAR(25) NULL,
`telefono` VARCHAR(10) NULL,
`correo` VARCHAR(50) NOT NULL,
`sexo` VARCHAR(10) NOT NULL,
`rfc` VARCHAR(13) NOT NULL,
`curp` VARCHAR(18) NOT NULL,
`observaciones` MEDIUMTEXT NULL,
`idPersonas` INT NOT NULL,
PRIMARY KEY (`idPersonas`))
ENGINE = InnoDB;
-- -----------------------------------------------------
-- Table `dinSchema`.`direccion`
-- -----------------------------------------------------
DROP TABLE IF EXISTS `dinSchema`.`direccion` ;
CREATE TABLE IF NOT EXISTS `dinSchema`.`direccion` (
`pais` VARCHAR(6) NOT NULL DEFAULT 'México',
`estado` VARCHAR(20) NOT NULL,
`ciudad` VARCHAR(25) NOT NULL,
`direccion` VARCHAR(150) NOT NULL,
`cp` INT(8) NOT NULL,
`idPersona` INT NOT NULL,
INDEX `fk_PersonaDireccion_idx` (`idPersona` ASC) VISIBLE,
CONSTRAINT `fk_PersonaDireccion`
FOREIGN KEY (`idPersona`)
REFERENCES `dinSchema`.`Personas` (`idPersonas`)
ON DELETE RESTRICT
ON UPDATE CASCADE)
ENGINE = InnoDB;
next i append EER Diagram img
Note: "Personas" id field is at last, beacuse i deleted a foreign key connection.
Somehow i fixed it, unchecked user default global settings in model options, and
INDEX `fk_PersonaDireccion_idx` (`idPersona` ASC) VISIBLE
disapeared, now "direccion" table got like this
CREATE TABLE IF NOT EXISTS `dinSchema`.`direccion` (
`pais` VARCHAR(6) NOT NULL DEFAULT 'México',
`estado` VARCHAR(20) NOT NULL,
`ciudad` VARCHAR(25) NOT NULL,
`direccion` VARCHAR(150) NOT NULL,
`cp` INT(8) NOT NULL,
`idPersona` INT NOT NULL,
CONSTRAINT `fk_PersonaDireccion`
FOREIGN KEY (`idPersona`)
REFERENCES `dinSchema`.`Personas` (`idPersonas`)
ON DELETE RESTRICT
ON UPDATE CASCADE)
ENGINE = InnoDB;

Error when uploading table to server

I am having trouble adding 3 tables to my database (MINOR_DEGREES, STUDENT, STUDENT_RECORD).
Can anyone assist?
Relational Map has been included if there is any confusion.
CREATE TABLE PROFESSOR(
PSSN int NOT NULL,
PName varchar(255) NOT NULL,
PStreet varchar(255) NOT NULL,
PCity varchar(255) NOT NULL,
PState varchar(255) NOT NULL,
PZip int NOT NULL,
PArea int NOT NULL,
PNum int NOT NULL,
PSex ENUM ('M','F') NOT NULL,
PTitle varchar(255) NOT NULL,
PSalary int NOT NULL,
PRIMARY KEY (PSSN)
);
CREATE TABLE DEGREES(
ProfessorSSN int NOT NULL,
PDegrees varchar(255) NOT NULL,
PRIMARY KEY (ProfessorSSN, PDegrees),
FOREIGN KEY (ProfessorSSN) REFERENCES PROFESSOR (PSSN)
);
CREATE TABLE DEPARTMENT(
DNum int NOT NULL,
DName varchar(255) NOT NULL,
DPhone varchar(255) NOT NULL,
DOffice_Location varchar(255) NOT NULL,
PChairSSN int NOT NULL,
PRIMARY KEY (DNum),
FOREIGN KEY (PChairSSN) REFERENCES PROFESSOR (PSSN)
);
CREATE TABLE PRE_REQ(
PreReqCNum int NOT NULL,
PreReqFor varchar(255) NOT NULL,
PreReqTo varchar(255) NOT NULL,
FOREIGN KEY (PreReqCNum) REFERENCES COURSE (CNum) ON DELETE CASCADE
);
CREATE TABLE COURSE(
CNum int NOT NULL,
CTitle varchar(255) NOT NULL,
CUnits int NOT NULL,
CTextBook varchar(255) NOT NULL,
Department_Num int NOT NULL,
PRIMARY KEY (CNum),
FOREIGN KEY (Department_Num) REFERENCES DEPARTMENT (DNum)
);
CREATE TABLE MINOR_DEGREES(
MinorCWID int NOT NULL,
MinorDNum int NOT NULL,
Minor varchar(255) NOT NULL,
PRIMARY KEY (MinorCWID, MinorDNum),
FOREIGN KEY (MinorCWID) REFERENCES STUDENT (SCWID) ON DELETE CASCADE,
FOREIGN KEY (MinorDNum) REFERENCES DEPARTMENT (DNum) ON DELETE CASCADE
);
CREATE TABLE STUDENT(
SCWID int NOT NULL,
SFname varchar(255) NOT NULL,
SLname varchar(255) NOT NULL,
SAdrress varchar(255) NOT NULL,
SPhone int NOT NULL,
Major varchar(255) NOT NULL,
MajorDeptNum int NOT NULL,
PRIMARY KEY (SCWID),
FOREIGN KEY (Major, MajorDeptNum).
);
CREATE TABLE SECTION(
CourseNum int NOT NULL,
SNum int NOT NULL,
Classroom varchar(255) NOT NULL,
Meet_Dates varchar(255) NOT NULL,
Time_Start int NOT NULL,
Time_End int NOT NULL,
No_Of_Seats int NOT NULL,
ProSSN int NOT NULL,
PRIMARY KEY (CourseNum, SNum),
FOREIGN KEY (CourseNum) REFERENCES COURSE (CNum),
FOREIGN KEY (ProSSN) REFERENCES PROFESSOR (PSSN)
);
CREATE TABLE STUDENT_RECORD(
Student_SWID int NOT NULL,
Course_Number int NOT NULL,
Section_Number int NOT NULL,
Grade varchar(255)
PRIMARY KEY (Student_SWID, Course_Number, Section_Number),
FOREIGN KEY (Student_SWID) REFERENCES STUDENT (SCWID)
);
And the errors
Error for MINOR_DEGREES:
ERROR 1064 (42000): 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 'REFERENCES STUDENT (SCWID) ON DELETE CASCADE,
UNIQUE KEY (MinorDNum) REFERENCE' at line 6
Error for STUDENT:
ERROR 1064 (42000): 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 ')' at line 11
Error for STUDENT_RECORD:
ERROR 1064 (42000): 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 '(Student_SWID, Course_Number, Section_Number),
FOREIGN KEY (Student_SWID) RE' at line 6.

i got error when creating table with some foreign key in MySQL

i got error when creating table with some foreign key in MySQL, here is my script :
CREATE TABLE tbl_mt_kuliah (
KD_AUTO INT (4) NOT NULL AUTO_INCREMENT,
NIM INT (10) NOT NULL,
KD_MATA_KULIAH INT (4) NOT NULL,
RUANG VARCHAR (4) NOT NULL,
KD_DOSEN INT (4) NOT NULL,
JAM TIME NOT NULL,
HARI DATE NOT NULL,
TH_AJARAN YEAR NOT NULL,
SMESTER INT (2) NOT NULL,
PRIMARY KEY KD_AUTO,
FOREIGN KEY FK_MATKUL(KD_MATA_KULIAH) REFERENCES mt_kuliah (KD_MATA_KULIAH),
FOREIGN KEY FK_MHS(NIM) REFERENCES tbl_mahasiswa (NIM),
FOREIGN KEY FK_DOSEN(KD_DOSEN) REFERENCES tbl_dosen (KD_DOSEN)
);
and here is the error :
Error Code: 1064
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 '
foreign KEY FK_MATKUL(KD_MATA_KULIAH) references mt_kuliah (KD_MATA_KULIAH),
' at line 12
I think this will help you.
CREATE TABLE tbl_mt_kuliah (
KD_AUTO INT (4) NOT NULL AUTO_INCREMENT,
NIM INT (10) NOT NULL,
KD_MATA_KULIAH INT (4) NOT NULL,
RUANG VARCHAR (4) NOT NULL,
KD_DOSEN INT (4) NOT NULL,
JAM TIME NOT NULL,
HARI DATE NOT NULL,
TH_AJARAN YEAR NOT NULL,
SMESTER INT (2) NOT NULL,
PRIMARY KEY (KD_AUTO),
CONSTRAINT FK_MATKUL FOREIGN KEY (KD_MATA_KULIAH) REFERENCES mt_kuliah (KD_MATA_KULIAH),
CONSTRAINT FK_MHS FOREIGN KEY (NIM) REFERENCES tbl_mahasiswa (NIM),
CONSTRAINT FK_DOSEN FOREIGN KEY (KD_DOSEN) REFERENCES tbl_dosen (KD_DOSEN)
);