SportId = 1;MySQL DELETEが機能しない
上記を実行すると、このエラーが発生します。私を助けてください;
DogSportはuse.Errorである:(、dogsport
をorders
CONSTRAINT orders_ibfk_1
FOREIGN KEY(EqId
)equipment
(EqId
)を参照する。)外部キー制約が失敗します= 1 SportIdは、親行を削除または更新できないスポーツ。DELETE FROM
/* Creating Sport table */
CREATE TABLE Sport(
SportId INT NOT NULL AUTO_INCREMENT,
SportName VARCHAR(20) NOT NULL,
Description VARCHAR(200) NOT NULL,
PRIMARY KEY(SportId)
);
/* Inserting values for Sport table */
INSERT INTO Sport(SportName,Description)
VALUES('Agility','This is a fun dog sport which a handler directs a dog through a course of obstacles. Body motion, speed, hand signals are used by the handler to direct the dog.'),
('Flyball','Energetic and exciting sport which is also called drag racing for dogs'),
('Disc Dog','This sport is also known as Frisbee dog. The sport involves the bond between the owner and dog, by letting them to work together'),
('Dog Diving','This sport involves loving run, jumping, and swimming. This is a very popular sport nowadays'),
('Cani-Cross','This is a sport event which running off-road with dogs. It is an useful sport which keeps the owner and the dog fit by a physical workout and directional commands.');
/* Creating UserSport table */
CREATE TABLE UserSport(
UserId INT NOT NULL,
SportId INT NOT NULL,
PRIMARY KEY(UserId,SportId),
FOREIGN KEY(UserId) REFERENCES User(UserId) ON DELETE CASCADE,
FOREIGN KEY(SportId) REFERENCES Sport(SportId) ON DELETE CASCADE
);
/* Inserting values for UserSport table */
INSERT INTO UserSport(UserId,SportId)
VALUES(1,2),
(1,4),
(1,3),
(1,5);
/* Creating Equipment table */
CREATE TABLE Equipment(
EqId INT NOT NULL AUTO_INCREMENT,
EqName VARCHAR(40) NOT NULL,
Price DECIMAL(9,2) NOT NULL,
SportId INT NOT NULL,
PRIMARY KEY(EqId),
FOREIGN KEY(SportId) REFERENCES Sport(SportId) ON DELETE CASCADE
);
/* Inserting values for Equipment table */
INSERT INTO Equipment(EqName,Price,SportId)
VALUES('Wing Jump',6700,1),
('Tire',4500,1),
('Open Tunnel',9000,1),
('Chute',3000,1),
('Boomerang Flyball Box',6300,2),
('Training Box',4200,2),
('Flyball Jumps',7800,2),
('Can Am Flyball Box',3100,2),
('Flyball Harness',1800,2),
('Balance Disc',2000,3),
('Training Punches',1000,3),
('Retrieve Water Ring',4500,4),
('Dive Jacket',3000,4),
('Aqua Floating Toy',1500,4),
('Cani-Cross Harness',4000,5),
('PawZ Dog Boots',1000,5),
('Custom Shoulder Harness',3000,5);
/* Creating User table */
CREATE TABLE User(
UserId INT NOT NULL AUTO_INCREMENT,
Title VARCHAR(5) NOT NULL,
FName VARCHAR(20) NOT NULL,
LName VARCHAR(20) NOT NULL,
Email VARCHAR(30) NOT NULL UNIQUE,
Phone VARCHAR(15),
Address VARCHAR(30) NOT NULL,
Password VARCHAR(20) NOT NULL UNIQUE,
PRIMARY KEY(UserId)
);
/* Inserting values for User table */
INSERT INTO User(Title,FName,LName,Email,Phone,Address,Password)
VALUES('Mr.','Raveen','Chandra','[email protected]','0778547079','Ambalangoda','123'),
('Miss','Bisma','Ishani','[email protected]','0785234123','Colombo','456'),
('Dr','Shantha','Kumara','[email protected]','0912374392','Ambalangoda','789'),
('Ms.','Madusha','Perera','[email protected]','0782361490','Galle','3235');
機器の子テーブルであるテーブルがありません.... –