1 Session 6: Database Best Practice iNET Academy Open Source Web Development.

Slides:



Advertisements
Similar presentations
Kirkwood Center for Continuing Education By Fred McClurg, Introduction to PHP and MySQL Copyright © 2010 All Rights Reserved.
Advertisements

Designing a Database Unleashing the Power of Relational Database Design.
Introduction to Oracle9i: SQL1 Selected Single-Row Functions.
1ISM - © 2010 Houman Younessi Lecture 3 Convener: Houman Younessi Information Systems Spring 2011.
Relational Databases What is a relational database? What would we use one for? What do they look like? How can we describe them? How can you create one?
MS Access 2007 IT User Services - University of Delaware.
Phil Brewster  One of the first steps – identify the proper data types  Decide how data (in columns) should be stored and used.
DATA, DATABASES, AND QUERIES Managing Data in Relational Databases CS1100Microsoft Access - Introduction1.
Chapter 6 Physical Database Design. Introduction The purpose of physical database design is to translate the logical description of data into the technical.
Session 5: Working with MySQL iNET Academy Open Source Web Development.
2.3 Organising Data for Effective Retrieval
With Microsoft Office 2007 Intermediate© 2008 Pearson Prentice Hall1 PowerPoint Presentation to Accompany GO! with Microsoft ® Office 2007 Intermediate.
GIS Concepts ‣ What is a table? What is a table? ‣ Queries on tables Queries on tables ‣ Joining and relating tables Joining and relating tables ‣ Summary.
With Microsoft Access 2007 Volume 1© 2008 Pearson Prentice Hall1 PowerPoint Presentation to Accompany GO! with Microsoft ® Access 2007 Volume 1 Chapter.
Copyright © 2003 by Prentice Hall Module 4 Database Management Systems 1.What is a database? Data hierarchy and data organization Field, record, file,
ASP.NET Programming with C# and SQL Server First Edition
PHP Programming with MySQL Slide 8-1 CHAPTER 8 Working with Databases and MySQL.
1 Lesson 22 Getting Started with Access Essentials Computer Literacy BASICS: A Comprehensive Guide to IC 3, 3 rd Edition Morrison / Wells.
Chapter 1 Overview of Database Concepts Oracle 10g: SQL
Mr. Justin “JET” Turner CSCI 3000 – Fall 2015 CRN Section A – TR 9:30-10:45 CRN – Section B – TR 5:30-6:45.
1 Chapter 1 Overview of Database Concepts. 2 Chapter Objectives Identify the purpose of a database management system (DBMS) Distinguish a field from a.
Concepts and Terminology Introduction to Database.
CHAPTER 8: MANAGING DATA RESOURCES. File Organization Terms Field: group of characters that represent something Record: group of related fields File:
Lecture 2 An Overview of Relational Database IST 318 – DB Admin.
RELATIONSHIPS Generally there are two main database types: flat-file and relational.
INFO 344 Web Tools And Development CK Wang University of Washington Spring 2014.
Chapter 7 Working with Databases and MySQL PHP Programming with MySQL 2 nd Edition.
Chapter 7 Working with Databases and MySQL PHP Programming with MySQL 2 nd Edition.
Chapter 10 Selected Single-Row Functions Oracle 10g: SQL.
Chapter 5 Selected Single-Row Functions. Chapter Objectives  Use the UPPER, LOWER, and INITCAP functions to change the case of field values and character.
Lesson 17 Getting Started with Access Essentials
MS Access: Creating Relational Databases Instructor: Vicki Weidler Assistant: Joaquin Obieta.
Advanced PHP: Using PHP with MySQL C. Daniel Chase The University of Tennessee at Chattanooga.
PHP and MySQL CS How Web Site Architectures Work  User’s browser sends HTTP request.  The request may be a form where the action is to call PHP.
Introduction to Databases Trisha Cummings. What is a database? A database is a tool for collecting and organizing information. Databases can store information.
 Agenda: 4/24/13 o External Data o Discuss data manipulation tools and functions o Discuss data import and linking in Excel o Sorting Data o Date and.
1 Outline  What is a Primary Key?  AutoNumber primary keys  Single-field primary keys  Composite-field primary key  About Foreign Keys  Database.
Chapter 1Introduction to Oracle9i: SQL1 Chapter 1 Overview of Database Concepts.
Oracle 11g: SQL Chapter 10 Selected Single-Row Functions.
Database Beginnings. Scenario so far In our scenario we have people registering for training sessions. –The data about the training sessions was placed.
6 1 Lecture 8: Introduction to Structured Query Language (SQL) J. S. Chou, P.E., Ph.D.
Open Source Server Side Scripting ECA 236 Open Source Server Side Scripting MySQL – Inserting Data.
Access 2007 ® Use Databases How can Microsoft Access 2007 help you structure your database?
Introduction to Database using Microsoft Access 2013 Part 7 November 19, 2014.
Databases,Tables and Forms Access Text by Grauer Chapters 1 & 2.
ITGS Databases.
INFORMATION TECHNOLOGY DATABASE MANAGEMENT. Adding a new field 1Right click the table name and select design view 2Type the field information at the end.
Access Review. Access Access is a database application A database is a collection of records and files organized for a particular purpose Access supports.
Advanced SELECT Queries CS 146. Review: Retrieving Data From a Single Table Syntax: Limitation: Retrieves "raw" data Note the default formats… SELECT.
Database Fundamental & Design by A.Surasit Samaisut Copyrights : All Rights Reserved.
SQL LANGUAGE and Relational Data Model TUTORIAL Prof: Dr. Shu-Ching Chen TA: Hsin-Yu Ha.
Using SQL Connecting, Retrieving Data, Executing SQL Commands, … Svetlin Nakov Technical Trainer Software University
Programming Logic and Design Fourth Edition, Comprehensive Chapter 16 Using Relational Databases.
Quiz questions. 1 A data structure that is made up of fields and records? Table.
Programming with Microsoft Visual Basic 2008 Fourth Edition Chapter Eight String Manipulation.
Lesson 2: Designing a Database and Creating Tables.
Introduction to Databases. What is a database?  A database program is nothing more than an electronic version of a 3x5 card file  A database is defined.
BSA206 Database Management Systems Lecture 2: Introduction to Oracle / Overview of Database Concepts.
A table is a set of data elements (values) that is organized using a model of vertical columns (which are identified by their name) and horizontal rows.
Copyright © 2013 by The McGraw-Hill Companies, Inc. All rights reserved. McGraw-Hill/Irwin APPENDIX C DESIGNING DATABASES APPENDIX C DESIGNING DATABASES.
Understand Relational Database Management Systems Software Development Fundamentals LESSON 6.1.
Database: SQL, MySQL, LINQ and Java DB © by Pearson Education, Inc. All Rights Reserved.
Database (Microsoft Access). Database A database is an organized collection of related data about a specific topic or purpose. Examples of databases include:
1 Section 1 - Introduction to SQL u SQL is an abbreviation for Structured Query Language. u It is generally pronounced “Sequel” u SQL is a unified language.
XP Chapter 1 Succeeding in Business with Microsoft Office Access 2003: A Problem-Solving Approach 1 Level 2 Objectives: Understanding and Creating Table.
Databases.
Chapter 10 Selected Single-Row Functions Oracle 10g: SQL
Database Management  .
Chapter 8 Working with Databases and MySQL
Introduction to SQL Server and the Structure Query Language
Presentation transcript:

1 Session 6: Database Best Practice iNET Academy Open Source Web Development

2 Objectives Relational Databases Normalization and Forms of Normalization Backup and Restore Data Advanced SQL

3 Relational Databases In relational systems, data is spread across several tables. The key is the relation between tables Decision of the primary key is very important in designing database. Foreign key is key (one or more than one field) that acts as the primary key in one table. In other tables, they are normal columns, not the key.

4 Relationship Types One-to-One Relationship Each item is related to one and only one other item.

5 Relationship Types (cont.) One-to-Many Relationships: a key from one table appears multiple times in another table

6 Relationship Types (cont.) Many-to-Many Relationships

7 Normalization Goal: minimize the duplication of data

8 Forms of Normalization - First Normal Form Tables must not have repeating columns that contain the same kind of data All column must containt only one value There must be a primary key that uniquely defines rows

9 First Normal Form (cont.) The Address is splited into street, city, state, zip code

10 Second Normal Form Tables must be in First Normal Form Columns that have repeating values across multiple rows must be placed in separate tables and referenced by a key value in the original table

11 Second Normal Form (cont.)

12 Third Normal Form Remove partial dependence, data that is not fully dependent on the primary key, but dependent on another value in the table.

13 Column Data Types PHP isn’t strongly typed, but most databases are!

14 Backing Up & Restoring Data - Copying Database Files To backup, simple copy all files in the database’s directory. Shutdown the database server before backing up To restore a database, copy all files into the database’s directory. Then, restart the database server Note: File Backup & Restore must consider the problem of multiple versions of database server. Backingup and Restoring on *nix systems must consider the file permissions.

15 Backing Up & Restoring Data – Using mysqldump Command Syntax: mysqldump –u user –p objects_to_backup Backingup a database: mysqldump –u root –p store > my_backup_of_store.sql

16 Backing Up & Restoring Data – Using mysqldump Command (cont.) To backup a table mysqldump –u root –p store authors > authors.sql To backup everything mysqldump –u root –p - -all-databases > my_backup.sql To backup only the structure, not the data mysqldump –u root –p - -no-data store > structure.sql To backup only the data mysqldump –u root –p - -no-create-info store > data.sql

17 Backing Up & Restoring Data – Using mysqldump Command (cont.) Restoring a MySQL backup Restoring a full backup mysql –u root –p < my_backup.sql Restoring a database mysql –u root –p –D store < my_backup.sql Working with other formats: CSV format mysqldump –u root –p - -no-create-info - -tab=/home/jon - -fields-terminated-by=‘,’ store Using mysqlimport command to import data from other formats mysqlimport –u root –p - -fields-terminated-by=‘,’ store books.txt Backup best practice Determine how often to backup based on How critical is your data How often it changes Keep a copy of data in a separate location

18 Advanced SQL Indexes Use to find the data as quick as possible Indexes are used when In a WHERE clause: SELECT * FROM authors WHERE author=‘Ellen Sieve’; the author column should be indexed In an ORDER BY clause: SELECT * FROM contacts ORDER BY author; the author column should be indexed In MIN or MAX clauses How to create the index CREATE UNIQUE INDEX authind ON authors (author);

19 Advanced SQL (cont.) Multicolumn indexes: columns that are likely to be used in the WHERE clause should be indexed LEFT JOIN Clause SELECT fields FROM left_table LEFT JOIN right_table ON left_table.field_id = right_table.field_id GROUP BY Clause SELECT title, COUNT(author_id) FROM books NATURAL JOIN authors GROUP BY title

20 Advanced SQL (cont.) Using Database Functions String Functions: Concatenation Concatenation with a predefined separator

21 Advanced SQL (cont.) String functions Calculate a string length Changing strings to upper- or lowercase

22 Advanced SQL (cont.) String Functions Trimming and padding strings To trim spaces or tabs from a string, use LTRIM or RTRIM To trim spaces or a specified character, use TRIM function TRIM(LEADING ‘X’ FROM string) TRIM(TRAILING ‘X’ FROM string)

23 Advanced SQL (cont.) String Functions String location and position Cutting up strings LEFT RIGHT SUBSTRING

24 Advanced SQL (cont.) String Functions Search and Replace

25 Advanced SQL (cont.) Date and Time Functions

26 Advanced SQL (cont.) Date and Time Functions

27 Advanced SQL (cont.) Date and Time Functions

28 Advanced SQL (cont.) Date and Time Functions

29 Advanced SQL (cont.) Date and Time Functions