DataBase System K Mathematical Relations a The current values( relation instance,关系实例) of a relation are specified by a table E An element t of ris a tuple(T-a), represented by a row in a table H Order of tuples is irrelevant(元组是无序的 tuples may be stored in an arbitrary order) attributes (or columns) customer_namecustomer_street customer_city Jones Main Harrison Smith North Rye tuples Curry North Rye y(or rows) Lindsay Park Pittsfie/d customer Haichang Gao, Software School, Xidian University 8
DataBase System Haichang Gao , Software School , Xidian University 8 Mathematical Relations The current values (relation instance, 关系实例) of a relation are specified by a table An element t of r is a tuple(元组), represented by a row in a table Order of tuples is irrelevant (元组是无序的 tuples may be stored in an arbitrary order) Jones Smith Curry Lindsay customer_name Main North North Park customer_street Harrison Rye Rye Pittsfield customer_city customer attributes (or columns) tuples (or rows)
DataBase System Relational database E A Relational database consists of multiple relations E Information about an enterprise is broken up into parts, with each relation storing one part of the information G Example customer_id I customer_ namel customer street customer cit 19283-7465J ohnson 12 Alma st Palo alto 677-89-9011 Hayes 3 Main st H arrison 182-73-6091 Turner 123 Putnam Ave. Stamford 321-12-3123 Jones 100 Main St Harrison 336-66-9999 Lindsay 175 Park Ave Pittsfield 019-28-3746 Smith 72 North st R ve (a) The customer table The customer table stores information about customers Haichang Gao, Software School, Xidian University
DataBase System Haichang Gao , Software School , Xidian University 9 Relational Database A Relational database consists of multiple relations Information about an enterprise is broken up into parts, with each relation storing one part of the information Example: The customer table stores information about customers
DataBase System Relational database account_number branch_name balance customer_id I account-number A-101 Downtown500 192-83-7465 A-101 A-215 Mianus 700 19283-7465A-201 A-102 Perryridge 400 019-28-3746 A-215 A-305 Round Hill 350 677-89-9011 A-102 A-201 Brighton 900 182-73-609 A-305 A-222 Redwood 700 321-12-3123 A-217 A-217 Brighton 750 336-66-9999 A-222 019-283746 A-201 (b) The account table (c) The depositor table The account table stores information about accounts The depositor table containing information about which customer owns which account Storing all information as a single relation is NoT a good idea! Haichang Gao, Software School, Xidian University 10
DataBase System Haichang Gao , Software School , Xidian University 10 Relational Database (b) The account table (c) The depositor table The account table stores information about accounts. The depositor table containing information about which customer owns which account Storing all information as a single relation is NOT a good idea!
DataBase System 沙Key Let Kcr e K is a superkey(ig)of R if values for K are sufficient to identify a unique tuple of each possible relation r(R) custoer id customer name Customer street customer cit 192-83-7465 Johnson 12 Alma St Palo alto 677-89-9011 Hayes 3 Main st Harrison 182-73-609 Turner 123 Putnam Ave Stamford 321-12-3123 ones 100 Main St Harrison 336-66-9999 Lindsay 175 Park Ave Pittsfield 019-28-3746 Smith 72 North St Rve (a) The customer table E Example: customer id, customer name) and customer id are both superkeys of Customer a by possible r” ve mean a relation r that could exist in the enterprise we are modeling Haichang Gao, Software School, Xidian University 11
DataBase System Haichang Gao , Software School , Xidian University 11 Key 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). Example: {customer_id, customer_name} and {customer_id} are both superkeys of Customer. by “possible r ” we mean a relation r that could exist in the enterprise we are modeling
DataBase System 沙Key Let Kcr e K is a superkey(ig)of R if values for K are sufficient to identify a unique tuple of each possible relation r(R) g K is a candidate key(候选码) if K is minimal customer-id customer-name custommer street customer -city 192-83-7465 Johnson 12 Alma St Palo alto 677-89-9011 laves 3 Main st H larrison 182-73-6091 Turner 123 Putnam Ave.Stamford 321-12-3123Jo ones 100 Main St Harrison 336-66-9999 Lindsay 175 Park Ave Pittsfield 019-28-3746 Smith 72 North St Rve (a) The customer table H Example: customer id, is a candidate key for Customer since it is a superkey and no subset of it is a superkey H customer name is a candidate key also, assuming no two customers can possibly have the same name Haichang Gao, Software School, Xidian University 12
DataBase System Haichang Gao , Software School , Xidian University 12 Key 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). K is a candidate key(候选码) if K is minimal. Example: {customer_id} is a candidate key for Customer, since it is a superkey, and no subset of it is a superkey. {customer_name} is a candidate key also, assuming no two customers can possibly have the same name