Create data dictionary and create table query of oracle of library management system.
min 5 table
To create a data dictionary and sample table queries for a library management system in Oracle, we can consider the following five tables:
Members table:
Categories table:
Borrowings table:
Reservations table:
Now, let's create the table queries for the above tables:
CREATE TABLE ( book_id NUMBER PRIMARY KEY, title VARCHAR2(100), author VARCHAR2(100), publication_year NUMBER, category_id NUMBER, FOREIGN KEY (category_id) REFERENCES categories(category_id) );
CREATE TABLE members ( member_id NUMBER PRIMARY KEY, name VARCHAR2(100), email VARCHAR2(100), phone_number VARCHAR2(20) );
CREATE TABLE categories ( category_id NUMBER PRIMARY KEY, category_name VARCHAR2(100) );
CREATE TABLE borrowings ( borrowing_id NUMBER PRIMARY KEY book_id NUMBER, member_id NUMBER, borrow_date DATE, return_date DATE, FOREIGN KEY (book_id) REFERENCES books(book_id), FOREIGN KEY (member_id) REFERENCES members(member_id) );
CREATE TABLE reservations ( reservation_id NUMBER PRIMARY KEY, book_id NUMBER, member_id NUMBER, reservation_date DATE, FOREIGN KEY (book_id) REFERENCES books(book_id), FOREIGN KEY (member_id) REFERENCES members(member_id) );
These queries will create the necessary tables in the Oracle database for a library management system.
Create data dictionary and create table query of oracle of library management system.
min 5 table
Sure, let's create a simple data dictionary and tables for a library management system in Oracle that includes five tables: Books
, Members
, Categories
, Borrowings
, and Reservations
.
Data Dictionary:
Books
:
book_id
(Primary Key, Number): Unique identifier for each book.title
(Varchar2): Book's title.author
(Varchar2): Book's author.publication_year
(Number): Year of publication.category_id
(Foreign Key, Number): References to 'Categories' table.Members
:
member_id
(Primary Key, Number): Unique identifier for each member.name
(Varchar2): Member's name.email
(Varchar2): Member's email.phone_number
(Varchar2): Member's phone number.Categories
:
category_id
(Primary Key, Number): Unique identifier for each category.category_name
(Varchar2): Name of the category.Borrowings
:
borrowing_id
(Primary Key, Number): Unique identifier for each borrowing.book_id
(Foreign Key, Number): References to 'Books' table.member_id
(Foreign Key, Number): References to 'Members' table.borrow_date
(Date): Date when the book was borrowed.return_date
(Date): Date when the book is to be returned.Reservations
:
reservation_id
(Primary Key, Number): Unique identifier for each reservation.book_id
(Foreign Key, Number): References to 'Books' table.member_id
(Foreign Key, Number): References to 'Members' table.reservation_date
(Date): Date when the reservation was made.Creation of Tables in Oracle:
Books
:CREATE TABLE Books ( book_id NUMBER PRIMARY KEY, title VARCHAR2(100), author VARCHAR2(100), publication_year NUMBER, category_id NUMBER, FOREIGN KEY (category_id) REFERENCES Categories(category_id));
Members
:CREATE TABLE Members ( member_id NUMBER PRIMARY KEY, name VARCHAR2(100), email VARCHAR2(100), phone_number VARCHAR2(20));
Categories
:CREATE TABLE Categories ( category_id NUMBER PRIMARY KEY, category_name VARCHAR2(100));
Borrowings
:CREATE TABLE Borrowings ( borrowing_id NUMBER PRIMARY KEY, book_id NUMBER, member_id NUMBER, borrow_date DATE, return_date DATE, FOREIGN KEY (book_id) REFERENCES Books(book_id), FOREIGN KEY (member_id) REFERENCES Members(member_id));
Reservations
:CREATE TABLE Reservations ( reservation_id NUMBER PRIMARY KEY, book_id NUMBER, member_id NUMBER, reservation_date DATE, FOREIGN KEY (book_id) REFERENCES Books(book_id), FOREIGN KEY (member_id) REFERENCES Members(member_id));
Remember that you need to create the referenced table before you create tables that reference it. So the order to create the tables should be: Categories
, Books
, Members
, Borrowings
, Reservations
.
Add Authors Table
Sure, let's add an 'Authors' table to the system.
Data Dictionary Addition:
Authors
:
author_id
(Primary Key, Number): Unique identifier for each author.
author_name
(Varchar2): Name of the.Creation of 'Authors' Table in Oracle:
CREATE TABLE Authors ( author_id NUMBER PRIMARY KEY, author_name VARCHAR2(100) );
With this addition, the Books
table should be modified to have a foreign key that references the Authors
table. The 'author' field in Books
table will now be author_id
to ensure data consistency.
**Modified Books Table:
Books
:
book_id
( Key, Number): Unique identifier for each book.title
(Varchar2): Book's title.author_id
(Foreign Key, Number): ID of the book's author linked to Authors
table.publication_year
(Number): Year of publication.category_id
(Foreign Key, Number): References to 'Categories' table.Modification Query for Books Table in Oracle:
Please note that this will work only if the Books table is not created yet. If the Books table is already created, you would need to alter the table or recreate it.
CREATE TABLE Books ( book_id NUMBER PRIMARY KEY, title VARCHAR2(100), author_id NUMBER, publication_year NUMBER, category_id NUMBER, FOREIGN KEY (author_id) REFERENCES Authors(author_id), FOREIGN KEY (category_id) Categories(category_id) );
With this adjustment, we've included the 'Authors' table and established a relationship with the 'Books' table.