DBMS lab Manual exp 9, 10 & 11
DBMS lab Manual exp 9, 10 & 11
Experiment -9
VIEW : Views are small part of sql . In SQL views are kind of virtual tables. A view also
has rows and columns as they are in a real table in the database. We can create a view by
selecting fields from one or more tables present in the database.
syntax : CREATE WEW view name AS SELECT column1, column2, ... FROM table name
WHERE condition;
Example :
CREATE VIEW stu View AS SELECT NAME, ADDRESS FROM college WHERE
S_ID < 5;
T * FROM stu_view;
Output :
name address
ani goa
nia chennai
DR SANGEETA SONI 42
Global Institute of Technology
DEPARTMENT OF COMPUTER SCIENCE ENGINEERING
To see result :
T * From stu_view;
Output :
DELETING VIEWS:
Example :
UPDATING VIEWS :
• Insertion :
syntax :
INSERT INTO view name(column1, column2 , column3,..)
VALUES(value1, value2, value3..);
VIVA Questions:-
1. What is a View in SQL Server?
A view can be considered as a virtual table. As a view represents a virtual table it does not
physically store any data by default.
DR SANGEETA SONI 43
Global Institute of Technology
DEPARTMENT OF COMPUTER SCIENCE ENGINEERING
When we create a view on more than 1 table then it is known as the complex
view.
On a complex view, we cannot perform DML operations so that a complex
view is also called a non-updatable or static view.
DR SANGEETA SONI 44
Global Institute of Technology
DEPARTMENT OF COMPUTER SCIENCE ENGINEERING
Experiment-10
Aim- Perform the queries for triggers.
TRIGGERS : A SQL trigger is a database object just like a stored procedure, or we can say
it is a special kind of stored procedure which fires when an event occurs in a database. We
can execute a SQL query that will "do something" in a database when an event is fired.
Types of Triggers
1. DDL Trigger
2. DML Trigger
RIGGERS PROCEDURES
RETURNS trigger AS
DR SANGEETA SONI 45
Global Institute of Technology
DEPARTMENT OF COMPUTER SCIENCE ENGINEERING
ON table_name
Example :
id SERIAL PRIMARY
KEY,
T * FROM employees;
Output :
_name ast_name
1 Doe
John
DR SANGEETA SONI 46
Global Institute of Technology
DEPARTMENT OF COMPUTER SCIENCE ENGINEERING
2 Lily Blush
UPDATE QUERY :
UPDATE employees
WHERE ID = 2;
T * FROM employees;
Output :
_name ast_name
1 John Doe
2 Lily Brown
Viva Questions:-
1. Advantages of Triggers :
DR SANGEETA SONI 47
Global Institute of Technology
DEPARTMENT OF COMPUTER SCIENCE ENGINEERING
These DML Triggers execute when the user tries to modify or change data through data
manipulation language events such as INSERT, UPDATE and DELETE statements on the table
or view.
The DDL triggers fires in response to a variety of data definition language events such as Create,
Alter, Drop, Grant, Denay and Revoke.
A trigger can also contain INSERT, UPDATE and DELETE logic within itself. A trigger that
contains data modification logic within itself which causes another trigger to be fired is called the
nested trigger.
DR SANGEETA SONI 48
Global Institute of Technology
DEPARTMENT OF COMPUTER SCIENCE ENGINEERING
Experiment-11
Aim- Write the query for creating the users and their roles.
• ALL PRIVILEGES - as we saw previously, this would allow a MySQL user full
access to a designated database (or if no database is selected, global access across the
system)
• SELECT - allows them to use the SELECT command to read through databases
DR SANGEETA SONI 49
Global Institute of Technology
DEPARTMENT OF COMPUTER SCIENCE ENGINEERING
To provide a specific user with a permission, you can use this framework:
If you need to revoke a permission, the structure is almost identical to granting it:
mysql > REVOKE type of _permission ON database_ name.table name FROM
’username @’localhost’;
You can review a user's current permissions by running the following:
Just as you can delete databases with DROP, you can use DROP to delete a user
altogether:
mysql>quit
DR SANGEETA SONI 50