Keys Let KcR K is a superkey of R if values for K are sufficient to identify a unique tuple of each possible relation r(R) by"possible r"we mean a relation r that could exist in the enterprise we are modeling. Example:{customer_name,customer_street}and {customer_name} are both superkeys of Customer,if no two customers can possibly have the same name In real life,an attribute such as customer id would be used instead of customer name to uniquely identify customers,but we omit it to keep our examples small,and instead assume customer names are unique. Database System Concepts-5th Edition,Oct 5,2006 2.12 @Silberschatz,Korth and Sudarshan
Database System Concepts - 5 2.12 ©Silberschatz, Korth and Sudarshan th Edition, Oct 5, 2006 Keys Let K R K is a superkey of R if values for K are sufficient to identify a unique tuple of each possible relation r(R) by “possible r ” we mean a relation r that could exist in the enterprise we are modeling. Example: {customer_name, customer_street} and {customer_name} are both superkeys of Customer, if no two customers can possibly have the same name In real life, an attribute such as customer_id would be used instead of customer_name to uniquely identify customers, but we omit it to keep our examples small, and instead assume customer names are unique
Keys (Cont.) K is a candidate key if K is minimal Example:{customer_name}is a candidate key for Customer,since it is a superkey and no subset of it is a superkey. Primary key:a candidate key chosen as the principal means of identifying tuples within a relation Should choose an attribute whose value never,or very rarely, changes. E.g.email address is unique,but may change Database System Concepts-5th Edition,Oct 5,2006 2.13 ©Silberschat乜,Korth and Sudarshan
Database System Concepts - 5 2.13 ©Silberschatz, Korth and Sudarshan th Edition, Oct 5, 2006 Keys (Cont.) K is a candidate key if K is minimal Example: {customer_name} is a candidate key for Customer, since it is a superkey and no subset of it is a superkey. Primary key: a candidate key chosen as the principal means of identifying tuples within a relation Should choose an attribute whose value never, or very rarely, changes. E.g. email address is unique, but may change
Foreign Keys A relation schema may have an attribute that corresponds to the primary key of another relation.The attribute is called a foreign key. E.g.customer_name and account_number attributes of depositor are foreign keys to customer and account respectively. Only values occurring in the primary key attribute of the referenced relation may occur in the foreign key attribute of the referencing relation. Schema diagram branch account depositor customer branch-name account_number customer_name customer-_name branch-city branch_name account_number customer_street assets balance customer-city loan borrower loan-number customer_name branch_name loan_number amount Database System Concepts-5th Edition,Oct 5,2006 2.14 @Silberschatz,Korth and Sudarshan
Database System Concepts - 5 2.14 ©Silberschatz, Korth and Sudarshan th Edition, Oct 5, 2006 Foreign Keys A relation schema may have an attribute that corresponds to the primary key of another relation. The attribute is called a foreign key. E.g. customer_name and account_number attributes of depositor are foreign keys to customer and account respectively. Only values occurring in the primary key attribute of the referenced relation may occur in the foreign key attribute of the referencing relation. Schema diagram
Query Languages Language in which user requests information from the database. Categories of languages Procedural Non-procedural,or declarative “Pure”languages: Relational algebra Tuple relational calculus Domain relational calculus Pure languages form underlying basis of query languages that people use. Database System Concepts-5th Edition,Oct 5,2006 2.15 ©Silberschat乜,Korth and Sudarshan
Database System Concepts - 5 2.15 ©Silberschatz, Korth and Sudarshan th Edition, Oct 5, 2006 Query Languages Language in which user requests information from the database. Categories of languages Procedural Non-procedural, or declarative “Pure” languages: Relational algebra Tuple relational calculus Domain relational calculus Pure languages form underlying basis of query languages that people use
Relational Algebra Procedural language Six basic operators select:o project::Π union: set difference:- Cartesian product:x rename:p The operators take one or two relations as inputs and produce a new relation as a result. Database System Concepts-5th Edition,Oct 5,2006 2.16 @Silberschatz,Korth and Sudarshan
Database System Concepts - 5 2.16 ©Silberschatz, Korth and Sudarshan th Edition, Oct 5, 2006 Relational Algebra Procedural language Six basic operators select: project: union: set difference: – Cartesian product: x rename: The operators take one or two relations as inputs and produce a new relation as a result