Introduction to Databases CIS 5.2
Where would you find info about yourself stored in a computer? College Physician’s office Library Grocery Store Dentist’s office Verizon IRS …
General Definition A DATABASE is a collection of related data. Data = known facts that can be recorded and have implicit meaning.
“Miniworld” Each database can be viewed as representing a part of the real world, called a “miniworld.”
Size of a database Small database example: your personal phone directory Large database example: database of the IRS
DBMS – Database Management System A collection of programs that enables users to create and maintain a database.
MS Access is a DBMS In ACCESS, a DATABASE consists of a collection of tables.
Example of a Database
Table A table is defined by its columns, called fields. Each row (or entry) in a table is called a record. A record is the information about a specific person, product, or event.
Starting ACCESS 1.Begin ACCESS 2.Open a blank Database – although a database consists of many files, in Access, each database is viewed as a single file, hence a single icon.
Defining a TABLE A TABLE is defined by its fields (column headings). 1.Field Name – unique name 2.Data Type – type of info a field can contain. 3.Description – comments about field.
PRIMARY KEY unique identifierEach table must have a primary key which is a unique identifier for each record. Eg. ID number for a student, course number for a course, driver number for a driver, etc.
Two VIEWS of a Table 1.Design View – view the table’s definition, I.e. the fields and their properties. 2.Datasheet View – view the actual records in the table.
Database Design Arranging data into tables and fields. This process can be long and difficult.
Remove Redundancy WHY? Wastes space Updating is difficult Inconsistent data may result
Maintenance Modifying the data –Add records –Delete records –Update records Modifying the design –Add fields into tables –Remove fields from a table –Change characteristics of existing fields
Query Types Select Query – chooses data from a table and displays it. Update Query – updates records in a table Delete Query – deletes records from a table.
Validation Rules Validation Rules are rules that a user must follow when entering data into a database. Validation Text – the message that appears if the user enters the wrong type of data.
Validation Rules Indicate that a field is required Entry must lie within a given range Specify a valid collection of values Specify a default value Change lowercase to UPPERCASE
Referential Integrity Primary Key - unique identifier for each record in a table. Foreign Key – a field in a table whose values must match a primary key in another table.
Referential Integrity We can define a relationship between two tables. ONE – to – MANY Relationship Primary key Foreign Key
Indexes An INDEX in the back of a book contains important words or phrases (in alphabetical order) together with a list of pages on which the given word or phrase can be found.
Indexes An INDEX on a table in ACCESS is a list of names in alphabetical order and their locations in the table. The INDEX can be constructed on any field, not only on the names. The field on which the index is built is called the index key.
Index An index is used instead of physically sorting the records. An index is automatically created for the primary key of every table.
When should you create an INDEX? Frequent need of sorted data. Frequent searches on that field. Note: updates on an indexed field will be slower since the index must also be updated.