0% found this document useful (0 votes)
39 views

Privileges in SQL:: Allows Read Access To Relation, or The Ability To Query

The document discusses various SQL privileges including select, insert, update, delete, and all privileges. It also covers SQL commands such as UPDATE, BETWEEN/AND, and provides examples of their usage. Additionally, it discusses database normalization including first normal form, second normal form, third normal form, functional dependencies, and transitive dependencies. The goal of normalization is to minimize redundancy and anomalies during data modification.

Uploaded by

Ayele Mitku
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
39 views

Privileges in SQL:: Allows Read Access To Relation, or The Ability To Query

The document discusses various SQL privileges including select, insert, update, delete, and all privileges. It also covers SQL commands such as UPDATE, BETWEEN/AND, and provides examples of their usage. Additionally, it discusses database normalization including first normal form, second normal form, third normal form, functional dependencies, and transitive dependencies. The goal of normalization is to minimize redundancy and anomalies during data modification.

Uploaded by

Ayele Mitku
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 29

Privileges in SQL

• select: allows read access to relation,or the ability to query


using the view
Example: grant users U1, U2, and U3 select authorization on the branch
relation:
grant select on branch to U1, U2, U3
• insert: the ability to insert tuples
• update: the ability to update using the SQL update statement
• delete: the ability to delete tuples.
• all privileges: used as a short form for all the allowable
privileges
UPDATE

• To change the data values in a pre existing table, the


UPDATE command can be used. 
UPDATE tablename 
SET colX = valX [, colY = valY, ...] 
WHERE condition 
• How can you change “abebe" into "CHala" in the
"LastName" column in the Persons table?
• UPDATE Persons SET LastName=' abebe ' INTO LastName='
CHala' ;
• MODIFY Persons SET LastName=' CHala' WHERE
LastName=' abebe‘;
BETWEEN / AND

• The BETWEEN ... AND operator selects a range


of data between two values. These values can
be numbers, text, or dates. 

SELECT*FROM table_name WHERE col_name 
BETWEEN val1 AND val2;
chapter 2 Basics of Functional Dependencies and
Normalization for Relational Databases

• There are two levels at which we can discuss the


goodness of relation schemas.
• The first is the logical (or conceptual) level—how
users interpret the relation schemas and the meaning
of their attributes.
• The second is the implementation (or physical
storage) level—how the tuples in a base relation are
stored and updated.
• database design may be performed using two
approaches: bottom-up or top-down.
Conn…
• A bottom-up design methodology (also called
design by synthesis) considers the basic relationships
among individual attributes as the starting point and
uses those to construct relation schemas.
• top-down design methodology (also called design
by analysis) starts with a number of groupings of
attributes into relations that exist together naturally,
for example, on an invoice, a form, or a report.
Informal Design Guidelines
for Relation Schemas
• Four informal guidelines that may be used as measures
to determine the quality of relation schema design:
■ Making sure that the semantics of the attributes is clear
in the schema.
■ Reducing the redundant information in tuples.
■ Reducing the NULL values in tuples.
■ Disallowing the possibility of generating spurious
tuples. referance(Fundamentals of Database Systems -
6th Edition - by Ramez Elmasri & Shamkant Navathe
around page 505 )
Conn…
• The problems we pointed out, which can be detected without
additional tools of analysis, are as follows:
■ Anomalies that cause redundant work to be done during
insertion into and modification of a relation, and that may cause
accidental loss of information during a deletion from a relation.
■ Waste of storage space due to NULLs and the difficulty of
performing selections, aggregation operations, and joins due to
NULL values.
■ Generation of invalid and spurious data during joins on base
relations with matched attributes that may not represent a
proper (foreign key, primary key) relationship.
Functional Dependencies
• A functional dependency is a constraint between two
sets of attributes from the database. Suppose that our
relational database schema has n attributes A1, A2, ...,
An; let us think of the whole database as being
described by a single universal relation schema.
• R = {A1, A2, ... , An}.
• We do not imply that we will actually store the
database as a single universal table; we use this
concept only in developing the formal theory of data
dependencies.
Conn..

• Definition. A functional dependency, denoted by X → Y,


between two sets of attributes X and Y that are subsets of
R specifies a constraint on the possible tuples that can form
a relation state r of R.
• The constraint is that, for any two tuples t1 and t2 in r that
have t1[X] = t2[X], they must also have t1[Y] = t2[Y].
• This means that the values of the Y component of a tuple in
r depend on, or are determined by, the values of the X
component; alternatively, the values of the X component of
a tuple uniquely (or functionally) determine the values of
the Y component.
Normal Forms Based on Primary Keys
Normalization of Relations
• The process, which proceeds in a top-down fashion by evaluating each
relation against the criteria for normal forms and decomposing relations
as necessary, can thus be considered as relational design by analysis.
• Codd proposed three normal forms, which he called first, second, and
third normal form.
• A stronger definition of 3NF—called Boyce-Codd normal form (BCNF)—
was proposed later by Boyce and Codd.
• All these normal forms are based on a single analytical tool the
functional dependencies among the attributes of a relation.
• Later, a fourth normal form (4NF) and a fifth normal form (5NF) were
proposed, based on the concepts of multivalued dependencies and join
dependencies, respectively.
Normalization of data
• can be considered a process of analyzing the given
relation schemas based on their FDs and primary
keys to achieve the desirable properties of:
• 1)minimizing redundancy
• 2) minimizing the insertion, deletion, and update
anomalies.
• considered as a “filtering” or “purification”
process to make the design have successively
better quality.
Conn…
normalization procedure provides database
designers with the following:
■ A formal framework for analyzing relation
schemas based on their keys and on the
functional dependencies among their attributes
■ A series of normal form tests that can be carried
out on individual relation schemas so that the
relational database can be normalized to any
desired degree
Conn…
• Denormalization is the process of storing the join of
higher normal form relations as a base relation, which
is in a lower normal form.
1. First Normal Form
• Disallow multivalued attributes, composite attributes,
and their combinations.
• It states that the domain of an attribute must include
only atomic (simple, indivisible) values and that the
value of any attribute in a tuple must be a single value
from the domain of that attribute.
Conn…
Conn…
Conn…
• Normalization into 1NF. (a) A relation schema
that is not in 1NF. (b) Sample state of relation
DEPARTMENT. (c) 1NF version of the same
relation with redundancy.
• The domain of Dlocations contains sets of
values and hence is nonatomic.
• Inthis case, Dnumber→Dlocations because
each set is considered a single member of the
attribute domain
Conn…
• There are three main techniques to achieve first normal form for such
a relation:
• Remove the attribute Dlocations that violates 1NF and place it in a
separaterelation DEPT_LOCATIONS along with the primary key
Dnumber of DEPARTMENT.
• Expand the key so that there will be a separate tuple in the original
DEPARTMENT relation for each location of a DEPARTMENT.
• If a maximum number of values is known for the attribute—for
example, if it is known that at most three locations can exist for a
department—replace the Dlocations attribute by three atomic
attributes: Dlocation1, Dlocation2, and Dlocation3. This solution has
the disadvantage of introducing NULL values if most departments have
fewer than three locations.
Conn…
• First normal form also disallows multivalued attributes that
are themselves composite.
• These are called nested relations because each tuple can
have a relation within it. the EMP_PROJ relation could
appear if nesting is allowed. Each tuple represents an
employee entity, and a relation PROJS(Pnumber, Hours)
within each tuple represents the employee’s projects and
the hours per week that employee works on each project.
The schema of this EMP_PROJ relation can be represented
as follows:
• EMP_PROJ(Ssn, Ename, {PROJS(Pnumber, Hours)})
Second Normal Form

• Second normal form (2NF) is based on the concept


of full functional dependency.
• Afunctional dependency X → Y is a full functional
dependency if removal of any attribute A from X
means that the dependency does not hold any more.
• A functionaldependency X→Y is a partial
dependency if some attribute A ε X can be removed
from X and the dependency still holds; that is, for
some A ε X, (X – {A}) → Y.
Conn…
• Definition. A relation schema R is in 2NF if
every nonprime attribute A in R is fully
functionally dependent on the primary key of
R.
Third Normal Form
• Third normal form (3NF) is based on the
concept of transitive dependency.
• A functional dependency X→Y in a relation
schema R is a transitive dependency if there
exists a set of attributes Z in R that is neither a
candidate key nor a subset of any key of R,and
both X→Z and Z→Y hold.
• The dependency Ssn→Dmgr_ssn is transitive
through Dnumber in EMP_DEPT
Conn…
Conn…
Conn…
• dependencies Ssn → Dnumber and Dnumber →
Dmgr_ssn hold and Dnumber is neither a key itself
nor a subset of the key of EMP_DEPT. Intuitively, we
can see that the dependency of Dmgr_ssn on
Dnumber is undesirable in EMP_DEPT since
Dnumber is not a key of EMP_DEPT.
• N.b: According to Codd’s original definition, a
relation schema R is in 3NF if it satisfies 2NF and no
nonprime attribute of R is transitively dependent on
the primary key.
General Definitions of Second
and Third Normal Forms
• we want to design our relation schemas so
that they have neither partial nor transitive
dependencies because these types of
dependencies cause the update anomalies.
• The steps for normalization into 3NF relations
that we have discussed so far disallow partial
and transitive dependencies on the primary
key.
Conn…
Conn…
• prime attribute, an attribute that is part of any
candidate key will be considered as prime.
• Partial and full functional dependencies and
transitive dependencies will now b considered
with respect to all candidate keys of a relation.
• General Definition of Second Normal Form
• Definition. A relation schema R is in second
normal form (2NF) if every nonprime attribute A
in R is not partially dependent on any key of R
Conn…

You might also like