The relational model is very simple and elegant; a database is a collection of one or more relations, where each relation is a table with rows and columns. This simple tabular representation enables even novice users to understand the contents of a database and it permits the use of simple, high-level languages to query the data. The major advantages of the relational model over the older data models are its simple data representation and the ease with which even complex queries can be expressed. The relational model represents the database as a collection of relations (or tables). Informally each relation resembles a table of values or, to some extent, a “flat” file of records. One of the main advantages of relational model is that it is conceptually simple and more important. It also frees the users from detail of storage and access methods. Show A relational model was proposed by Ted Codd of IBM Research in 1970. Basic concept in relational model is that the relation can be viewed as a table which has the following properties
Attributes In relational model terminology all the column headers are called attributes. Consider a table STUDENT. In this table there are three column headers, it means this table has three attributes RollNo, Name, Address
Domain “The set of permitted values for each attribute is called domain” or “A domain is referred to in a relation schema by the attribute name and has a set of associated values”. A domain D is a set of atomic values. By Atomic we mean that each value in the domain is individual as far as the relational model is concerned. “The data type describing the types of values that can appear in each column is represented by a domain of possible values.” For example Set_phone_number can be declared as of character strings. The data type for Employee_ages is an integer number between 15 and 80. For academic_deaprtment_names, the data type is the set of all characters strings that represent valid department names. A domain is thus given a name, data type, and format. Tuples / Records In relational model terminology all the rows are called tuples or records in the relation. Consider a table STUDENT. In this table there are six rows, it means there six tuples or records in this table Relation schema “The relation schema describes the column headers for the table or relation”. A relation schema R denoted by R (A1, A2, A3…An), is made up of a relation name R and a list of attributes A1, A2, A3… An. Each attribute Aj, is the name of role played by some domain D in the relation schema R. D is called domain of Aj and is denoted by dom (Aj). A relation schema is used to describe a relation R, and R is called the name of this relation. “The
degree (or arity) of a relation is the number of attributes of its relation schema”. STUDENT (Name, RollNo, HomePhone, Address, OfficePhone, Age, GPA) Relation The main construct for representing data in the relational model is a relation. “A relation consists of a relation schema and a relation instance. The relation instance is a table, and the relation schema describes the column heads for the table”. A relation (or relation state) r of the relation schema R (A1, A2, A3…An), is a set of n–tuples r = {t1, t2, t3, . . . .tn}, which is denoted by r (R). Each tuple t is an ordered
list of n values t = , where each value vi (1in) is an element of domain or is a special null value. Characteristics of relations
An important concept is that of nulls, which are used to represent the values of attributes that may be unknown or may not apply to a tuple. A special value, called null is used for these cases.
Key “A key is a subset of one or more fields that allows us to identify a set of attributes that suffice to distinguish tuples from each other”. It is used to implement the concept of key constraints in the relations. Superkey Superkey is a subset of one or more attributes that allows us to identify uniquely a tuple in the relation. For example in the above relation the sid attribute of the relation STUDENT is sufficient to distinguish one student entity or a tuple from another. Each relation contains a default Superkey which is a set of all the attributes. In above relation STUDENT {sid}, {login}, {sid, name}, {name, login}, {sid, name, login, age} is a Superkey, and set of all attribute {sid, name, login, age, gpa} is also a Superkey, which is default Superkey for this relation. Candidate key A minimal subset of fields that uniquely identifies tuples in a relation is called a candidate key for the relation. It is also called a minimal Superkey for a relation. A relation may have several candidate keys. Primary key Primary key is a key or a key attribute in a relation which allows only unique values to be accepted by a relation. It does not allow a relation to accept null values. Primary key is a key by which all the tuples can be identified uniquely. It restricts the duplicate rows in a relation. Foreign key When a primary key of a relation (or a table) is used as a primary key in another relation (or table), it is called foreign key. For example there are two relations EMPLOYEE and SALARY which contain employee details and salary details of employee respectively. An attribute {emp_id} which is present in both the relation can be considered as a primary key in EMPLOYEE relation and as a foreign key in SALARY relation. Unique key Unique key is just like a primary key with a little difference that primary key enforces the NOT NULL constraint but unique key do not enforce NOT NULL constraint in the relation. It means a unique key is a key which allows a relation to accept only unique values and null value. A unique value can accept only one null value in a relation. Alternate key A relation may contain more then one candidate key. If one candidate key has been chosen as a primary key than another candidate key is called alternate key in that relation. For example a STUDENT relation has two attributes {s_di} and {login_id}. In this case both attributes serve as a unique identifier for the relation. Hence, both of them are called the candidate keys. If suppose {s_id} has been chosen as primary key then {login_id} would become alternate key Composite key In certain tables a single attribute can not be used to identify rows uniquely then a combination of two or more attributes is used to as a primary key. Such keys are called composite keys. The main types of constraints that can be expressed in the relational model are as
Which attribute used to uniquely identify tuples in a relation?A relation can have one or more attributes that takes distinct values. Any of these attributes can be used to uniquely identify the tuples in the relation. Such attributes are called candidate keys as each of them are candidates for the primary key.
What is used to uniquely identify each tuple in a table?Primary key is a Candidate key chosen to uniquely identify tuples in the table. Primary key values should be unique and non-null. There can be multiple Super keys and Candidate keys in a table, but there can be only one Primary key in a table.
Is an attribute or a set of attributes that uniquely identifies the relation?Super Key is an attribute (or set of attributes) that is used to uniquely identifies all attributes in a relation.
|