220 likes | 305 Views
Databases and DBMSs. Todd S. Bacastow January 2005. 1. Evolution. Ways of storing data. Files (1960) (ancient times) Databases Hierarchical (1970) Network (1970) Relational (1980) Object (1990). File terms. Record
E N D
Databases and DBMSs Todd S. Bacastow January 2005 1
Ways of storing data • Files (1960) (ancient times) • Databases • Hierarchical (1970) • Network (1970) • Relational (1980) • Object (1990)
File terms • Record • data items related to a single logical entity (e.g. a student’s information) or row in a table • Field • a place for a data item in a record (first name field in a student record) or a column in a table • File • a sequence of records of the same type (the table)
File structures A file: “STUDENT” field ID Last First Grade 3 Smith Jane A 1 Wood Bob C 2 Kent Chuck B 4 Boone Dan B record
File organization • Serial • new records appended • Sequential • records ordered in file, usually according to a numeric key
File structures • Indexes provide a reference to records based on an index field, which is ordered Last Pointer ID Last First Grade Boone * Kent * Smith * Wood * 1 Wood Bob C 2 Kent Chuck B 3 Smith Jane A 4 Boone Dan B
Problems with files • Redundancy • number of files grows with applications, and data is duplicated • Inconsistency • data is updated in one application’s files, but not in another’s • Maintenance problems • changes to data structures mean changes to many programs • Difficulty combining data • business needs may mean users want data from different applications
Other ways to organize • Data model • A data model is a particular way of conceptually organizing multiple data files in a database • Other common models • Hierarchical • Network • Relational • Object
Network data model • Advantages • flexible, fast, efficient • Disadvantages • Complex • Restructuring can be difficult because of changing all the pointers
Network data model Relationships: • one-to-one • one-to-many • many-to-one • many-to-many Class Student Instructor Department Grade ID
Hierarchical data model • Parent-child relationship: • one-to-one • one-to-many Class Student Instructor Department Grade ID
Hierarchical data model • Advantages • easy to search • add new branches easily • Disadvantages • Must establish the types of search prior to development of the hierarchical structure
Relational database • Fields (columns) in the table store attributes. • Each attribute has a specific domain. • (records or rows) in the table store information. • Each record is a unique instance of an object. • Tables are composed of a set of records. • A table is also called a relation.
Terms • Table • A collection of relevant data relating to one type of real world objects. • Column • A specific place for one type of data relating to one type of real world objects. • Domain • Set of all possible values for a specific column. • Row • Collection of data describing one real world object. • Primary Key • Columns, which are part of the row and uniquely identify any one row.
Records • Each record represents a logical entity (e.g. a student) • Each field represents an attribute of the logical entity Student ID Last First Grade Class 1 Wood Bob C IST357 2 Kent Chuck B IST115 3 Smith Jane A IST357 4 Boone Dan B IST357
Keys • Each table has a primary key, one field (or a combination of fields) that has a unique value for each and every record in the table Student ID Last First Grade Class ID is the primary key in this table (two students may share either a last or first name) 1 Wood Bob C IST357 2 Kent Chuck B IST115 3 Smith Jane A IST357 4 Boone Dan B IST357
Relating tables • Tables can be related (joined) together based on their keys • The idea is to decompose into separate tables with no redundancy and to provide a capability to reassemble with no information loss Student Class ID Last First Grade Class Name #Stud Instructor 1 Wood Bob C IST357 2 Kent Chuck B IST115 3 Smith Jane A IST357 4 Boone Dan B IST357 IST357 48 Jones IST115 120 Brower IST20 120 Fountain
Relating tables Primary key Foreign key Primary key Student Class ID Last First Grade Class Name #Stud Instructor 1 Wood Bob C IST357 2 Kent Chuck B IST115 3 Smith Jane A IST357 4 Boone Dan B IST357 IST357 48 Jones IST115 120 Brower IST20 120 Mennis
Relationships • Link between entities. • A relationship may define constraints. • E.G, a person can only have one SSN.