0% found this document useful (0 votes)
11 views4 pages

TMP 619711440170051879

The document outlines the SQL commands to create a database named LIBRARY2 and its associated schema and tables for managing a library system. It includes definitions for tables such as books, authors, members, reservations, fines, and their relationships. Each table has specified constraints for primary and unique keys to ensure data integrity.

Uploaded by

way93185
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views4 pages

TMP 619711440170051879

The document outlines the SQL commands to create a database named LIBRARY2 and its associated schema and tables for managing a library system. It includes definitions for tables such as books, authors, members, reservations, fines, and their relationships. Each table has specified constraints for primary and unique keys to ensure data integrity.

Uploaded by

way93185
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Made with Xodo PDF Reader and Editor

‫المشاريع‬

use master;
GO
CREATE DATABASE LIBRARY2
ON
(NAME = LIBRARY2_DATA,
FILENAME = 'C:\Program Files\Microsoft SQL
Server\MSSQL16.MSSQLSERVER2\MSSQL\DATA\LIBRARY2_DATA.mdf',
SIZE = 100,
MAXSIZE = 250,
FILEGROWTH = 50)
LOG ON

(NAME = LIBRARY2_LOG,
FILENAME = 'C:\Program Files\Microsoft SQL
Server\MSSQL16.MSSQLSERVER2\MSSQL\DATA\LIBRARY2_LOG.ldf',
SIZE = 50,
MAXSIZE = 100,
FILEGROWTH = 25);
GO

use LIBRARY2 ;
GO
create schema library;
GO

create table library.books


(
book_id int,
title varchar(50) not null,
numper_parts int ,
Made with Xodo PDF Reader and Editor

category_id int not null,


copies_owned int not null,
constraint books_pk primary key (book_id),
constraint books_uq unique (category_id)
);

create table library.authors


(
author_id int,
first_name varchar(20) not null,
last_name varchar(20) not null,
constraint authors_pk primary key (author_id)
);

create table library.books_authors


(
book_id int not null,
author_id int not null,
constraint books_uq unique (book_id, author_id)
);

create table library.category


(
category_id int,
category_name varchar(20) not null,
constraint category_pk primary key (category_id)
);

create table library.members


(
member_id int,
first_name varchar(20) not null,
last_name varchar(20) not null,
joined_date date not null,
Made with Xodo PDF Reader and Editor

member_status_id int not null,


constraint member_pk primary key (member_id),
constraint member_uq unique (member_status_id)
);

create table library.reservation


(
reservation_id int,
book_id int not null,
member_id int not null,
resrvation_date date not null,
reservation_status_id int not null,
constraint reservation_pk primary key (reservation_id),
constraint reservation_uq unique (book_id, member_id,
reservation_status_id)
);

create table library.reservation_status


(
reservation_status_id int,
status_value varchar(10) not null,
constraint reservation_status_pk primary key (reservation_status_id)
);

create table library.fine_payment


(
fine_payment_id int,
member_id int not null,
payment_date date not null,
payment_amount numeric(9,3) check (payment_amount between 500 and
900000),
constraint fine_payment_pk primary key (fine_payment_id),
constraint fine_payment_uq unique (member_id)
);
Made with Xodo PDF Reader and Editor

create table library.loan


(
loan_id int,
book_id int not null,
member_id int not null,
loan_date date not null,
returned_date date not null,
constraint loan_pk primary key (loan_id),
constraint loan_uq unique (book_id, member_id)
);

create table library.fine


(
fine_id int,
member_id int not null,
loan_id int not null,
fine_date date not null,
fine_amount numeric(9,3) check (fine_amount between 900000 and 500),
constraint fine_pk primary key (fine_id),
constraint fine_uq unique (member_id, loan_id)
);

create table library.member_status


(
member_status_id int,
status_value varchar(10) not null,
constraint member_status_pk primary key (member_status_id)
);

You might also like