Presentation is loading. Please wait.

Presentation is loading. Please wait.

Advanced Web 2012 Lecture 3 Sean Costain 2012. What is a Database? Sean Costain 2012 A database is a structured way of dealing with structured information.

Similar presentations


Presentation on theme: "Advanced Web 2012 Lecture 3 Sean Costain 2012. What is a Database? Sean Costain 2012 A database is a structured way of dealing with structured information."— Presentation transcript:

1 Advanced Web 2012 Lecture 3 Sean Costain 2012

2 What is a Database? Sean Costain 2012 A database is a structured way of dealing with structured information. An organized mechanism for storing, managing and retrieving information. Information is stored in tables Think of a table as a single spreadsheet, a database consists of multiple spreadsheets that can be linked together using a key.

3 Types of Data - Numeric Sean Costain 2012 Tinyint – Use as a boolean Int – Use for uid/id number

4 Types of Data – Numeric cont. Sean Costain 2012 Fixed Point – Decimal, Numeric -Use decimal as numeric defaults to decimal -eg: salary DECIMAL (5,2) Allows for the range -999.99 to 999.99 Floating Point – float, double -Use float - eg: salary FLOAT (7,4) Allows for the range -999.9999 to 999.9999 Floating point rounds numbers, so not exact for storage, stick to using decimal.

5 Types of Data – Date and Time Sean Costain 2012 DATETIME has a supported range is '1000-01-01 00:00:00' to'9999-12-31 23:59:59'. TIMESTAMP has a range of'1970-01-01 00:00:01' UTC to '2038-01-19 03:14:07' UTC. The DATETIME and TIMESTAMP type is used for values that contain both date and time parts. MySQL retrieves and displays DATETIME & TIMESTAMP values in 'YYYY-MM-DD HH:MM:SS' format.

6 Types of Data – Strings Sean Costain 2012 String Types -Char -VarChar -Binary -Varbinary -Blob -Text -Enum -Set The useful String types -Varchar -Blob -Text A varchar can have a set length, eg: varchar(4) means that the field being entered can contain exactly 4 characters. Useful for storing simple data like, M/F, names varchar (60)….

7 Types of Data – Strings Sean Costain 2012 Blobs -Tinyblob -Blob -Mediumblob -Longblob BLOB values are treated as binary strings (byte strings). They have no character set, and sorting and comparison are based on the numeric values of the bytes in column values. Blobs can store images

8 Types of Data – Strings Sean Costain 2012 Text -Tinytext -Text -Mediumtext -Longtext TEXT values are treated as nonbinary strings (character strings). They have a character set, and values are sorted and compared based on the collation of the character set. Text stores … text! (strings)

9 Types of Data – Size Sean Costain 2012

10 Normalisation Sean Costain 2012 Normalisation Rules 1 st Normal Form Eliminate repeating groups Create a table for related data Identify each table with a primary key 2 nd Normal Form Create tables for sets of values that apply to multiple records Relate these tables with a foreign key 3 rd Normal Form Eliminate fields that do not depend on the key Normalization is the process of organizing data in a database. This includes creating tables and establishing relationships between those tables according to rules designed both to protect the data and to make the database more flexible by eliminating redundancy and inconsistent dependency.

11 Normalisation Example Sean Costain 2012 Simple spreadsheet that contains student detail. It works, but sorting by student name or subject would be pretty insane, so we need to normalise the information for storing into a database.

12 Normalisation Example Cont. Sean Costain 2012 Normalisation on data, break it down and add unique identifiers (uid or id) So this is the first breakdown of the data, but it’s not broken down enough yet

13 Normalisation Example Cont. Sean Costain 2012 The address can be broken down further There has to be links to keep the data consistent

14 Normalisation Example Cont. Sean Costain 2012 Table linking – Student to address

15 Normalisation Example Cont. Sean Costain 2012 Table linking – Subject to Date Though a good break down, reality doesn’t always fall into 3 rd Normal form, so you can break the rules.

16 Normalisation Example Cont. Sean Costain 2012 Table linking – Add Student to Subject and Date

17 ERD – Entity Relationship Diagram Sean Costain 2012 Links the tables by Headers

18 ERD – Entity Relationship Diagram Sean Costain 2012 All of the tables shown with linking

19 phpmyAdmin Sean Costain 2012 Creating a Database -Make a user with the correct privileges -Create a database -Add tables to database -Insert data to tables Start by having the web server running, get to the web control via - localhost/phpmyadmin

20 Creating a user Sean Costain 2012 Privileges - Add User

21 Fill in the Blanks Sean Costain 2012 Webservers recognise themselves as localhost

22 Create Database Sean Costain 2012 Start Adding tables

23 Database Fields Sean Costain 2012 Fill in the blanks, such as name, type if it’s auto incrementing and a primary key

24 Database Sean Costain 2012 You should end up with multiple tables for your database


Download ppt "Advanced Web 2012 Lecture 3 Sean Costain 2012. What is a Database? Sean Costain 2012 A database is a structured way of dealing with structured information."

Similar presentations


Ads by Google