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

dbms2 File

The document describes experiments on database management system concepts like integrity constraints, DML commands, built-in functions, joins, grouping and aggregation. The experiments cover applying primary keys, foreign keys, check constraints and other constraints. Basic queries for select, insert, update and delete are also covered along with grouping, having, order by and join operations.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
49 views

dbms2 File

The document describes experiments on database management system concepts like integrity constraints, DML commands, built-in functions, joins, grouping and aggregation. The experiments cover applying primary keys, foreign keys, check constraints and other constraints. Basic queries for select, insert, update and delete are also covered along with grouping, having, order by and join operations.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 17

DATABASE MANAGEMENT SYSTEM LAB

Faculty name: Dr. Vasudha Bahl Name: Anushka Bhat


Roll no: 75214803122
Semester: 4th
Group: I9

Maharaja Agrasen Institute of Technology, PSP Area,


Sector-22, Rohini, New Delhi-110086
DATABASE MANAGEMENT SYATEM LAB
PRACTICAL RECORD
PAPERCODE :
Name :
Roll no. :
Branch :
Group :

PRACTICAL DETAILS
S. Date Experiment name Marks Total Sign
No. Marks

R1 R2 R3 R4 R5
S. Date Experiment name Marks Total Sign
No. Marks

R1 R2 R3 R4 R5
EXPERIMENT-1
AIM:- Introduction to Mariadb
OUTPUT

Anushka

Anushka

Anushka ;

[Anushka]

[Anushka]

[Anushka]

[Anushka]
user@l6it159 ~]$
[user@l6it159 ~]$ su
Password: // password for su is mait_123
[root@l6it159 user]# yum install mariadb mariadb-server
Redirecting to '/usr/bin/dnf install mariadb mariadb-server' (see 'man yum2dnf')

Package mariadb-1:10.0.28-1.fc23.x86_64 is already installed, skipping.


Package mariadb-server-1:10.0.28-1.fc23.x86_64 is already installed, skipping.
Dependencies resolved.
Nothing to do.
Complete!
[root@l6it159 user]# sudo systemctl start mariadb.service
[root@l6it159 user]# sudo systemctl enable mariadb.service
[root@l6it159 user]# mysql
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 3
Server version: 10.0.28-MariaDB MariaDB Server

Copyright (c) 2000, 2016, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]>
Experiment 2

Aim of the Experiment:Apply the integrity constraints like Primary Key, Foreign
key, Check, NOT NULL, etc. to the tables.

Primary Key Constraint:


The primary key constraint ensures that a column or a combination of
columns uniquely identify each row in the table.
Example:
CREATE TABLE users (
id INT PRIMARY KEY,
username VARCHAR(50) NOT NULL,
email VARCHAR(50) UNIQUE NOT NULL,
password VARCHAR(255) NOT NULL
);
In this example, the "id" column is the primary key for the "users" table.
The "username" and "email" columns are also required and must be
unique.
Foreign Key Constraint:
The foreign key constraint ensures that the values in a column or a
combination of columns in one table correspond to the values in another
table.
Example:
CREATE TABLE orders (
id INT PRIMARY KEY,
customer_id INT,
order_dateDATE,
total DECIMAL(10,2),
FOREIGN KEY (customer_id) REFERENCES customers(id)
);
In this example, the "orders" table has a foreign key constraint on the
"customer_id" column that references the "id" column in the "customers"
table. This ensures that the "customer_id" values in the "orders" table
correspond to valid "id" values in the "customers" table.
Check Constraint:
The check constraint ensures that the values in a column meet a specific
condition or set of conditions.
Example:
CREATE TABLE products (
id INT PRIMARY KEY,
name VARCHAR(50) NOT NULL,
price DECIMAL(10,2) NOT NULL CHECK (price > 0),
stock_quantity INT NOT NULL CHECK (stock_quantity >= 0)
);
In this example, the "price" column must be greater than 0, and the
"stock_quantity" column must be greater than or equal to 0.

Not Null Constraint:


The not null constraint ensures that a column cannot have a null value.
Example:
CREATE TABLE customers (
id INT PRIMARY KEY,
name VARCHAR(50) NOT NULL,
email VARCHAR(50) UNIQUE NOT NULL,
phone VARCHAR(20) NOT NULL
)
In this example, the "name", "email", and "phone" columns are all required and
cannot have null values.
These are some examples of how to apply different types of integrity constraints in
MySQL tables. By applying these constraints, we can ensure data accuracy and
consistency in our database.
OUTPUT

anushka anushka

anushka

anushka

anushka

anushka

anushka

anushka

anushka
Experiment 3 :

AIM: Experiments based on basic DML commands – SELECT, INSERT,


UPDATE and DELETE.
SELECT:
The SELECT command is used to retrieve data from one or more tables
in a database. Example:
SELECT * FROM customers;
This command retrieves all columns and all rows from the "customers"
table.
INSERT:
The INSERT command is used to insert new rows into a table.
Example:
INSERT INTO customers (name, email, phone)
VALUES ('John Doe', '[email protected]', '555-1234');
This command inserts a new row into the "customers" table with the name,
email, and phone values.
UPDATE:
TheUPDATEcommandisusedtomodifyexistingdatainatable.
Example:
UPDATEcustomers
SET email = '[email protected]'
WHERE id = 1;
This command updates the email value for the row with id 1 in the
"customers" table.
DELETE:
The DELETE command is used to remove rows from a table.
Example:
This command deletes the row with id 1 from the "customers" table. By
experimenting with these basic DML commands in MySQL, we can perform
various operations on data in our database, such as querying, inserting,
updating, and deleting data. These commands are essential for managing
data in a database and can be used to perform complex operations when
combined with other SQL clauses and functions.
OUTPUT:

anushka

anushka

anushka

anushka

anushka

anushka

anushka

anushka
Experiment 4 :

AIM:Write the queries for implementing Built-in functions, GROUP


BY, HAVING and ORDER BY.

Built-in Functions:
MySQL provides several built-in functions that can be used to manipulate and
transform data. Here's an example of a query that uses some of these functions:
SELECT CONCAT(first_name, ' ', last_name) AS full_name, UPPER(email) AS
email_uppercase
FROM employees;
This query uses the CONCAT and UPPER functions to concatenate the first and
last name columns into a new "full_name" column and convert the email column
to uppercase in the "email_uppercase" column.

GROUP BY:
The GROUP BY clause is used to group rows in a result set based on a
specified column or expression. Here's an example of a query that uses
GROUP BY: SELECT department, COUNT(*) AS num_employees
FROM employees
GROUP BY department;
This query groups employees by department and counts the number of
employees in each department.
HAVING:
The HAVING clause is used to filter rows in a result set based on a specified
condition. Here's an example of a query that uses HAVING:
SELECT department, AVG(salary) AS avg_salary
FROM employees
GROUP BY department
HAVING AVG(salary) > 50000;
This query groups employees by department and calculates the average
salary for each department. The HAVING clause filters the result set to show
only departments with an average salary greater than 50,000.
ORDER BY:
The ORDER BY clause is used to sort the rows in a result set based on one or
more columns. Here's an example of a query that uses ORDER BY:
SELECT first_name, last_name, salary
FROM employees
ORDER BY salary DESC;
This query selects the first name, last name, and salary columns from the
"employees" table and sorts the result set in descending order based on the
salary column.

By using built-in functions, GROUP BY, HAVING, and ORDER BY clauses in


MySQL queries, we can perform more advanced data manipulations and
analysis. These features allow us to transform data, group and aggregate data,
filter data based on conditions, and sort data in various ways to gain insights
from our data.
OUTPUT

anushka

anushka

anushka
Experiment 5:

AIM: Write the queries to implement the joins.

INNER JOIN:
The INNER JOIN keyword returns only the matching rows from both tables.
Here's an example of a query that uses INNER JOIN:
SELECT orders.order_id, customers.customer_name, orders.order_date FROM
orders
INNER JOIN customers ON orders.customer_id = customers.customer_id; This
query selects the customer_name and order_id columns from the "customers" and
"orders" tables and joins the two tables on the customer_id column using LEFT
JOIN. The result set includes all rows from the "customers" table and only the
matching rows from the "orders" table.

RIGHT JOIN:
The RIGHT JOIN keyword returns all rows from the right table and the matching
rows from the left table. If there are no matching rows in the left table, the result
set will contain NULL values. Here's an example of a query that uses RIGHT
JOIN: SELECT orders.order_id, customers.customer_name
FROM orders
RIGHT JOIN customers ON orders.customer_id = customers.customer_id; This
query selects the order_id and customer_name columns from the "orders" and
"customers" tables and joins the two tables on the customer_id column using
RIGHT JOIN. The result set includes all rows from the "orders" table and only the
matching rows from the "customers" table.

FULL OUTER JOIN:


MySQL does not support FULL OUTER JOIN, but we can simulate it using
UNION and LEFT JOIN and RIGHT JOIN. Here's an example of a query that
simulates FULL OUTER JOIN:

SELECT customers.customer_name, orders.order_id


FROM customers
LEFT JOIN orders ON customers.customer_id = orders.customer_id UNION
SELECT customers.customer_name, orders.order_id
FROM customers

RIGHT JOIN orders ON customers.customer_id = orders.customer_id This query


selects the customer_name and order_id columns from the "customers" and
"orders" tables and simulates FULL OUTER JOIN using UNION, LEFT JOIN,
and RIGHT JOIN. The result set includes all rows from both tables.

By using different types of joins in MySQL, we can combine data from multiple
tables based on common columns and perform more complex queries on our data.
This allows us to retrieve and analyze data that is stored across multiple tables in a
database.

OUTPUT

ANUSHKA

ANUSHKA

ANUSHKA

You might also like