You are on page 1of 6

Assignment-4 [DBMS]

Q-2.Explain the difference between Discretionary access control and


mandatory access Control
Q-3.Describe GRANT and REVOKE commands. State the differences
between COMMIT and ROLLBACK commands
Q-4.Explain DDL,DML,DCL with example. Discuss aggregate functions with
example(s).
DDL (Data Definition Language)
(1)Create:- CREATE statement is used to create a new database, table, index or stored
procedure.
Example:-
CREATE TABLE user (
id INT(16) PRIMARY KEY AUTO_INCREMENT,
name VARCHAR(255) NOT NULL
);
(2)Drop:- DROP statement allows you to remove database, table, index or stored procedure.
Example:-
DROP TABLE user;

(3)Alter:- ALTER is used to modify existing database data structures (database, table).
Example:-
ALTER TABLE user ADD COLUMN lastname VARCHAR(255) NOT NULL;

(4)Rename:- RENAME command is used to rename SQL table.


Example:-
RENAME TABLE user TO student;

(5) Truncate:- TRUNCATE operation is used to delete all table records.


Example:-
TRUNCATE student;

DML (Data Manipulation Language)


(1)Select:- SELECT query is used to retrieve a data from SQL tables.
Example:-
SELECT * FROM student;

(2)Insert:- INSERT command is used to add new rows into the database table.
Example:-
INSERT INTO student (name, lastname) VALUES ('Dmytro',
'Shvechikov');

(3)Update:- UPDATE statement modifies records into the table.


Example:-
UPDATE student SET name = 'Dima' WHERE lastname = 'Shvechikov';
(4)Delete:- DELETE query removes entries from the table.
Example:-
DELETE FROM student WHERE name = 'Dima';

DCL (Data Control Language)


(1)Grant:- GRANT command gives permissions to SQL user account.
Example:-
CREATE USER 'dmytro'@'localhost' IDENTIFIED BY '123';

(2)Revoke:- REVOKE statement is used to remove privileges from user accounts.


Example:-
REVOKE ALL PRIVILEGES ON explainjava.* FROM
'dmytro'@'localhost';

Aggregate functions:- Aggregate functions in DBMS take multiple rows from the table
and return a value according to the query.

(1)AVG Function

This function returns the average value of the numeric column that is
supplied as a parameter.

Example: Write a query to select average salary from employee table.


Select AVG(salary) from Employee

(2)COUNT Function

The count function returns the number of rows in the result. It does not
count the null values.

Example: Write a query to return number of rows where salary > 20000.
Select COUNT(*) from Employee where Salary > 20000;

(3)MAX Function

The MAX function is used to find maximum value in the column that is
supplied as a parameter. It can be used on any type of data.

Example − Write a query to find the maximum salary in employee table.


Select MAX(salary) from Employee
(4)SUM Function

This function sums up the values in the column supplied as a parameter.

Example: Write a query to get the total salary of employees.


Select SUM(salary) from Employee

(5)STDDEV Function

The STDDEV function is used to find standard deviation of the column


specified as argument.

Example − Write a query to find standard deviation of salary in Employee


table.
Select STDDEV(salary) from Employee
(6)VARIANCE Function

The VARIANCE Function is used to find variance of the column specified


as argument.

Example −
Select VARIANCE(salary) from Employee

Q-5.What is a view? What are its types? Write the syntax for creating a view
A database view is a subset of a database and is based on a query that runs on
one or more database tables. Database views are saved in the database as
named queries and can be used to save frequently used, complex queries.
There are two types of database views:
Dynamic views :- Dynamic views can contain data from one or two tables and
automatically include all of the columns from the specified table or tables.
Dynamic views are automatically updated when related objects or extended
objects are created or changed.
Static views :- Static views can contain data from multiple tables and the
required columns from these tables must be specified in the SELECT and
WHERE clauses of the static view. Static views must be manually updated
when related objects or extended objects are created or changed.
Syntax:-
CREATE VIEW view_name AS
SELECT column1, column2, ...
FROM table_name
WHERE condition;

Q-6. Define PL/SQL. Write PL/SQL block to print sum of even numbers
Define:- PL/SQL is a block of codes that used to write the entire program blocks/ procedure/
function, etc.
Write PL/SQL block to print sum of even numbers
declare
NUM number:=0;
Sum number:=0;
begin
loop
NUM1 := NUM+2;
Sum:=Sum+Num1;
exit when NUM1=100;
end loop;
dbms_output.put_line (sum);
end;

You might also like