根据此表,reviewid
和prankid
都是自动递增的。
CREATE TABLE Review
(
reviewId INT NOT NULL AUTO_INCREMENT,
email VARCHAR(32) NOT NULL,
prankId INT NOT NULL,
rating INT,
comment VARCHAR(1056) NOT NULL,
PRIMARY KEY(reviewId),
FOREIGN KEY (email) REFERENCES User(email),
FOREIGN KEY (prankId) REFERENCES Prank(prankId)
);
此insert语句是否会正确地将值插入审阅表中的所有属性。
INSERT INTO Review (email, prankId) SELECT email, prankId from User;
INSERT INTO Review (rating, comment) VALUES(‘5’,’amazing!’);
INSERT INTO Review (rating, comment) VALUES(‘5’,’brilliant!’);
答案 0 :(得分:0)
我怀疑你想要这个:
INSERT INTO Review (email, prankId, rating, comment)
SELECT email, prankId, 'S', 'amazing!'
from User;
INSERT INTO Review (email, prankId, rating, comment)
SELECT email, prankId, 'S', 'brilliant'
from User;
在您的版本中,最后两个insert
将失败,因为email
和prankid
为NULL
。请记住,insert
会在表格中添加新行。它不会修改现有的行。