Presentation is loading. Please wait.

Presentation is loading. Please wait.

Creating a database table

Similar presentations


Presentation on theme: "Creating a database table"— Presentation transcript:

1 Creating a database table
Database development

2 Learning objectives Design a database table
Create the database structure Use suitable field types including numbers and text Add validations and validation text to at least one field Add records to the table and test the validations

3 Tables, records and fields
Data in a database is stored in tables Tables have rows and columns How many fields are there in each record? What type of data is held in each field? (e.g. text, integer, etc.)

4 Primary key Each record may have a unique identifier, called the primary key Which field is the primary key field? Think of another field which could replace Car ID as a primary key for this table

5 Database structure A table should relate to a single “entity” – person or thing When you create a new table, you specify the name and data type of each field Choosing the correct field type is important! You can add validation rules and masks to some of the fields

6 A sample database application
A national newspaper is running a Young Writer Short Story Competition, which will be judged by a famous author of children’s books. There are two categories; Category 1 for writers aged 11-14, and Category 2 for writers 15-17 Prizes will be awarded in each category and the schools which the winners attend will also receive books for the school library A database needs to be designed to hold the details of pupils entering the competition

7 Database structure A first attempt at designing a database table is shown below How many entities are involved? What are the weaknesses of this table structure?

8 A Relational Database When more than one entity is involved, each entity needs its own table The tables have to link to each other using a common field There are three types of relationship – one-to-one, one-to-many and many to many

9 Two related tables What is the relationship between the School table and the Pupil table shown below? Which field links the two tables?

10 Design your own database!
Choose an idea that involves a single table or two tables linked together in a one-to-many relationship Pay attention to field types when you create the table structure Common field types include text, number (integer or decimal), date/time, currency, Yes/No Choosing Lookup wizard allows you to specify valid entries, e.g. “M”, “F”

11 Validation Range check Length check Presence check Type check
Format check or Input Mask

12 Data validation In the Field Properties box, add a Validation rule to some of your fields Use operators >, <, >=, <=, = or <> on numeric fields to specify a valid range Use the Lookup wizard if there are only a few valid possibilities for a field In the Validation Text box, add a message that will be displayed if the user tries to make an invalid entry

13 Testing Save your table Change to Datasheet view Enter several records
Make sure you test out all your validations Edit the table structure if you need to by returning to Design View

14


Download ppt "Creating a database table"

Similar presentations


Ads by Google