不确定为什么但是当我尝试对creditcard表执行insert语句时,它给了我一个重复条目的错误。我的主键是cardNumber,外键是电子邮件(取自用户表)。 insert语句如下所示。
INSERT INTO CreditCard (email) SELECT email FROM User;
INSERT INTO CreditCard (cardNumber, name, cvv, expiryMonth, expiryyear)
VALUES('3345678902345678','alicia','444','08','2015');
INSERT INTO CreditCard (cardNumber, name, cvv, expiryMonth, expiryyear)
VALUES('2345678902222278','javier','442','01','2015');
INSERT INTO CreditCard (cardNumber, name, cvv, expiryMonth, expiryyear)
VALUES('2111678902345678','eddy','344','02','2015');
INSERT INTO CreditCard (cardNumber, name, cvv, expiryMonth, expiryyear)
VALUES('1111678902345678','vanessa','224','01','2015');
INSERT INTO CreditCard (cardNumber, name, cvv, expiryMonth, expiryyear)
VALUES('7777778902345678','aaron','400','03','2015');
信用卡和用户的创建表:
CREATE TABLE CreditCard
(
cardNumber CHAR(16) NOT NULL,
email VARCHAR(32) NOT NULL,
name VARCHAR (32) NOT NULL,
cvv CHAR(3) NOT NULL,
expiryMonth INT NOT NULL,
expiryYear INT NOT NULL,
PRIMARY KEY(cardNumber),
FOREIGN KEY (email) REFERENCES User(email) ON UPDATE CASCADE
);
CREATE TABLE User
(
email VARCHAR(32) NOT NULL,
name VARCHAR(32) NOT NULL,
password VARCHAR(32) NOT NULL,
dateOfBirth DATE NOT NULL,
PRIMARY KEY(email)
);