Database Security
View
View Retrieval/ Update
select * from a_view;
Example: create or replace view a_view1 as select sid from a_student where sid>=102;
example
CREATE VIEW salvu50 (ID_NUMBER, NAME, ANN_SALARY)
AS
SELECT employee_id, last_name, salary*12
FROM employee WHERE department_id = 50;
Drop View
Example: drop view a_view1;
Question: Can you update the data in an Oracle VIEW?
Answer: A VIEW in Oracle is created by joining one or more tables. When you update record(s) in a VIEW, it updates the records in the underlying tables that make up the view. So, yes, you can update the data in an Oracle VIEW providing you have the proper privileges to the underlying Oracle tables.
Question: Does the Oracle View exist if the table is dropped from the database?
Answer: Yes, in Oracle, the VIEW continues to exist even after one of the tables (that the Oracle VIEW is based on) is dropped from the database. However, if you try to query the Oracle VIEW after the table has been dropped, you will receive a message indicating that the Oracle VIEW has errors.
If you recreate the table (the table that you had dropped), the Oracle VIEW will again be fine.
Materialized View
Differentiate view and materialized view
view | Materialized view |
are virtual only and run the query definition each time they are accessed | are disk based and update periodically base upon the query definition. |
Views evaluate the data in the tables underlying the view definition at the time the view is queried |
|
It is a logical view of your tables, with no data stored anywhere else. | Materialized views are similar to regular views |
The upside of a view is that it will always return the latest data to you. | The upside of this is this is that when you query a materialized view, you are querying a table, which may also be indexed |
| with query rewrite enabled, Oracle can optimize a query that selects from the source of your materialized view in such a way that it instead reads from your materialized view |
The downside of a view is that its performance depends on how good a select statement the view is based on. If the select statement used by the view joins many tables, or uses joins based on non-indexed columns, the view could perform poorly. | The downside though is that the data you get back from the materialized view is only as up to date as the last time the materialized view has been refreshed. |
| Materialized views can be set to refresh manually, on a set schedule, or based on the database detecting a change in data from one of the underlying tables. |
| Materialized views are most often used in data warehousing / business intelligence applications where querying large fact tables with thousands of millions of rows would result in query response times that resulted in an unusable application. |
Views are essentially logical table-like structures populated on the fly by a given query. The results of a view query are not stored anywhere on disk and the view is recreated every time the query is executed | Materialized views are actual structures stored within the database and written to disk. They are updated based on the parameters defined when they are created. |
Limitation & Syntax of Materialized View
CREATE MATERIALIZED VIEW view-name
BUILD [IMMEDIATE | DEFERRED]
REFRESH [FAST | COMPLETE | FORCE ]
ON [COMMIT | DEMAND ]
[[ENABLE | DISABLE] QUERY REWRITE]
[ON PREBUILT TABLE]
AS
SELECT ...;
IMMEDIATE : The materialized view is populated immediately.
DEFERRED : The materialized view is populated on the first requested refresh.
FAST : A fast refresh is attempted. If materialized view logs are not present against the source tables in advance, the creation fails.
COMPLETE : The table segment supporting the materialized view is truncated and repopulated completely using the associated query.
FORCE : A fast refresh is attempted. If one is not possible a complete refresh is performed.
ON COMMIT : The refresh is triggered by a committed data change in one of the dependent tables.
ON DEMAND : The refresh is initiated by a manual request or a scheduled task.
Create materialized view
Error: ORA-01031: insufficient privileges, on a_student
It's easier to GRANT or REVOKE privileges to the users through a role rather than assigning a privilege directly to every user. If a role is identified by a password, then, when you GRANT or REVOKE privileges to the role, you definitely have to identify it with the password.
Authentication vs Authorization
Authentication | Authorization |
Authentication verifies who you are | Authorization verifies what you are authorized to do. |
For example, you can login | For example, you are allowed to login into your Unix server via ssh client, but you are not authorized to browser /data2 or any other file system. |
| Authorization occurs after successful authentication |
| Authorization can be controlled at file system level or using various application level configuration |
Authentication: I am an employee of the company. Here is my ID badge. | Authorization: As an employee of the company, I am allowed entrance into the building. |
Authorization:
Each system privilege allows a user to perform a particular database operation or class of database operations; for example, the privilege to create tablespaces is a system privilege.
Each object privilege allows a user to perform a particular action on a specific object, such as a table, view, sequence, procedure, function, or package
Tablespace Quotas, Profiles and Resource Limits )
System Privileges
Syntax
GRANT {system_privilege|role}
[, {system_privilege|role} ]...
TO {user|role|PUBLIC}
[, {user|role|PUBLIC} ]...
[WITH ADMIN OPTION]..
REVOKE {system_privilege|role}
[, {system_privilege|role} ]...
FROM {user|role|PUBLIC}
[, {user|role|PUBLIC} ]...
Object Privileges
GRANT { object_privilege [(column_list)]
[, object_privilege [(column_list)] ]...
|ALL [PRIVILEGES]}
ON [schema.]object
TO {user|role|PUBLIC}[, {user|role|PUBLIC} ]...
[WITH GRANT OPTION]
Example
Grant select on scott.emp to jeff with grant option
Revoke Priviledge
REVOKE { object_privilege
[, object_privilege ]...
| ALL [PRIVILEGES] }
ON [schema.]object
FROM {user|role|PUBLIC}
[, {user|role|PUBLIC} ]...
[CASCADE CONSTRAINTS]
ROLES
Benefits of Roles�
CREATE ROLE role
Assign privilege to role
Assign role to user or roles
Data Encryption
RSA
RSA (Choosing Public / Private Key)
1 < e < ϕ(n)
That is inverse of public key
[e* d mod [ϕ(n) = 1]
RSA …..
Strengths of RSA
Missing Information
ID | Name | Marital Status | Salary |
1 | A | Married | |
2 | B | | 15000 |
3 | | Unmarried | 23000 |
Sometimes we don’t know what value an entry in a relation should have
Two main methods have been proposed to deal with this
NULL’s
Problems with NULLs
Theoretical solutions
Boolean Operators
AND | T | U | F |
T | T | U | F |
U | U | U | F |
F | F | F | F |
OR | T | U | F |
T | T | T | T |
U | T | U | U |
F | T | U | F |
NOT | |
T | F |
U | U |
F | T |
3 Value Logic-3VL
X | Y | X AND Y | X OR Y | NOT X |
T | T | T | T | F |
T | U | U | T | F |
T | F | F | T | F |
U | T | U | T | U |
U | U | U | U | U |
U | F | F | U | U |
F | T | F | T | T |
F | U | F | U | T |
F | F | F | F | T |
For example A=3, B=4 and C=unk
Check
Maybe Boolean Operator
Maybe | |
T | f |
U | t |
f | f |
Exists expression
Exists V(p(v)) is defined to be equivalent to False or (p(t1) or p(t2) or… or p(tm))
ID | Name | Marital Status | Salary |
1 | A | Married | |
2 | B | | 15000 |
3 | | Unmarried | 23000 |
Exists (Marital_status=Married)
=f or (t or unk or f)
=f or t
=t
Exists (Maybe((Marital_status=Married) ))
=f or (maybe(t) or maybe(unk) or maybe(f))
=f or (f or t or f)
=f or t
=true
ForAll expression
ForAll V(p(v)) is defined to be equivalent to true and (p(t1) and p(t2) and… and p(tm))
ID | Name | Marital Status | Salary |
1 | A | Married | |
2 | B | | 15000 |
3 | | Unmarried | 23000 |
Forall (Marital_status=Married)
=t and (t and unk and f)
=t and f
=f
IS_UNK operator
It takes a single scaler operand and returns true if that operand evaluates to unk otherwise false
ID | Name | Marital Status | Salary |
1 | A | Married | |
2 | B | | 15000 |
3 | | Unmarried | 23000 |
Exists (IS_UNK(name)
=f or (f or f or t)
=t
Forall(IS_UNK(name)
=t and (f and f and t)
=f
IF_UNK operator
IF_UNK operator takes 2 scaler operands and return the value of 1st operand unless that operand evaluates to unk
IF_UNK(exp1,exp2)= IF_UNK(exp1) then return exp2 else exp1;
Note: exp1 & exp2 must be of same type
Example:::: IF_UNK k(name,’no name’)
Whenever name is unknown ‘no name’ will be the default value
UNK== unk ?
UNK= the value unknown
unk=the unknown truth value
X is a boolean variable can have values like true, false or unk.
“x is unk”= value of x is known to be unk
“x is UNK”= value of x is not known
Example1
STU_ID | STU_NAME | SCHOLARSHIP_AMOUNT | ELECTIVE_SUBJECT |
1 | Samantha | 2000 | WT |
2 | Smith |
| .NET |
3 | David | 2000 | .NET |
4 |
|
| WT |
5 | Jennifer |
|
|
6 |
| 2000 | .NET |
Solution1
Example2
Branch_Id | Branch_Name | City | Emp_Head |
B001 | KALUPUR | AHMEDABAD | Anil |
B002 | KAROLI BAUG | VADODRA | Dhani |
B003 | MALAD | unk | unk |
B005 | unk | unk | Mukesh |
a) EXISTS(maybe(V.Branch_id=B003))
b) FORALL V (maybe(city=unk) or is_unk(Emp_head))
c) EXISTS V(is_unk(Branch_Name))