Download Database Theory What is a database? A database is a document

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts

Concurrency control wikipedia , lookup

Microsoft Jet Database Engine wikipedia , lookup

Entity–attribute–value model wikipedia , lookup

Database wikipedia , lookup

Extensible Storage Engine wikipedia , lookup

Relational model wikipedia , lookup

Clusterpoint wikipedia , lookup

Database model wikipedia , lookup

Transcript
Database Theory
What is a database?
A database is a document containing large amounts of ordered data. The ‘Yellow
Pages” is an example of a paper based database. With computerisation huge
amounts of data is being stored, which makes finding the data required difficult.
Data is facts and figures. When put together in a meaningful way, it becomes
information. The data in a database is stored in records and fields.
Why use a database





to be able to find information quickly
to allow data to be stored quickly and efficiently
to allow data to be changed easily
to allow data to be sorted into groups easily
to allow data to be presented in a user-friendly format (reports)
quick
searching data is boring and time-consuming for humans, and the
results are prone to error. Computerised databases containing millions of pieces
of data can be searched in milliseconds with an extremely high degree of
accuracy. These searches are often called ‘queries’
Stored
Optical and magnetic media are tiny compared to paper based
records, which in the past could take up a whole room
Changed
People move house, change names, die etc. Data becoming
obsolete or no longer needed applies to many situations. Altering or deleting data
creates no waste and in quicker on a computer.
Sorted
sometimes information is needed in batches instead if individual
records: for example, to find all of the boys over a certain height.
Reports
most databases have built-in features that organize and display
findings in a fashion that is acceptable to non-technical people. Sorted
information and charts are often features of reports
Tables
are a structure for holding a collection of records. Some databases have more
than one table, but for now we will treat any table we use as a database.
Records
The rows into which data is put. All the data on a line of a database
are related.
The table above shows 9 records
Data
Fields
The columns into which data is put. These usually have a
column header at the top which is not included in the
data, which has a sensible descriptive name
The table above shows six Data Fields
primary key
(a field)
if the parents of David Smith of Form 10Gk arrived at a school to take
home David Smith of Form 10Pv, who had been taken ill, there would
probably be two sets of very angry parents and a pupil who was
waiting needlessly. Each record must be unique so that can be no possible
confusion as to who or what is being referred to. Surnames would not be enough
to ensure that there is no question of which record is addressed. This is why the
College has Student_ID. No two Student_IDs are the same, even when the
students have left the College. One way to achieve this easily in a database is
by using auto increment.
Auto-increment
every time a new record is created it has the next available
integer allocated to it in the Auto-increment field.
Field Data type
These are examples of Field data types





Text (also known as Alphanumeric or Character)
Numeric (there are different types)
Date (the style is stipulated)
Yes/No (or True/False)
Enum (the user can choose from certain options only)
Setting the data type in fields is important because:



Certain field types automatically spot errors: eg. Entering 30/2/2011 would
be flagged as an error if it was entered into a Date field
If the field is defined as Currency or Numeric, the user would be stopped
from making certain errors
If calculations are to be performed the field must be Currency, Numeric or
Date.
Limiting the size of the field
There must be enough space to input each piece of data if the table is to be
accurate. But if spaces are left unnecessarily, the search time will be longer.
Therefore the field size should be set to the maximum expected number of
characters
Eg a field called ‘Title’ in a table of members of a club may be limited to 4
spaces, (for ‘Miss’). In the same table, ‘Surname’ may be limited to 20, because
hyphenated names can be quite long. The hyphen does count as a character!
Why not use a spreadsheet?
Spreadsheets can be used as databases if the data is inputted appropriately. But
the facilities of these are limited compared to a database. Spreadsheets are
primarily designed for number operations, not data manipulation.
Questions
1.
Select appropriate Data Type for the following fields:
Primary key
First name
Surname
Title
Address line 1
Address line 2
Town
Country
Date Of Birth
Telephone
Postcode
Email
2.
Choose an appropriate Field Length for each of the fields above.
3.
Which field would you use as the Primary key in MMC?
4.
How would you ensure that your primary key is unique?
5.
What is the purpose of a database?
6.
What is the purpose of a report?
7.
What is the difference between a spreadsheet and a database?
8.
Could you use a spreadsheet as a database?
Setting up a Database in MySql using PhpMyadmin
(PhpMyadmin is a user friendly tool for administrating MySql databases through
a web interface).
In your web browser, Safari, enter this URL
http://php.mmc.school.nz/phpmyadmin/index.php
You should get this log in screen.
Enter your Username and Password and click Go.
You should get this screen. (with your username showing in blue on the left)
If we want to enter this table of students shown below.
It has 6 fields that we need to decide on the data types.
student_id is an Integer field of length 2.
first_name, last_name are varchar (strings) which we will give a length of 30
characters.
gender is an Enum datatype, we give a choice of male or female only. (For the
values write them as ‘male’,’female’
date_of_birth is a Date datatype (YYYY-MM-DD)
house is another Enum datatype, as you can only be in one of four houses. (For
the values write them as 'Hufflepuff','Gryffindor','Ravenclaw','Slytherin'
How to set up our table
In PhpMyadmin click on your username (in blue on the left) and this screen
should appear. (Note: in the example below the username is Jamesbond)
Where it says create a new table on database ………. Click in the Name box and
enter students as the name of the table. Enter 6 for the number of fields and
click Go.
Fill in the screen as shown below.
Note: student_id is the primary key and by ticking A_I it auto increments.
When you click save the following screen is generated. Showing the queries to
set up the structure of the table and the actual structure.
Now click on Insert to input your data from the table given.
Here is a pic of the first record. Note: Only enter data into the Value column and
only fill in the first part and press GO.
Continue adding all the other records in the table.
Credits
73
28
57
94
81
35
66
79
58
31
83
84
88
76
91
13
15
25
71
62
44
For the last 4
records (on the
second page)
79
87
81
46
80
55
55
75
83
81
87
82
65