I have a mysql commands
mysql> create table enrolled (snum int,cname varchar(20), primary key (snum,cname),
foreign key(snum) references student (snum),
foreign key (came ) references class (cname)
on delete cascade );
When I run it , I get an ERROR
ERROR 1604 (42000) :You have an ERROR in your SQL syntax ; check manual that corresponds to your MYSQL server version for the right syntax to use near 'mysql> create table enrolled ( sum int, cname varchar(20) primary key(snum ,cnam' at line 1
Change
foreign key (came )
To this
foreign key (cname )
Related
Apply changes to exams Error 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 '
CONSTRAINT `reg`
FOREIGN KEY (`reg`)
REFERENCES `students`.`stdinf...
at line 6 SQL Statement:
CREATE TABLE `students`.`exams`
(
`reg`VARCHAR(25) NOT NULL,
`code`VARCHAR(10) NOT NULL,
`marks` INT NULL,
PRIMARY KEY (`reg`, `code`),
INDEX `code_idx` (`code`ASC) VISIBLE,
CONSTRAINT`reg`
FOREIGN KEY (`reg`)
REFERENCES `students`.`stdinfo` (`reg`)
ON DELETE NO ACTION
ON UPDATE NO ACTION,
CONSTRAINT `code`
FOREIGN KEY (`code`)
REFERENCES `students`.`courses` (`code\`)
ON DELETE NO ACTION
ON UPDATE NO ACTION
)
I wanted to make foreign key in third table for connecting my other two tables but it showing this error.
I have three tables in my database
Books(table)
create table books (book_id int auto_increment, bookName varchar(10), qty int,primary key(book_id));
Students(table)
create table students (student_id int auto_increment,studentName varhchar(10),primary key(student_id));
issuedBooks(table)
create table issuedBooks(book_id int ,student_id int ,issued_date date, foreign key (book_id) references books(book_id), foreign key (students) references students(student_id));
mysql report an error that
ERROR 1064 (42000): 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 'references students(student_id))' at line 1
When I remove second foreign key, It works. I don't understand what mistake did I do?
Works(without any error, I just removed second foreign key)
create table issuedBooks(book_id int ,student_id int,issued_date date, foreign key (book_id) references books(book_id));
image of the code and error
CREATE TABLE Ticket(
-> Ticket_No INT PRIMARY KEY NOT NULL AUTO_INCREMENT,
-> BusID INT,
-> Registration_No INT,
-> Seat_No INT NOT NULL,
-> FOREIGN KEY BusID REFERENCES Bus(BusID),
-> FOREIGN KEY Registration_No REFERENCES Passenger(Registration_No));
Error message:
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 Bus(BusID),
FOREIGN KEY Registration_No REFERENCES Passenger(Registra' at line 6
I am trying to add foreign keys to this table but this error message keeps appearing. The referenced table and column name is correct. I have also tried changing the column name. Please help.
You need to put parenthesis around the referencing column(s).
...
FOREIGN KEY (BusID) REFERENCES Bus(BusID),
...
And analog for the other one.
I am trying to create a table favorite_food in which I have a constraint, a foreign key referencing a person_id. I'm using MySQL version 5.7.20 Here is the error message:
ERROR 1064 (42000): 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_fav_food_person_id FOREIGN KEY
(person_id) REFERENCES person (pers' at line 1
Here is the command:
mysql> CREATE TABLE favorite_food (
person_id SMALLINT UNSIGNED,
food VARCHAR(20),
CONSTRAINT pk_favorite_food PRIMARY KEY (person_id, food)
CONSTRAINT fk_fav_food_person_id FOREIGN KEY (person_id) REFERENCES
person (person_id) );
I'm trying to understand why a parsing error occurred (1064) with the following 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 '' at line 3>
CREATE TABLE Party_Library
(
Party INT(11)
Library varchar(40)
PRIMARY KEY (Library,Party)
FOREIGN KEY (Party) REFERENCES Party(PartyKey) ON DELETE CASCADE
FOREIGN KEY (Library) REFERENCES MusicLibraries(MusicSource) ON DELETE CASCADE
)
You are missing commas after each declaration:
CREATE TABLE Party_Library
(
Party INT(11),
Library varchar(40),
PRIMARY KEY (Library,Party),
FOREIGN KEY (Party) REFERENCES Party(PartyKey) ON DELETE CASCADE,
FOREIGN KEY (Library) REFERENCES MusicLibraries(MusicSource) ON DELETE CASCADE
);