Professional Documents
Culture Documents
DBMS Exp 4
DBMS Exp 4
DBMS Exp 4
THEORY:
DML, or Data Manipulation Language, statements are used to manipulate the data present in a
database. The most important DML statements are INSERT, UPDATE & DELETE.
Apart from these commands, there are also other manipulative operators/functions such
as:
INSERT
Syntax:
The INSERT INTO statement can be written in the following two ways:
Syntax:
UPDATE table_name
SET column1 = value1, column2 = value2, ...
WHERE condition;
Syntax:
The SELECT statement is used to select data from a database and the data returned is stored in
a result table, called the result-set.
Syntax:
SELECT column1, column2, ...
FROM table_name;
Apart from the individual SELECT keyword, you can use the SELECT keyword with the
following statements:
• DISTINCT
• ORDER BY
• GROUP BY
• HAVING Clause
Syntax:
SELECT DISTINCT column1, column2, ...
FROM table_name;
Syntax:
SELECT column1, column2, ...
FROM table_name
ORDER BY column1, column2, ...ASC|DESC;
The ‘GROUP BY’ Statement
This statement is used with the aggregate functions to group the result-set by one or more
columns.
SELECT column_name(s)
FROM table_name
WHERE condition
GROUP BY column_name(s)
ORDER BY column_name(s);
The ‘HAVING’ Clause Statement
Since the WHERE keyword cannot be used with aggregate functions, the HAVING clause was
introduced.
Syntax:
SELECT column_name(s)
FROM table_name
WHERE condition
GROUP BY column_name(s)
HAVING condition
ORDER BY column_name(s);
UPDATE Query is used to modify the existing records in a table. You can use the
WHERE clause with the UPDATE query to update the selected rows, otherwise all the
rows would be affected.
The basic syntax of the UPDATE query with a WHERE clause is as follows −
UPDATE table_name
SET column1 = value1, column2 = value2...., columnN = valueN
WHERE [condition];
You can use the WHERE clause with a DELETE query to delete the selected rows,
otherwise all the records would be deleted.
The basic syntax of the DELETE query with the WHERE clause is as follows −
Select<attribute_name,avg(<attribute_name>)as
<new_attribute_name>l From <table_name>
Group by <attribute_name>
2. Having clause: A having clause is like a where clause but only applies only to groups
as a whole whereas the where clause applies to the individual rows. A query can contain
both where clause and a having clause. In that case
a. The where clause is applied first to the individual rows in the tables or table
structures objects in the diagram pane. Only the rows that meet the conditions in the
where clause are grouped.
b. The having clause is then applied to the rows in the result set that are produced
by grouping. Only the groups that meet the having conditions appear in the query
output.
Example:
Example: The following SQL statement returns TRUE and lists the productnames if it
finds ANY records in the OrderDetails table that quantity = 10:
SELECT ProductName
FROM Products
WHERE ProductID
= ANY (SELECT ProductID FROM OrderDetails WHERE Quantity = 10);