Advanced Database (Lab)

You might also like

Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 11

Advanced-Database lab

Eyasu D.
Outline:

• View

• Security management (grant & revoke)

• Trigger

• Attach and detach

• Backup and recovery


Eyasu D.
Eyasu D.
View
• View: it is a virtual table, which is the logical representation of data from one or more table. It is
not the physical part of the database.
• View can be simple or complex view:
• Why view?
• Performance
Syntax:
CREATE VIEW <view name> AS <query>

? create view which display all employee details for those who are department 1.
• CREATE VIEW emp_dpt1 As Select * From Employee WHERE DNO= 1
Eyasu D.
Examples

Create a view for two users as[view1 and view2]


• View1
• Contains all information of those employee who are working for
department 2

• View2
• Contains employee fname, salary and address of those working either in
department 2 or who earn salary greater than 7000

Eyasu D.
exercises
Create the following view based on STUDENT table
Fname Lname SID Dept GPA

• View1
• Contains only information of computer science student
• View2
• Contains student id, dept and GPA
• View3
Eyasu D.
• Contains student id, dept and GPA of computer science student
Data Control Language (DCL)
• Used for controlling the access to database objects for users. Generally
these statements will be used by DBA people to control the access of users
to the database.
• We have 2 DCL statements available in SQL.

1.GRANT

2. REVOKE

Eyasu D.
GRANT
• Grant will be used for giving permissions on the database to users. Using this we can
give any type of permissions to the users on the database.

For example if we want to give Select permission on all the database tables to a user,

GRANT SELECT ANY TABLE TO user_name;

If we want to give select permission on specific table then

GRANT SELECT ON tab_name TO user_name;

Like this we can give any privilege to the users on the database.

Eyasu D.
Grant:

• Create login login_name with password=‘password'

• Create user user_name for login login_name

• Grant connect to user_name

• Grant privilege on table_name to user_name

Eyasu D.
ExampleGrant: Insertion for Abel to employee table

• Create login log1 with password=‘abc'

• Create user Abel for login log1

• Grant connect to Abel

• Grant select on employee to Abel

Eyasu D.
Exercise
User log name Password Privilege given On Table Propagation
name to user
Sara Log11 abc@123 Select Employee No

Kedir Log12 def@456 Select Employee and No


Department

Yared Log13 ghi@789 Insert and Employee and Yes


Department
Delete
Marta Log14 jkl@654 Select and Employee(only No
fname,lname and salary)
insert
Sifan Log15 mno@321 Update Employee (only column Yes
salary)

Eyasu D.

You might also like