Hele-Mai Haav: CSC210-Spring*01 CSC230-Spring*03 Database Design
The process of designing a database begins with an analysis of what information the database must hold and the relationships among components of that information. The structure of the database is called the database schema and it is specified in one of database design languages (e.g. E/R or ODL) If the design is committed to a form in which it can be put to a DBS, then the database takes physical existence
IDENTIFY RELATIONSHIPS DATABASE DESIGN IDENTIFY ENTITIES IDENTIFY RELATIONSHIPS CHECK FOR DESIGN PROBLEMS SELECT PRIMARY KEYS CREATE INITIAL RELATIONS APPLY NORMALIZATION PRINCIPLES PRODUCE FINAL DESIGN
UML Object-oriented DBS ODL Ideas Relations Relational DBS E-R Database modeling and implementation
Entity-Relationship Diagrams Entity and entity sets An entity set is a collection of distinguishable real-world objects with common properties. An entity is a member of an entity set Students, Instructors, Cars... Attributes An attribute is a data item that describes a property of an entity or a relationship name, registration number, rank….
Relationship Relationships are connections among two or more entity sets Multiplicity of E-R Relationships many-to-one many-to-many one-to-one
name addr title year movies Stars-in Stars length filmtype Owns Studios E-R schema of movie database name addr
Attributes on Relationships
E-R DIAGRAM S/W COMPANY SALES PERSON S/W PACKAGES REPRESENTS NAME PHONE RNO ADDRESS KEY SALES PERSON SSN REGION 1 n ONE-TO-MANY DISTRIBUTES PRICE MANY-TO-MANY m S/W PACKAGES CODE PURPOSE E-R DIAGRAM
ONE-TO-MANY RELATIONSHIP IBM MS BCS HELMES LAURI VERA JAANUS MERIKE JUSTAS S/W COMPANY REPRESENTS SALES PERSON
MANY-TO-MANY RELATIONSHIP IBM MS BCS HELMES OS/2 OFFICE 95 WIN NT OFFICE 97 WIN 95 S/W COMPANY DISTRIBUTES S/W PACKAGES LOTUS NOTES
Design Principles Faithfulness Entity sets and their attributes should reflect reality Whatever connections are asserted should make sense given what we know about the part of the real world being modeled
Avoiding Redundancy We should be careful to say everything once only Simplicity Counts Avoid introducing more elements into your design than are absolutely necessary
Keys in E-R model We underline the attributes belonging to a key for an entity set (primary key is indicated only) title year movies
Relational Database = set of RELATIONS (or TABLES) each with a distinct name Movies, Stars,…. Each relation has a set of ATTRIBUTES (or COLUMNS) with a distinct name within its relation title, year, length, filmtype,...
Relational data model is used by most commercial DBS Oracle, Informix, Sybase, MS Access Relational model is very simple
Keys: A key for a relation is a set of attributes such that no two tuples can have the same values for all of their key attributes. In real databases, if there isn't a natural, compact one-attribute key, then keys may be system-generated.
Translating E-R design to relations Assume each entity set has a specified key Translation can be fully automated (except determining keys for generated relations in certain cases)
1. Entity set (strong) translates directly to relation SW Company R-No Name Address Phone R101 IBM Pirita tee 4 6 245 555 R102 Microsoft XYZ 5 5 666 666 R103 BCS Narva mnt 2 6 765 456 R104 Helmes Parnu mnt 123 6 507 567 R106 IE Soft Akadeemia tee 21 6578900
E-R Relationships translate to Relations Corresponding relation has attribute for key attributes of each entity set (E. S.) that participates in relationship if the relationship has attributes, then these are also attributes of corresponding relations renaming attributes is OK (needed if multiple roles in one E. S.
2. Binary relationship set between entity sets translates to relation containing keys for entity sets RNO Code Price R101 S100 550 R101 S200 2000 R101 S300 5000 R101 s333 340 R101 S500 3500 R101 S600 8000 R102 S300 4000 R102 S301 3000 R102 s444 4589 R103 S302 3500 R104 S500 6000 R106 S100 600 R106 S401 700 Distribution Relationship set with attributes: add attributes to relation for relationship set
What is key for relation? In most general case, key for the relation= all key attributes from all the E.S. involved in relationship however, the relation’s key excludes attributes from the “one” side if relationship is many-one for one-to-one relationship, choose which side provides the key for the relation
Combining relations Foreign key Salespersons Common case relation for an E.S. E plus the relation for some many-one relationship from E to another E.S. Foreign key Salespersons SSN Name Region RNo K10100 Lauri Estonia R104 K10150 Vera Estonia R103 K10200 Jaanus Latvia R104 K10300 Justas Lithuania R102 K10500 Merike Estonia R101 K10600 Marion Latvia R101 K20000 Margus Estonia R102 K300400 Edgars Latvia R106
name manuf addr name beers likes drinkers favorite married Example
Drinker(name,addr,….favoritebeerName) beers(name, manuf) likes(DrinkerName,BeerName) married(hasbund,wife)
Example:Registration process at CIUE Financial Information STUDENTS REGISTRAR Student Service Office BANK ACCOUNTANT Account Information Registration Information Special Forms Application 4 REGISTER 3 MANAGE REGISTRATION FORMS 2 SCHEDULE 1 MANAGE BILLS Money Receipts Data Pay Registration Chosen Courses Course data