0% found this document useful (0 votes)
7 views4 pages

Chap 13

The document discusses database views, which allow users to access data from multiple tables as if it were a single table, simplifying data retrieval. It also covers user access management through GRANT and REVOKE commands, enabling database administrators to control permissions for users and groups. Additionally, it mentions triggers and stored procedures, providing links for further learning on these topics.

Uploaded by

[smo] Monkeyy-3
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views4 pages

Chap 13

The document discusses database views, which allow users to access data from multiple tables as if it were a single table, simplifying data retrieval. It also covers user access management through GRANT and REVOKE commands, enabling database administrators to control permissions for users and groups. Additionally, it mentions triggers and stored procedures, providing links for further learning on these topics.

Uploaded by

[smo] Monkeyy-3
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

Chap13 – Misc.

 Views
A View is a window into the database, or a view into the database. It can seem
like it is a table, but it is not, it is a view that pulls data from the real tables.

Views are created so users can use the view instead of a table to pull data from.

The best Example I can think of from our Registration database is: wouldn’t it be
nice if we had a Sections table with the instructor’s name and the CourseName
in the Sections table. Well we can do that with a View. We can create a
SectionsView that contains these columns. Then when the user uses this view, it
seems like the columns are already there.

The data for a view remains in the actual tables, but from the users stand point,
it seems like the data is in the View.

So here is how you create a view:

CREATE VIEW SectionsView as


SELECT s1.crn, s1.CourseID, c1.CourseName, s1.timedays,
s1.roomNo, i1.firstName, i1.lastName
FROM Sections s1, Courses c1, Instructors i1
WHERE s1.CourseId = c1.CourseID
And s1.instructor = i1.id;

This view will be created with the 7 columns(CRN, CourseID, CourseName,


TimeDays, RoomNo, Inst Firstname, Inst LastName.

So a user can now query this View by:

SELECT *
FROM SectionsView
WHERE crn = 30115;
The User does not have to do the Join. It was already done when we created the
View.

One limitation of a view is that they are only used for Select. You cannot Insert,
Update or Delete from a view. You need to do these 3 functions with the actual
tables.

To get rid of a View you use Drop.

DROP VIEW SectionsView;

 Transactions

 Security
o Users and Groups

Almost all databases have Users and Groups. Users need to login to the
database to get access to the entities that they have access to. A database
Administrator usually gives out the access. They are the ones that usually
execute the following command. Programmers do not usually execute these
commands, programmers act as users at this point.

The 2 commands for giving and taking away database access are GRANT and
REVOKE.

o Grant

GRANT Examples:

A DB Administrator may give everyone access to a table by:


GRANT all
ON Students
TO public;

All means (Select, Insert, Update and Delete).


On Students means on the Students Table
To Public means to everyone, all users and groups.
A DB Administrator may give everyone access to a table by:
GRANT Select
ON Schedule
TO jsmith;

Select means (Select).


On Schedule means on the Schedules Table
To jsmith means to just the one user jsmith.

o Revoke

REVOKE Examples:

A DB Administrator may revoke everyone’s access to a table by:


REVOKE all
ON Students
FROM public;

All means (Select, Insert, Update and Delete).


On Students means on the Students Table
FROM Public means from everyone, all users and groups.

A DB Administrator may give everyone access to a table by:


REVOKE Select
ON Schedule
FROM jsmith;

Select means (Select).


On Schedule means on the Schedules Table
FROM jsmith means just revoke access for the one user jsmith.

 Triggers

Follow the links below to learn more about Triggers:

https://docs.oracle.com/cd/A57673_01/DOC/server/doc/SCN73/ch15.htm

https://www.essentialsql.com/what-is-a-database-trigger/
 Stored Procedures

Follow the link below to learn more about Stored Procedures:

https://www.w3schools.com/sql/sql_stored_procedures.asp

 Summary

 Other Resources

Click on the link below to get more help with “SQL Views”.

https://www.w3schools.com/sql/sql_view.asp

http://beginner-sql-tutorial.com/sql-views.htm

Click on the link below to get more help with “GRANT & REVOKE”.

http://beginner-sql-tutorial.com/sql-grant-revoke-privileges-roles.htm

You might also like