N
N
Nikita Zelikov2021-07-31 14:58:55
MySQL
Nikita Zelikov, 2021-07-31 14:58:55

Error when working with Mysql, what's the problem?

They gave a task in which the name of the Group table is indicated, knowing that it is reserved, inserted it through quotes, but there was a problem creating a many-to-many relationship, I get the following 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 'FOREIGN KEY (idGame) REFERENCES `Group` (id))' at line

6

Create Table 
Team(
   id INT NOT NULL AUTO_INCREMENT,
   name VARCHAR(50) NOT NULL,
   country VARCHAR(50),
   PRIMARY KEY ( id )
);

INSERT INTO Team (id, name, country) VALUES (1, 'Team 1', 'Беларусь');
INSERT INTO Team (id, name, country) VALUES (2, 'Team 2', 'Испания');
INSERT INTO Team (id, name, country) VALUES (3, 'Team 3', 'Франция');
INSERT INTO Team (id, name, country) VALUES (4, 'Team 4', 'Россия');
INSERT INTO Team (id, name, country) VALUES (5, 'Team 5', 'Россия');

Create table 
`Group`(
   id INT NOT NULL AUTO_INCREMENT,
   name VARCHAR(50) NOT NULL,
   PRIMARY KEY ( id )
);

INSERT INTO `Group` (id, name) VALUES (1, 'Group A');
INSERT INTO `Group` (id, name) VALUES (2, 'Group B');
INSERT INTO `Group` (id, name) VALUES (3, 'Group C');

Create table 
Game(
   idTeam INT NOT NULL,
   idGame INT NOT NULL,
   FOREIGN KEY (idTeam) REFERENCES Team (id)
   FOREIGN KEY (idGame) REFERENCES `Group` (id)
);

Answer the question

In order to leave comments, you need to log in

1 answer(s)
T
toxa82, 2021-07-31
@toxa82

CONSTRAINT `fk_idTeam`
    FOREIGN KEY (`idTeam`)
    REFERENCES `Group` (`id`)
    ON DELETE RESTRICT
    ON UPDATE RESTRICT,

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question