Professional Documents
Culture Documents
Dbms 1210 Project
Dbms 1210 Project
BACHELORS IN TECHNOLOGY
FROM
SHADAN COLLEGE OF ENGINEERING &
TECHNOLOGY
TOPIC
Q1. Explain with DDL, and DML
Commands
(i) Aggregate Functions
(ii) Integrity Constraints
DDL COMMANDS:
Definition
Database: Creates a new database.
Table: Creates a new table with specified columns
and constraints.
Index: Creates an index on specified columns of a
table
.
EXAMPLE QUERY
4|Page
2. ALTER:
Definition
Table: Modifies the structure of an existing table by
adding, modifying, or dropping columns and
constraints.
EXAMPLE QUERY
5|Page
3. DROP:
Definition
Database: Deletes a database and all its objects.
Table: Deletes a table and all its data.
Index: Deletes an index.
EXAMPLE QUERY
4. TRUNCATE:
Definition
6|Page
EXAMPLE QUERY
5. RENAME:
Definition
Table: Renames a table.
Column: Renames a column in a table.
EXAMPLE QUERY
DML COMMANDS:
Data Manipulation Language (DML) commands
are used to manage and manipulate the data stored
7|Page
1. INSERT:
Definition
Table: Adds new rows of data to a specified
table.
EXAMPLE QUERY
2. SELECT:
8|Page
Definition
Table: Retrieves data from specified columns
and rows in one or more tables.
EXAMPLE QUERY
3. UPDATE:
Definition
Table: Modifies the values of existing rows in
a specified table.
9|Page
EXAMPLE QUERY
4. DELETE:
Definition
Table: Removes specified rows from a table.
EXAMPLE QUERY
Definition
Procedure: Executes a specified stored
procedure.
10 | P a g e
EXAMPLE QUERY
6. LOCK TABLE:
Definition
Table: Locks a specified table or tables to
control access.
EXAMPLE QUERY
LOCK TABLE employees IN EXCLUSIVE
MODE;
1. COUNT ():
The COUNT () function returns the number of rows
that match a specified criterion. It is often used to
determine the number of rows in a table or the
number of non-NULL values in a column.
Definition
COUNT (expression): Returns the number of
non-NULL values in the specified column.
COUNT (*): Returns the total number of rows
in the table, including rows with NULL values.
2. SUM ():
The SUM () function calculates the total sum of a
numeric column. It adds up all the values in the
specified column.
Definition
SUM (expression): Returns the sum of all
non-NULL values in the specified column.
3. AVG ():
12 | P a g e
Definition
AVG (expression): Returns the average of all
non-NULL values in the specified column.
4. MAX ():
The MAX () function returns the maximum value
in a set of values. It finds the highest value in the
specified column.
Definition
MAX (expression): Returns the maximum
value of all non-NULL values in the
specified column.
5. MIN ():
The MIN () function returns the minimum
value in a set of values. It finds the lowest
value in the specified column.
13 | P a g e
Definition
MIN (expression): Returns the minimum
value of all non-NULL values in the
specified column.
-- Create a database
CREATE DATABASE company;
2. SUM ():
The SUM () function returns the total sum of a numeric
column.
3. AVG ():
The AVG () function returns the average value of a
numeric column.
16 | P a g e
4. MAX ():
The MAX () function returns the maximum value in a
column.
5. MIN ():
The MIN () function returns the minimum value in a
column.
1. COUNT ()
The COUNT () function returns the number of rows that
match a specified criterion.
-- Count the number of sales (DML command)
SELECT COUNT (*) AS total_sales FROM
employee_sales;
2. SUM ():
The SUM () function calculates the total sum of a
numeric column.
19 | P a g e
3. AVG ():
The AVG () function computes the average of a numeric
column.
4. MAX ():
The MAX () function returns the maximum value in a
set of values.
5. MIN ():
The MIN () function returns the minimum value in a set
of values.
20 | P a g e
3. Unique Constraint:
4. Check Constraint:
23 | P a g e
In this example:
emp_id is defined as the primary key,
ensuring each emp_id value is unique.
emp_email has a UNIQUE constraint,
ensuring each email address is unique across
all rows.
25 | P a g e
In this case:
customer_name cannot contain NULL values,
ensuring every customer has a name.
In this example:
Each emp_id value must be unique due to the
primary key constraint.
Here:
The third INSERT statement will fail because
emp_id = 3 does not exist in the employee’s table.
In this scenario: