0% found this document useful (0 votes)
12 views34 pages

DBMSmyfileee

Notes

Uploaded by

Girraj Jha
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)
12 views34 pages

DBMSmyfileee

Notes

Uploaded by

Girraj Jha
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/ 34

Practical file

Database Management System


CS 502

Submitted by: Submitted to:

Roll no.:
Department of Computer Science & Engineering
Continuous Assessment Sheet(CAS)

Academic Year:2022-26 Course Name: DBMS (CS-502)


Name of Student: Class & Batch:

Roll No.:

Date Title of Experiment Concept Progr Oral Total Date Sign


Exp. Un am an d (30) of ature
derstanding Ex Repo rt Su of St
No. (10) ecutio Writi
bmis aff
n ng(10)
and sion
(10)
1. Learn and apply the concept of Data
Definition Language (DDL)
commands in RDBMS, Data
Manipulation Language (DML) and
Data Control Language (DCL).
2. Show the implementation of Select,
Like, Order by, Group by, Having
clause, in, between on your database.
3. Create primary key, candidate key,
foreign key, not null, unique, and
default constraints
4. Use different SQL functions like max,
min, count, avg, sum, last, upper etc.
on your database.
5. Perform Join operations like INNER
JOIN, LEFT JOIN, RIGHT JOIN,
CROSS JOIN and NATURAL JOIN.
6. Create an index and perform
operations on it for the chosen
database.
7. Apply the concept of transition control
language to use commite ,rollback,set
transitionon the choosen database and
understanding account management.
8. Create a view and perform different
operations on it for the chosen
database.
9. Show the use control flow functions in
SQL.
Exp. Date TitleofExperiment ConceptU ProgramE Oral Total Date Signat
nderstandi xecutiona andRep (30) ofSub ure
No. ng(10) nd(10) ortWriti missio ofStaf
ng(10) n
f
10. Perform Different SET operations like
UNION,INTERSECT,MINUS and
UNION ALL.
11. Creating Procedures, Functions,
Triggers ,Prepare Statement and
Compound Statement, Cursors in
MYSQL. .
12. RGPV Queries

Total Marks

Marks (outof100)

Signature Sign

Head of Department Course Teacher Student Signat


Experiment 1

DDL COMMANDS -Data Definition Language (DDL) commands are used to create,
manipulate, and modify objects in Snowflake, such as users, virtual warehouses,
databases, schemas, tables, views, columns, functions, and stored procedures.

DML COMMANDS- A data manipulation language (DML) is a computer programming


language used for adding (inserting), deleting, and modifying (updating) data in a
database. A DML is often a sublanguage of a broader database language such as SQL,
with the DML comprising some of the operators in the language.

Create database:

Use database:

Create table:
1: Customers
2: Products

3: Payments

4: Orders

5: Order Details
Show tables:
1. Customers

2.Products

2.
3.Payments

4.Orders
5. Order Details

Inserting Records:
1.Insert Records into Customers

2.Insert Records into Product

3.Insert Records into Payment


4.Insert Records into Order

5.Insert Records into OrderDetails

Showing all data from the Tables:


1.Show all data from the Customers Table

2.Show all the data from Products Table


3.Show all data from the Payments table

4.Show all data from the Orders table

5.Show all data from the OrderDetails table


Experiment 2

SELECT Statement:
The SELECT statement is used to retrieve specific data from one or more tables in a database.

LIKE Operator:
The LIKE operator is used in a WHERE clause to search for a specified pattern in a column.
• Wildcards:
o %: Matches zero or more characters.
o _: Matches exactly one character.

ASCENDING (ASC):
Used to sort query results in ascending order (smallest to largest or A to Z). This is the default
order in SQL.

DESCENDING (DESC):
Used to sort query results in descending order (largest to smallest or Z to A).

Select:
Like:

Order By:
ASC:

DESC:
Experiment 3
PRIMARY KEY- A primary key, also called a primary keyword, is a key in a relational
database that is unique for each record.

FOREIGN KEY- FOREIGN KEY is a key used to link two tables together. A FOREIGN KEY
is a field (or collection of fields) in one table that refers to the PRIMARY KEY in another table.

CANDIDATE KEY- CANDIDATE KEY is a set of attributes that uniquely identify tuples in a
table. Candidate Key is a super key with no repeated attributes.

NOT NULL: Ensures that a column cannot have NULL values, meaning every record must
contain a valid (non-NULL) value in this field.

UNIQUE KEY: Ensures all values in a column or group of columns are distinct across the
table, allowing only one NULL value (if permitted).

DEFAULT CONSTRAINTS- The DEFAULT constraint is used to provide a default value for
a column. The default value will be added to all new records IF no other value is specified

Primary key:

Foreign Key:
Candidate Key:

Unique Key:

Not null key:

Default constraint:
Experiment 4
COUNT FUNCTION - The COUNT function returns the total number of values in the
specified field. It works on both numeric and non-numeric data types.

MIN FUNCTION - The COUNT function returns the total number of values in the specified
field. It works on both numeric and non-numeric data types.

MAX FUNCTION - The MAX function is the opposite of the MIN function. It returns the
largest value from the specified table field.

SUM FUNCTION - MySQL SUM function which returns the sum of all the values in the
specified column. SUM works on numeric fields only. Null values are excluded from the result
returned.

AVG FUNCTION - AVG function returns the average of the values in a specified column. Just
like the SUM function, it works only on numeric data types.

UPPER FUNCTION - The UPPER() function to convert any lowercase characters to


uppercase.

LOWER FUNCTION - MySQL last function is used to return the last value of the selected
column.

Find the maximum OrderDate (Latest order):

Find the minimum OrderDate (oldest order):


Count the total number of Customers:

Find the average CustomerID value from the Customers Table:

Calculate the total number of Orders through course ID:

Get the last Customer (based on CustomerID)

Convert all FirstName values to uppercase


Experiment 5
JOIN FUNCTION - MySQL last function is used to return the last value of the selected
column.

INNER JOIN- The INNER JOIN selects all rows from both participating tables as long as
there is a match between the columns.

LEFT JOIN - he LEFT JOIN allows you to query data from two or more tables. Similar to
the INNER JOIN clause, the LEFT JOIN is an optional clause of the SELECT statement,
which appears immediately after the FROM clause. Suppose that you want to join two
tables t1 and t2.

RIGHT JOIN - The Right Join is used to joins two or more tables and returns all rows from
the right-hand table, and only those results from the other table that fulfilled the join
condition. If it finds unmatched records from the left side table, it returns Null value.

CROSS JOIN- MySQL CROSS JOIN is used to combine all possibilities of the two or
more tables and returns the result that contains every row from all contributing tables. The
CROSS JOIN is also known as CARTESIAN JOIN, which provides the Cartesian product
of all associated tables.

NATURAL JOIN - A NATURAL JOIN is a JOIN operation that creates an implicit join
clause for you based on the common columns in the two tables being joined. Common
columns are columns that have the same name in both tables. A NATURAL JOIN can be an
INNER join, a LEFT OUTER join, or a RIGHT OUTER join. The default is INNER join

INNER JOIN
Query: Retrieve Customer details along with their Orders status and payment details
LEFT JOIN
Query: Retrieve all Customers with product names, including those who have not ordered
any product

RIGHT JOIN
Query: Retrieve all Customer ID, Order ID and Product ID

SELF JOIN
Query: Find Customer with the same City.
FULL OUTER JOIN Query: Combine all Customer and Orders, even if no matching
record exists

CROSS JOIN Query: Get all possible pairs of Customer, order and order status
Experiment 6
Single-Column Index:
A database index created on a single column to improve query performance by allowing faster
retrieval of rows based on that column's values.
Composite Index:
An index created on two or more columns to speed up queries that filter or sort data based on a
combination of these columns.
Unique Index:
Ensures that all values in the indexed column(s) are distinct, preventing duplicate entries while
enhancing query performance.
View Indexes:
Indexes created on materialized views to improve performance by precomputing and storing
query results for faster access.
Drop Index Query:
Used to delete an existing index from a table to reduce maintenance overhead or if the index is
no longer required.

Single-Column Index: Create an index on the FirstName column in the Customer table to
speed up searches by name.

Composite Index: Create a composite index on the FirstName and LastName columns in
the Customer table..

Unique Index: Create a unique index on the Email column in the Customers table to ensure
no two customer can have the same email.
View Indexes

Drop Index Query: Drop an index (e.g., idx_firstname) if it’s no longer needed.

Add Index to Other Tables: Add an index on the CustomersName column in the
Customers table
Experiment 7
1. Create User Accounts
This operation is used to create new user accounts in the database system. Each user account is
assigned a unique username and password, allowing individual access and management of
database resources based on specific privileges.

2. Grant Limited Privileges to student_user


This operation allows the administrator to assign specific permissions to a user, such as the
ability to perform SELECT, INSERT, or UPDATE operations on particular tables, ensuring
controlled access to the database.

3. Grant All Privileges to admin_user


This operation provides complete control over the database to a user. The user can perform any
operation, such as creating or deleting tables, modifying data, and managing other users'
permissions.

4. View Privileges
This operation allows the user to check what permissions are assigned to a specific user. It is
useful for verifying and auditing user roles and access control.

5. Revoke Privilege
This operation removes specific permissions that were previously granted to a user. It is used to
limit or withdraw access to database resources when necessary.

Create User Accounts:

Grant Limited Privileges to Customer_user:

Grant All Privileges to admin_user:


View Privileges:

Revoke Privileges:
Experiment 8
1. Create Views:
Views are virtual tables created from a query, representing specific data from one or
more tables without storing the data physically.
o sView for Customer Order Details: A virtual table showing selected customer
order information, such as customer name, order ID, and order date.
o View for Product Sales Count: Displays the total number of units sold for each
product by aggregating sales data.
2. Query Views:
Views can be queried like regular tables to fetch data as per the defined structure.
o Query the CustomerOrderDetails View: Retrieve specific customer order
information by selecting columns from the CustomerOrderDetails view.
o Query the ProductSalesCount View: Fetch the total sales count for each
product by querying the ProductSalesCount view.
3. Modify a View:
Views can be updated to include additional columns or alter existing query logic.
o Update the CustomerOrderDetails View to Include Customer Emails: Add
an email column to the CustomerOrderDetails view definition for enhanced
customer records.
4. Drop a View:
The DROP VIEW statement removes a view from the database without affecting the
underlying data.
o Drop the ProductSalesCount View: Deletes the ProductSalesCount view to
remove its access point.

Create Views
1. View for Customer Orders
2. View for ProductDetails Count

Query Views
1. Query the CustomerOrdersCount view

2.Query the ProductDetails view

Modify a View
Update the CustomerOrders view to include email addresses
Drop a View
Drop the CustomerOrders count view
Experiment 9
Control flow functions in SQL
1.IF
The IF function evaluates a condition and returns a value based on whether the condition is
true or false.
2.CASE
The CASE function performs conditional logic, returning a value based on specified
conditions. It works like an IF-ELSE statement in programming.
3.IFNULL
The IFNULL function checks whether a value is NULL and returns a specified replacement
value if it is, otherwise, it returns the original value.
4.NULLIF
The NULLIF function compares two values and returns NULL if they are equal; otherwise,
it returns the first value.

Using the IF() Function :-


Determine if a Order Total Amount is low(<1000) or medium/high(>5000)

Using the CASE Statement :-


Categorize Order on the basis of TransactionStatus
Using the IFNULL() Function :-
Replace NULL PaymentDate with a default value

Using NULLIF() :-
Mark Customers who have the same first and last name

Count TotalProducts:-
Experiment 10
Union: Combines the results of two SELECT statements, removing duplicates. The first
query merges data from Products with data where Stock > 50.

Intersection: Retrieves rows common to two SELECT queries using an INNER JOIN, as
shown where Stock >= 50 in both cases.

Difference: Returns rows in one SELECT query but not in another, demonstrated by
filtering products where Name is not in the list of Stock > 50.

UNION ALL:
• Combines the results of two SELECT queries without removing duplicates.
• Unlike UNION, UNION ALL keeps all rows, including repeated values.
Experiment 11
1. • Stored Procedure:
A stored procedure is a precompiled set of SQL statements stored in the database
that can be executed as a single unit to perform a specific task.
2. • Compound Functions:
Compound functions combine multiple SQL functions to perform complex
operations, such as aggregations, on data in a single query.
3. • Trigger:
A trigger is a special procedure in a database that automatically executes in
response to specific events (e.g., INSERT, UPDATE, or DELETE) on a table.
1. Stored Procedures
Add a New Student
Query to Create Procedure

Call Procedure

Verify the Data

2. Compound Functions
Calculate Age Based on DOB
Query to Create Function
Use the Function

3. Triggers
Log Changes in Enrollment Table
Create the Log Table

Query to Create Trigger

Test the Trigger


Experiment 12
RGPV Queries

Delete Duplicate Rows

Display Alternate Rows

Update Multiple Rows in a Single Update Statement

Display the order with OrderDate<=15


Display customer name start with J,K,L OR M
Rollback, Commit, and Savepoint
Start a Transaction

Insert a Record into Student

Rollback to the Savepoint


Commit the Transaction

You might also like