用sqlite语句数据库创建学生表、课程表,选课表
时间: 2024-01-15 16:05:36 浏览: 149
创建学生表的sql语句
创建学生表:
CREATE TABLE IF NOT EXISTS students (
id INTEGER PRIMARY KEY AUTOINCREMENT,
name TEXT NOT NULL,
age INTEGER,
gender TEXT,
address TEXT
);
创建课程表:
CREATE TABLE IF NOT EXISTS courses (
id INTEGER PRIMARY KEY AUTOINCREMENT,
name TEXT NOT NULL,
teacher TEXT,
credit INTEGER
);
创建选课表:
CREATE TABLE IF NOT EXISTS course_selections (
id INTEGER PRIMARY KEY AUTOINCREMENT,
student_id INTEGER NOT NULL,
course_id INTEGER NOT NULL,
score INTEGER,
FOREIGN KEY (student_id) REFERENCES students (id) ON DELETE CASCADE ON UPDATE CASCADE,
FOREIGN KEY (course_id) REFERENCES courses (id) ON DELETE CASCADE ON UPDATE CASCADE
);
阅读全文