图书管理系统需要创建7个表,分别用于存储图书,学生和图书分类等信息,这些表将存储在前面创建的永久性表空间bookspace中,由于这7 个表中有很多之间存在外键关系,所以在创建时也需要注意部分表的先后顺序。同时将该7张表存储在bookstore用户下。
时间: 2024-02-25 09:58:45 浏览: 83
好的,下面是创建这7个表的SQL语句,这些表将存储在永久性表空间bookspace中,同时存储在bookstore用户下:
```
-- 创建bookstore用户
CREATE USER bookstore IDENTIFIED BY password;
-- 分配表空间和临时表空间
ALTER USER bookstore DEFAULT TABLESPACE bookspace TEMPORARY TABLESPACE booktemp;
-- 授予必要的角色和权限
GRANT CONNECT, RESOURCE TO bookstore;
-- 创建图书分类表
CREATE TABLE bookstore.book_categories (
category_id NUMBER(10) PRIMARY KEY,
category_name VARCHAR2(50) NOT NULL
);
-- 创建学生表
CREATE TABLE bookstore.students (
student_id NUMBER(10) PRIMARY KEY,
student_name VARCHAR2(100) NOT NULL,
student_email VARCHAR2(100),
student_phone VARCHAR2(20),
student_address VARCHAR2(200)
);
-- 创建图书表
CREATE TABLE bookstore.books (
book_id NUMBER(10) PRIMARY KEY,
book_title VARCHAR2(200) NOT NULL,
book_author VARCHAR2(100) NOT NULL,
book_publisher VARCHAR2(100),
publish_date DATE,
category_id NUMBER(10) REFERENCES bookstore.book_categories(category_id)
);
-- 创建借阅记录表
CREATE TABLE bookstore.book_loans (
loan_id NUMBER(10) PRIMARY KEY,
book_id NUMBER(10) REFERENCES bookstore.books(book_id),
student_id NUMBER(10) REFERENCES bookstore.students(student_id),
loan_date DATE,
due_date DATE,
return_date DATE
);
-- 创建罚款记录表
CREATE TABLE bookstore.fines (
fine_id NUMBER(10) PRIMARY KEY,
loan_id NUMBER(10) REFERENCES bookstore.book_loans(loan_id),
fine_amount NUMBER(10, 2),
paid BOOLEAN DEFAULT FALSE
);
-- 创建预约记录表
CREATE TABLE bookstore.book_reserves (
reserve_id NUMBER(10) PRIMARY KEY,
book_id NUMBER(10) REFERENCES bookstore.books(book_id),
student_id NUMBER(10) REFERENCES bookstore.students(student_id),
reserve_date DATE,
status VARCHAR2(20) DEFAULT 'Pending'
);
-- 创建管理员表
CREATE TABLE bookstore.admins (
admin_id NUMBER(10) PRIMARY KEY,
admin_name VARCHAR2(100) NOT NULL,
admin_email VARCHAR2(100),
admin_phone VARCHAR2(20),
admin_address VARCHAR2(200)
);
```
这7个表的创建顺序需要有先后顺序,因此我们按照表之间的引用关系进行了排序。这些表将存储在永久性表空间bookspace中,并存储在bookstore用户下。
阅读全文