You are on page 1of 48

Database

Learning objective
Students will be able to
• Define Flat file Database and Relational Database
• Create a data base in MS access
• Create report, data entry forms , queries and Labels in MS Access
Database
• Database – Organised collection of data
• Field - column
• Record – Row . Collection of fields
• File - Collection of records
• 2 types of Database
• Flat file Database
• Relational Database
Flat file Database
• Store data in one file
Relational Database
• Store data in more than one linked table
• Same data is not stored many times
• Each table must have keys
• Primary key
• A primary key is used to ensure data in the specific column is unique.
• It cannot have NULL values.
• Only one primary key is allowed in a table.
• Foreign key
• It points to primary key of another table
• More than one foreign key is allowed
STUD_NO in STUDENT_COURSE is a foreign key to STUD_NO in STUDENT table.
Benefits of relational database
• Flexible to make changes
• Reduce redundancy
• Ease of backup and disaster recovery
• Save storage space
Data types
• Alphanumeric ( text / number)
• Numeric
• Integer
• Decimal
• Currency
• Date and time
• Boolean
etc…
Create a flat file database from an existing
file

From the dialogue box we can set column names, data types, etc.
To add a new column to table
Creating relationship between tables
• Database tools  Relationships
Create a data entry form
• Create  Form wizard

• In the dialogue box we can select columns, give name to forms, etc..
Different Form views
Queries
Queries
• To search or manipulate data
• It select a subset of data from table
• Create  Query wizard

• From this dialogue box we can select columns, give name to query, etc.
Click on “Run” to execute Query
In bottom section we can set criteria and can add new columns
Different Query views
Query Criteria
• Query criteria helps you to retrieve specific items from database.
• If an item matches with all the criteria you enter, it appears in the
query results.
Formulae and Arithmetic operations
Mark: [Score]/60
• To set the “Mark” column value to “Score / 60”
• To set “Current_Salary” column to
Value in “Basic_Pay” column + [ Value in “Year_Service” column * 400 ]

• Profit column value = Sprice column value – Pprice column value


Arithmetic operations
• Mark: [Score] + 60
• Mark: [Score] - 60
• Mark: [Score] * 60
• Mark: [Score] / 60
Grouping and Subtotal
• Select the data
• Go to “Report Layout design”. Under that we can find Grouping and Subtotal
Sorting of Data
Data validation
Data validation
• ‘Validation’ control the user’s input in the table
• It ensure the data entered by the use is appropriate
• ‘Validation rule’ for preventing data entry error
• Display error messages in case of invalid data entry
• 2 types of validation
1. Field Validation Rule
2. Record Validation Rule
1. Field Validation Rule
• To check the value that you enter in a field when you leave the field.
Examples :

• Disallow date values in the past: >=Date()

• Generally accepted email format: Is Null OR ((Like "*?@?*.?*") AND (Not Like
"*[ ,;]*"))

• Number less than or equal to five: <=5

• Currency field can't be negative: >=0

• Restrict character length in string: Len([StringFieldName])<100


2. Record Validation Rule
• To specify a condition that all valid records must satisfy.
• We can compare values across different fields using a record validation rule
• Eg:
Ensure the end date doesn't come before the start date:
[End Date]>=[Start Date]
Access provides a number of ways to restrict input:
• Data types: Restrict data type that, what users can enter.
• Eg: Date/Time field accepts only dates and times
• Currency field accepts only monetary data.
• Field properties: To restrict data input.
• Eg: Field Size property of a field restricts input by limiting the amount of data.
• Input masks: To force the users to enter values in a specific way.
• Eg: an input mask can force users to enter dates in a European format, such as
2007.04.14.
Report
Report
• To present data
• Create  Report wizard

• Here we can select the columns required in report creation


• Here we can sort the report
based on column values

• Here we can set page layout


Layout view of report

Different Views of report Design view of report


• Page header
• Shown on top of every page
• Page footer
• Shown on every bottom of page
• Report header
• It appears at the start of the report
• Report footer
• It appears at the end of the report
Export data
• To export data in report or queries to other software packages
Hide data in report
• To hide some in report
• In property sheet go to “Visible” and set it as “No”
Labels
Labels
• Labels are for advertising products
• Address labels for mailing letters to customers
• Create  Labels
• Here we can set the “label size”

• We can format the label content


• Select the required columns that
need to be shown on the label

• Select a column to sort the label


• Give a name to Label
• Click “Finish”
AFL
• Differentiate between flat file database and relational database.
• Define the following terms
I. Query
II. Report
III. Label
• List the different types of “Data validation” in MS access with example.

You might also like