Introduction to Databases CIS 5.2. Where would you find info about yourself stored in a computer?...
-
date post
21-Dec-2015 -
Category
Documents
-
view
213 -
download
0
Transcript of Introduction to Databases CIS 5.2. Where would you find info about yourself stored in a computer?...
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 DatabaseSTUDENT Table:
COURSE Table:
GRADE_REPORT Table: StudentNumber SectionIdentifier Grade 17 112 B 17 119 C 8 85 A 8 92 A 8 102 B 8 135 A
PREREQUISITE Table: CourseNumber PrerequisiteNumber CIS22 CIS15 MAT240 MAT140 CIS72 CIS71
Name StudentNumber Class Major Smith 17 1 CIS Brown 8 2 MATH
CourseName CourseNumber CreditHours Department Intro to Computer Science CIS1.1 3 CIS Data Structures CIS22 4 CIS Discrete Mathematics MAT240 3 MATH Databases CIS72 3 CIS
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 ACCESS2. 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
• Each table must have a primary key which is a unique unique identifieridentifier 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.