CREATE TABLE member_book_inf (
userid VARCHAR(30) PRIMARY KEY NOT NULL,
username VARCHAR(100) NOT NULL,
rentable_book_number INT NOT NULL DEFAULT 5,
current_rental_book_number INT NOT NULL DEFAULT 0,
total_rental_book INT NOT NULL DEFAULT 0,
FOREIGN KEY (userid) REFERENCES member (userid) ON DELETE CASCADE
);
addJoinMember() {
var memberSql =
"INSERT INTO member (userid, userpassword, username, phone, email) VALUES (?, ?, ?, ?, ?)";
var memberBookInfSql =
"INSERT INTO member_book_inf (userid, username) VALUES (?, ?)";
var param = [
this.userid,
this.userpassword,
this.username,
this.phone,
this.email,
];
var param2 = [this.userid, this.username];
connection.beginTransaction((err) => {
if (err) {
console.log("트랜잭션 에러 :" + err);
} else {
connection.query(memberSql, param, (err, row, fields) => {
if (err) {
console.log("쿼리 1 에러 : " + err);
connection.rollback();
} else {
connection.query(memberBookInfSql, param2, (err, row, fields) => {
if (err) {
console.log("쿼리 2 에러 : " + err);
connection.rollback();
} else {
connection.commit();
console.log("Success Join!!");
connection.end();
}
});
}
});
}
});
}
member 테이블
member_book_inf 테이블