【文章內(nèi)容簡介】
al database was originally defined and coined by Edgar Codd at IBM Almaden Research Center in 1970. Relational database theory uses a set of mathematical terms, which are roughly equivalent to SQL database terminology. 1.2 Relations or TablesA relation is defined as a set of tuples that have the same attributes. A tuple usually represents an object and information about that object. Objects are typically physical objects or concepts. A relation is usually described as a table, which is organized into rows and columns. All the data referenced by an attribute are in the same domain and conform to the same constraints.The relational model specifies that the tuples of a relation have no specific order and that the tuples, in turn, impose no order on the attributes. Applications access data by specifying queries, which use operations such as select to identify tuples, project to identify attributes, and join to bine relations. Relations can be modified using the insert, delete, and update operators. New tuples can supply explicit values or be derived from a query. Similarly, queries identify tuples for updating or deleting. It is necessary for each tuple of a relation to be uniquely identifiable by some bination (one or more) of its attribute values. This bination is referred to as the primary key.1.3 Base and derived relationsIn a relational database, all data are stored and accessed via relations. Relations that store data are called base relations, and in implementations are called tables. Other relations do not store data, but are puted by applying relational operations to other relations. These relations are sometimes called derived relations. In implementations these are called views or queries. Derived relations are convenient in that though they may grab information from several relations, they act as a single relation. Also, derived relations can be used as an abstraction layer.1.3.1DomainA domain describes the set of possible values for a given attribute. Because a domain constrains the attribute39。s values and name, it can be considered constraints. Mathematically, attaching a domain to an attribute means that all values for this attribute must be an element of the specified set .The character data value 39。ABC39。, for instance, is not in the integer domain. The integer value 123, satisfies the domain constraint.1.4 ConstraintsConstraints allow you to further restrict the domain of an attribute. For instance, a constraint can restrict a given integer attribute to values between 1 and 10. Constraints provide one method of implementing business rules in the database. SQL implements constraint functionality in the form of check constraints.Constraints restrict the data that can be stored in relations. These are usually defined using expressions that result in a boolean value, indicating whether or not the data satisfies the constraint. Constraints can apply to single attributes, to a tuple (restricting binations of attributes) or to an entire relation.Since every attribute has an associated domain, there are constraints (domain constraints). The two principal rules for the relational model are known as entity integrity and referential integrity.1.4.1 Foreign keysA foreign key is a reference to a key in another relation, meaning that the referencing tuple has, as one of its attributes, the values of a key in the referenced tuple. Foreign keys need not have unique values in the referencing relation. Foreign keys effectively use the values of attributes in the referenced relation to restrict the domain of one or more attributes in the referencing relation.A foreign key could be described formally as: For all tuples in the referencing relation projected over the referencing attributes, there must exist a tuple in the referenced relation projected over those same attributes such that the values in each of the referencing attributes match the corresponding values in the referenced attributes.1.5 Stored proceduresA stored procedure is executable code that is associated with, and generally stored in, the database. Stored procedures usually collect and customize mon operations, like inserting a tuple into a relation, gathering statistical information about usage patterns, or encapsulating plex business logic and calculations. Frequently they are used as an application programming interface (API) for security or simplicity. Implementations of stored procedures on SQL DBMS often allow developers to take advantage of procedural extensions (often vendorspecific) to the standard declarative SQL syntax.Stored procedures are not part of the relational database model, but all mercial implementations include them.1.6 IndicesAn index is one way of providing quicker access to data. Indices can be created on any bination of attributes on a relation. Queries that filter using those attributes can find matching tuples randomly using the index, without having to check each tuple in turn. Relational databases typically supply multiple indexing techniques, each of which is optimal for some bination of data distribution, relation size, and typical access pattern.Indices are usually not considered part of the database, as they are considered an implementation detail, though indices are usually maintained by the same group that maintains the other parts of the database.2 Relational operationsQueries made against the relational database, and the derived relations in the database are expressed in a relational calculus or a relational algebra. In his original relational algebra, Codd introduced eight relational operators in two groups of four operators each. The first four operators were based on the traditional mathematical set operations:(1)The union operator bines the tuples of two relations and removes all duplicate tuples from the result. The relational union operator is equivalent to the SQL UNION operator. (2)The intersection operator produces the