0% found this document useful (0 votes)
15 views

DBMS 5

The document details how to insert data into tables in a library database management system. It provides SQL commands to create tables for authors, categories, books, borrowers, and transactions. It then shows how to insert sample data into each table to populate the database.

Uploaded by

devdasisop
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views

DBMS 5

The document details how to insert data into tables in a library database management system. It provides SQL commands to create tables for authors, categories, books, borrowers, and transactions. It then shows how to insert sample data into each table to populate the database.

Uploaded by

devdasisop
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

BCSE-510L

PRACTICAL-5
Aim: To Insert Data in the Tables of Library DBMS.

The "INSERT" command is used to add new records (rows) into a table within a
database. It allows you to specify the values for each column of the table that you're
inserting data into.

SQL Commands & Code:-


-- Create Authors Table

CREATE TABLE Authors (

AuthorID INT PRIMARY KEY,

AuthorName VARCHAR(255) NOT NULL

);

-- Insert sample data into Authors Table

INSERT INTO Authors (AuthorID, AuthorName)

VALUES

(1, 'John Doe'),

(2, 'Jane Smith'),

(3, 'Robert Johnson');

-- Create Categories Table

CREATE TABLE Categories (

CategoryID INT PRIMARY KEY,

CategoryName VARCHAR(50) NOT NULL

);

-- Insert sample data into Categories Table

INSERT INTO Categories (CategoryID, CategoryName)

VALUES

(1, 'Fiction'),
BCSE-510L

(2, 'Non-fiction'),

(3, 'Mystery');

-- Create Books Table

CREATE TABLE Books (

BookID INT PRIMARY KEY,

Title VARCHAR(255) NOT NULL,

AuthorID INT,

ISBN VARCHAR(13),

Genre VARCHAR(50),

FOREIGN KEY (AuthorID) REFERENCES Authors(AuthorID)

);

-- Insert sample data into Books Table

INSERT INTO Books (BookID, Title, AuthorID, ISBN, Genre)

VALUES

(1, 'The Great Gatsby', 1, '9780743273565', 'Fiction'),

(2, 'To Kill a Mockingbird', 2, '0061120081', 'Fiction'),

(3, 'The Da Vinci Code', 3, '0307474275', 'Mystery');

-- Create Borrowers Table

CREATE TABLE Borrowers (

BorrowerID INT PRIMARY KEY,

FirstName VARCHAR(50) NOT NULL,

LastName VARCHAR(50) NOT NULL,

Email VARCHAR(100)

);

-- Insert sample data into Borrowers Table

INSERT INTO Borrowers (BorrowerID, FirstName, LastName, Email)

VALUES
BCSE-510L

(1, 'Alice', 'Johnson', '[email protected]'),

(2, 'Bob', 'Smith', '[email protected]');

-- Create Transactions Table

CREATE TABLE Transactions (

TransactionID INT PRIMARY KEY,

BookID INT,

BorrowerID INT,

TransactionDate DATE,

DueDate DATE,

ReturnDate DATE,

FOREIGN KEY (BookID) REFERENCES Books(BookID),

FOREIGN KEY (BorrowerID) REFERENCES Borrowers(BorrowerID)

);

-- Insert sample data into Transactions Table

INSERT INTO Transactions (TransactionID, BookID, BorrowerID, TransactionDate, DueDate,


ReturnDate)

VALUES

(1, 1, 1, '2024-02-10', '2024-03-10', '2024-03-02'),

(2, 2, 2, '2024-02-11', '2024-03-11', NULL);

-- Create Books_Categories Junction Table

CREATE TABLE Books_Categories (

BookID INT,

CategoryID INT,

PRIMARY KEY (BookID, CategoryID),

FOREIGN KEY (BookID) REFERENCES Books(BookID),

FOREIGN KEY (CategoryID) REFERENCES Categories(CategoryID)

);
BCSE-510L

-- Insert sample data into Books_Categories Table

INSERT INTO Books_Categories (BookID, CategoryID)

VALUES

(1, 1),

(2, 1),

(3, 3);

Database corresponding to above code: -

You might also like