Beruflich Dokumente
Kultur Dokumente
Relational system
Briefly, a relational system is a system in which: (a) The data is perceived by the user as tables (and nothing but tables); and (b)The operators at the users disposal (e.g., for data retrieval) are operators that generate new tables from old. The relational model is divided into three parts, having to do with 1. data structure, 2. data integrity, and 3. data manipulation, respectively All three parts have their own special terms. The most important of the terms used in connexion with the data structure part are shown in Fig. Shown below, A relation corresponds is a table. A tuple corresponds to a row of such a table and an attribute to a column. The number of tuples is called the cardinality and the number of attributes is called the degree. The primary key is a unique identifier for the tablethat is, a column or column combination with the property that, at any given time, no two rows of the table contain the same value in that column or column combination. Finally, a domain is a pool of values, from which one or more attributes (columns) draw their actual values. For example, the domain labeled S# in Fig. 11.1 is the set of all legal supplier numbers
These terms are summarized in the table (Data structure terminology) Formal relational term relation tuple cardinality attribute degree primary key domain Informal equivalents table row or record number of rows column or field number of columns unique identifier pool of legal values
Page 1 of 9
Table
A table in a relati ional syste em consist ts of Head: a row of co olumn hea adings, tog gether with Body: zero z or mo ore rows of o data valu ues.
Base Tab ble (Base relations) A base ta able is table that the tabl le exists in it ts own right. It given a name via an a appropria ate CREATE E statement.
EATE VEIW W GOOD-SU UPPLIERS CRE AS S SELECT S#, S STATUS, CITY FROM S RE STATUS S > 15; WHER Pag ge 2 of 9
3-
Snapshots:
A snapshot is also a named, derived relation, like a view. Unlike a view, however, a snapshot is real, not virtuali.e., it is represented not only by its definition in terms of other named relations, but also by its own stored data. an example (pseudoSQL): CREATE SNAPSHOT Sc AS SELECT S#, CITY FROM S REFRESH EVERY DAY Creating a snapshot is much like executing a query, except that (i) the result of that query is stored in the database under the specified
name (SC in the example ) as a read-only relation, and (ii) periodically (EVERY DAY in the example) the sbapshot is refreshedi.e., its current value is discarded, the query is executed a and the result of that new execution becomes the new value of the snapshot. 4- Query results: 5Intermediate results:
An intermediate result is a relation (typically unnamed) that results from some relational expression that is nested within some larger expression. For example, consider the following SQL statement:
SELECT DISTINCT S.CITY FROM S WHERE S.S# IN (SELECT SP.S# FROM SP WHERE SP.P# P2);
The relation resulting from the sub query here is an intermediate result. Like a final query result, it has no persistent existence within the database.
6- Temporary relations
A temporary relation is a named relation, like a base relation or view or snapshot, but (unlike a base relation or view or snapshot) one that automatically destroyed at some appropriate time (e.g., at the end of an interactive session). Base relations, snapshots, and views, by contrast, are more permanent, the sense that they are only destroyed as a result of some explicit user action.
Page 3 of 9
INTRODUCTION TO VIEWS
A view in SQL terminology is a single table that is derived from other tables. These other tables could be base tables or previously defined views. A view is a predefined query on one or more tables called base tables. A view is not stored as a physical table. Oracle stores the information you use to create a view, its definition, in its system tables. When you use a view, Oracle activates its definition and perform SELECT statements based on the views definition. Views allow you to define exactly what information is delivered from underlying base tables upon which the views are defined Views provide a type of security known as discretionary access control, means that different users can see different rows and columns from the same base tables. Views act like filters, allowing certain information to pass through the filter to users but preventing other information from passing. A column subset view hides selected columns from some users but make them accessible to others. A row subset view users rows meeting stated criteria inaccessible to selected user groups
Types of Views
There are two fundamental types of views: Complex views;. Contains a subquery that retrieve data from multiple tables, or groups rows using GROUP BY or DISTINCT clause, or contains a function call. Simple views Retrieve rows from one base table.
Page 4 of 9
Updates on Views
Update mean, add (insert), remove (delete), and update You can not perform remove or add a row if the view contains the following Group functions A Group By clause The DISTINCT keyword The pseudo column ROWNUM keyword another case where addition record is not permitted which is: NOT NULL columns in the base tables that are not selected by the view.
Page 5 of 9
Examples CREATE OR REPLACE VIEW MaleEmployees AS SELECT * FROM Employee WHERE Sex = M WITH READ ONLY;
CREATE OR REPLACE VIEW Employee_View AS SELECT SSN, FirstName, LastName, BDate FROM employee;
In SQL, the clause WITH CHECK OPTION must be added at the end of the view definition if a view is to be updated. This allows the system to check for view updatability and to plan an execution strategy for view updates.
Page 6 of 9
Figure 0-1: Schema diagram for the COMPANY relational database schema.
Page 7 of 9
In VI, we did not specify any new attribute names for the view WORKS_ONI (although we could have); in this case, WORKS_ONI inherits the names of the view attributes from the defining tables EMPLOYEE, PROJECT, and WORKS_ON. View V2 explicitly specifies new attribute names for the view DEPT_INFO, using a one-to-one correspondence between the attributes specified in the CREATE VIEW clause and those specified in the SELECT clause of the query that defines the view.
Removing a view
Query a View
We can now specify SQL queries on a view-or virtual table-in the same way we specify queries involving base tables. For example, to retrieve the last name and first name of all employees who work on 'ProjectX', we can utilize the WORKS_ONI view and specify the query as in QVI:
Listing View Definition To display information about the views you can write the following SQL statement: SELECT view_name, text_length, text FROM user_views ORDER BY view_name; If you want to list all the views to which you have access. SELECT view_name, text_length, text FROM all_views ORDER BY view_name;
Page 9 of 9