DBMS Practical File
DBMS Practical File
Experiment
-1
Introduction to SQL
● SQL stands for Structured query language .
● It is a special purpose programming language designed for managing data held in a
relational DBMS.
● SQL was initially developed at IBM by Donald Chamberlin and Raymond Boyes in the
early 1970s this person initially called SEQUEL (Structured English Query Language).
● It is standard language for accessing and manipulating database.
Features of SQl
● It can be used by a range of users including those with little or no programming experience.
● It is non procedural language .
● It reduces the amount of time required for creating and manipulating system.
● It is an english like language.
RDBMS
● Its stands for Relation DataBase Management.
1
Vanshika Tiwari 23100BTCSAII14332
Experiment
● It is the basis for SQL and for all modern database systems such as MySql , MS Sql server , DB2
, Microsoft Access.
2
Vanshika Tiwari 23100BTCSAII14332
Experiment
● This command is the heart of the SQL ● DQL commands
■ SELECT
-2
DB Schema for E-Commerce Data Source Organisation
EBAY_APP
USER_DETAILS
PRODUCT_DETAILS
PURCHASING_TABLE
PAYMENT_DETAILS
3
Vanshika Tiwari 23100BTCSAII14332
Experiment
DISCOUNT_TABLE
BRAND_OUTLETS
SELLING_TABLE
REVIEW_TABLE
4
Vanshika Tiwari 23100BTCSAII14332
Experiment
-3
ER Diagram for DBMS Application
5
Vanshika Tiwari 23100BTCSAII14332
Experiment
Experiment -4
SQL Commands
6
Vanshika Tiwari 23100BTCSAII14332
Experiment
Aim: To study and execute various SQL commands for an eCommerce database of
an eBay-like application.
The CREATE DATABASE command is used to create a new database in SQL. A database is a
structured collection of data that allows efficient storage and retrieval of information.
Syntax:
Example:
To start working with this database, we need to select it using the USE command.
Syntax:
USE <database_name>;
7
Vanshika Tiwari 23100BTCSAII14332
Example:
USE eBayDB;
This sets eBayDB as the active database, allowing all subsequent queries to be executed within
this database.
The CREATE TABLE command is used to create tables within a database. A table consists of
columns, each with a specific data type and constraints.
Basic Syntax
...
1. Primary Key
8
Vanshika Tiwari 23100BTCSAII14332
A Primary Key is a column (or a set of columns) in a table that uniquely identifies each row in
that table. It ensures that the values in this column(s) are unique and not NULL.
Column2 DataType,
...
);
2. Foreign Key
A Foreign Key is a column (or a set of columns) in a table that establishes a relationship between
two tables. It refers to the Primary Key of another table, ensuring referential integrity.
Column1 DataType,
Column2 DataType,
);
Example Tables:
USER_DETAILS Table
Username VARCHAR(50),
Email VARCHAR(100) ,
9
Vanshika Tiwari 23100BTCSAII14332
Password VARCHAR(255),
Registration_Date INT,
Past_Customer BOOLEAN
);
PRODUCT_DETAILS Table
Seller_Id INT,
Title VARCHAR(200),
Category VARCHAR(100),
Listing_Date DATE,
Discounted_Price DECIMAL(10,2),
);
10
Vanshika Tiwari 23100BTCSAII14332
This table stores product listings with pricing and category information.
PURCHASING_TABLE
Buyer_Id INT,
Product_Id INT,
Purchase_Date DATE,
);
11
Vanshika Tiwari 23100BTCSAII14332
This table records product purchases, linking buyers and purchased products.
PAYMENT_DETAILS Table
Purchase_Id INT,
Transaction_Date DATE,
);
12
Vanshika Tiwari 23100BTCSAII14332
DISCOUNT_TABLE
Product_Id INT,
Start_Date DATE,
End_Date DATE,
);
13
Vanshika Tiwari 23100BTCSAII14332
BRAND_OUTLETS Table
Headquarters_Address TEXT,
Contact_Number VARCHAR(20),
Website_Url VARCHAR(255)
);
14
Vanshika Tiwari 23100BTCSAII14332
SELLING_TABLE
Seller_Id INT,
Product_Id INT,
Listing_Date DATE,
);
15
Vanshika Tiwari 23100BTCSAII14332
REVIEW_TABLE
Product_Id INT,
User_Id INT,
Review_Date DATE,
);
16
Vanshika Tiwari 23100BTCSAII14332
4. DESCRIBE Command
The DESCRIBE command is used to view the structure of a table, including column names, data
types, and constraints.
Syntax:
DESCRIBE <table_name>;
Example:
DESCRIBE USER_DETAILS;
17
Vanshika Tiwari 23100BTCSAII14332
Shows the structure of the USER_DETAILS table, including column names, data types, and
constraints.
DESCRIBE PRODUCT_DETAILS;
DESCRIBE PURCHASING_TABLE;
18
Vanshika Tiwari 23100BTCSAII14332
DESCRIBE PAYMENT_DETAILS;
DESCRIBE DISCOUNT_TABLE;
19
Vanshika Tiwari 23100BTCSAII14332
DESCRIBE BRAND_OUTLETS;
DESCRIBE SELLING_TABLE;
20
Vanshika Tiwari 23100BTCSAII14332
Displays the structure of the REVIEW_TABLE, storing user reviews and ratings for products
5. INSERT Command
The INSERT command is used to add new records (rows) into a table. It allows you to specify
values for each column in the table.
Syntax:
Example:
1. Insert into USER_DETAILS Table
VALUES
21
Vanshika Tiwari 23100BTCSAII14332
This command inserts five new users into the USER_DETAILS table with their respective
details.
VALUES
22
Vanshika Tiwari 23100BTCSAII14332
This command inserts five new products into the PRODUCT_DETAILS table with their
respective details.
VALUES
23
Vanshika Tiwari 23100BTCSAII14332
This command inserts five new purchase records into the PURCHASING_TABLE with their
respective details.
VALUES
24
Vanshika Tiwari 23100BTCSAII14332
This command inserts five new payment records into the PAYMENT_DETAILS table with their
respective details.
VALUES
25
Vanshika Tiwari 23100BTCSAII14332
This command inserts five new discount records into the DISCOUNT_TABLE table with their
respective details.
VALUES
26
Vanshika Tiwari 23100BTCSAII14332
This command inserts five new brand outlet records into the BRAND_OUTLETS table with their
respective details.
VALUES
27
Vanshika Tiwari 23100BTCSAII14332
This command inserts five new selling records into the SELLING_TABLE table with their
respective details.
VALUES
28
Vanshika Tiwari 23100BTCSAII14332
This command inserts five new review records into the REVIEW_TABLE table with their
respective details.
6. SELECT Command
The SELECT command is used to retrieve data from a table. Using SELECT *, you can fetch all
columns and records from a specified table.
Syntax:
Example:
A . Retrieve all rows and all columns :
29
Vanshika Tiwari 23100BTCSAII14332
This command retrieves all records and columns from the USER_DETAILS table, displaying
user details such as User_Id, Username, Email, Password, Registration_Date, and
Past_Customer.
This command retrieves all records from the PRODUCT_DETAILS table, showing details like
Product_Id, Seller_Id, Title, Category, P_Rate, Listing_Date, and Discounted_Price.
30
Vanshika Tiwari 23100BTCSAII14332
31
Vanshika Tiwari 23100BTCSAII14332
32
Vanshika Tiwari 23100BTCSAII14332
Description: Retrieves product reviews including Review_Id, Product_Id, User_Id, Rating, and
Review_Date.
33
Vanshika Tiwari 23100BTCSAII14332
Table: USER_DETAILS
Description: Fetches only Username and Registration_Date for all users.
Table: PRODUCT_DETAILS
Description: Fetches only Product_Id and P_Rate for all products.
34
Vanshika Tiwari 23100BTCSAII14332
Table: PURCHASING_TABLE
Description: Fetches all purchase details where Purchase_Date is after 2025-03-15.
35
Vanshika Tiwari 23100BTCSAII14332
Table: DISCOUNT_TABLE
Description: Fetches all columns for discounts where Discount_Percent is greater than
15%.
36
Vanshika Tiwari 23100BTCSAII14332
Table: PAYMENT_DETAILS
Description: Fetches only Payment_method and Transaction_amount where Transaction_amount
is greater than 500.
37
Vanshika Tiwari 23100BTCSAII14332
Table: REVIEW_TABLE
Description: Fetches only Review_Id and Rating where the rating is 4 or higher.
38