CREATE TABLE students (
student_id INT PRIMARY KEY,
name VARCHAR(50),
major VARCHAR(50)
);
CREATE TABLE textbooks (
textbook_id INT PRIMARY KEY,
title VARCHAR(100),
author VARCHAR(50),
price DECIMAL(10, 2)
);
CREATE TABLE orders (
order_id INT PRIMARY KEY,
student_id INT,
textbook_id INT,
quantity INT,
FOREIGN KEY (student_id) REFERENCES students(student_id),
FOREIGN KEY (textbook_id) REFERENCES textbooks(textbook_id)
);
def add_textbook(title, author, price):
# 假设已连接数据库
cursor.execute("INSERT INTO textbooks (title, author, price) VALUES (%s, %s, %s)",
(title, author, price))
db.commit()