0% found this document useful (0 votes)
123 views9 pages

DBMS Practical 6

The document describes performing SQL queries on a university database. It provides examples of 15 SQL queries including SELECT statements to retrieve data from tables, JOINs to combine data from multiple tables, aggregate functions like COUNT and AVG, UPDATE and INSERT statements to modify data, and ALTER statements to modify a table structure. The queries are executed on tables like department, instructor, student, course and time_slot in the university database.

Uploaded by

Tech Gyan
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)
123 views9 pages

DBMS Practical 6

The document describes performing SQL queries on a university database. It provides examples of 15 SQL queries including SELECT statements to retrieve data from tables, JOINs to combine data from multiple tables, aggregate functions like COUNT and AVG, UPDATE and INSERT statements to modify data, and ALTER statements to modify a table structure. The queries are executed on tables like department, instructor, student, course and time_slot in the university database.

Uploaded by

Tech Gyan
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/ 9

PRACTICAL 6

D.O.P: D.O.S:

AIM: TO PERFORM SQL QUERIES ON UNIVERSITY DATABASE


THEORY:
SQL, or Structured Query Language, is a standard language used to communicate with relational
databases and manage data. There are many SQL commands, or statements, that can be used to
perform various tasks such as querying, inserting, updating, and deleting data. Some of the most
commonly used SQL commands include:

SELECT: used to query data from one or more tables.


SYNTAX: SELECT column1, column2, ...
FROM table_name;
INSERT: used to insert new data into a table.
SYNTAX:
INSERT INTO table_name (column1, column2, column3, ...)
VALUES (value1, value2, value3, ...);
UPDATE: used to update existing data in a table.
SYNTAX:
UPDATE table_name
SET column1 = value1, column2 = value2, ...
WHERE condition;
DELETE: used to delete data from a table.
SYNTAX:
DELETE FROM table_name WHERE condition;
CREATE: used to create new tables, views, indexes, and other database objects.
SYNTAX:
CREATE TABLE table_name (
column1 data_type,
column2 data_type,
column3 data_type,
....
);
ALTER: used to modify the structure of an existing table or other database object.
SYNTAX:
ALTER TABLE table_name
ADD column_name data_type;
DROP: used to delete tables, views, indexes, and other database objects.
SYNTAX:
DROP TABLE table_name;
TRUNCATE: used to delete all data from a table while preserving its structure.
SYNTAX:
TRUNCATE TABLE table_name;
GRANT: used to grant privileges to users or roles.
SYNTAX:

CO22333 Page 1
PRACTICAL 6
D.O.P: D.O.S:

GRANT privilege_name
ON object_name
TO {user_name | PUBLIC | role_name}
[WITH GRANT OPTION];
REVOKE: used to revoke privileges from users or roles.
SYNTAX:
REVOKE privilege_name
ON object_name
FROM {user_name | PUBLIC | role_name}
WHERE: clause is used to filter records.
It is used to extract only those records that fulfill a specified condition.
Syntax:
SELECT column1, column2, ...
FROM table_name
WHERE condition;
ORDER BY :keyword is used to sort the result-set in ascending or descending order.
The ORDER BY keyword sorts the records in ascending order by default. To sort the records in
descending order, use the DESC keyword.
Syntax:
SELECT column1, column2, ...
FROM table_name
ORDER BY column1, column2, ... ASC|DESC;

PROCEDURE:

1. SELECT * FROM `department` ORDER BY `department`.`dept_name` ASC

2. SELECT dept_name, SUM(budget) as total_budget FROM department GROUP BY dept_name;

CO22333 Page 2
PRACTICAL 6
D.O.P: D.O.S:

3. SELECT I.name, I.dept_name, D.building, D.budget


FROM instructor I
JOIN department D ON I.dept_name = D.dept_name;

4. SELECT I.name, I.dept_name, D.building, D.budget FROM instructor I INNER JOIN department
D ON I.dept_name = D.dept_name;

CO22333 Page 3
PRACTICAL 6
D.O.P: D.O.S:

5. SELECT I.name, I.dept_name, D.building, D.budget


FROM instructor I
LEFT JOIN department D ON I.dept_name = D.dept_name;

6. SELECT I.name, I.dept_name, D.building, D.budget


FROM instructor I
RIGHT JOIN department D
ON I.dept_name = D.dept_name;

CO22333 Page 4
PRACTICAL 6
D.O.P: D.O.S:

7. SELECT COUNT(*) FROM teaches;

8. SELECT AVG(salary) FROM instructor;

CO22333 Page 5
PRACTICAL 6
D.O.P: D.O.S:

9. SELECT MIN(salary) FROM instructor;

10. SELECT MAX(salary) FROM instructor;

CO22333 Page 6
PRACTICAL 6
D.O.P: D.O.S:

11. UPDATE `takes` SET `grade` = 'A+' WHERE `takes`.`ID` = '00128' AND `takes`.`course_id` =
'CS-347' AND `takes`.`sec_id` = '1' AND `takes`.`semester` = 'Fall' AND CONCAT(`takes`.`year`) =
2009;

12. INSERT INTO `student` (`ID`, `name`, `dept_name`, `tot_cred`) VALUES ('0122', 'RAM', 'CSE',
'100');

CO22333 Page 7
PRACTICAL 6
D.O.P: D.O.S:

13. SELECT * FROM `course` ORDER BY `course`.`course_id` ASC

14. DELETE FROM `takes`


WHERE `takes`.`ID` = '98988' AND `takes`.`course_id` = 'BIO-301' AND `takes`.`sec_id` = '1'
AND `takes`.`semester` = 'Summer' AND CONCAT(`takes`.`year`) = 2010;

CO22333 Page 8
PRACTICAL 6
D.O.P: D.O.S:

15. ALTER TABLE `time_slot` DROP PRIMARY KEY, ADD PRIMARY KEY(`time_slot_id`);

RESULT:
All the queries have been executed on banking database.

CO22333 Page 9

You might also like