Title: Credentials Presentation
1 Introduction to Database Design and Programming
2Objectives
- In this lesson, you will learn
- To understand the relational database model.
- To be able to write database queries using SQL
(Structured Query Language). - To understand the MySQL database server.
- To learn various database interfaces.
3Introduction
- Database
- Integrated collection of data
- Database management system (DBMS)?
- Store and organize data consistent with
databases format - Relational database
- SQL (Structured Query Language)?
- Queries
- Manipulate data
4Relational Database Model
- Composed of tables
- Row
- Composed of column
- Primary key
- Reference data in the table
- A column or set of columns in table contains
unique data
5Relational Database Model
Relational database structure of an student table.
6Relational Database Model
id
lastname
23603
Hadad
24568
Harris
34589
Hilliers
Table formed by selecting id and lastname data
from the Students table.
7Relational Database Overview
- Primary key uniquely identifies each row
- Rule of Entity Integrity
- Lines connecting tables
- Relationships
- One-to-many relationship (most common)?
- Many-to-many (may indicate complex data)?
- One-to-one (usually extra info on another table)?
- Foreign key
- Join multiple tables
- Rule of Referential Integrity
- The referential integrity rule states that if a
relational table has a foreign key, then every
value of the foreign key must either be null or
match the values in the relational table in which
that foreign key is a primary key.
8Relational Database Overview
9Relational Database Overview
10Relational Database Overview Photo gallery
Database
11Relational Database Overview Photo gallery
Database
12Relational Database Overview Photo gallery
Database
13Relational Database Overview Photo gallery
Database
1422.3 Relational Database Overview Books.mdb
Database
Fig. 22.11 Table relationships in Books.mdb.
15SQL (Structured Query Language)
16Basic SELECT Query
- SELECT FROM tableName
- SELECT FROM photos
- SELECT photographerID, lastName FROM
photographers
17Basic SELECT Query
18WHERE Clause
- Specify selection criteria for query
- SELECT columnName1, columnName2, FROM tableName
WHERE criteria - SELECT photoID, name, description FROM photos
WHERE photographer Brian Ferry
19WHERE Clause
20WHERE Clause
21WHERE Clause
22ORDER BY Clause
- Arranged in ascending or descending order
- SELECT columnName1, columnName2, FROM tableName
ORDER BY column ASC - SELECT photographerID, firstName, lastName FROM
photographers ORDER BY lastName ASC - SELECT columnName1, columnName2, FROM tableName
ORDER BY column DESC - SELECT photographerID, firstName, lastName FROM
photographers ORDER BY lastName DESC
23INSERT Statement
- Inserts new row in table
- INSERT INTO tableName ( columnName1, columnName2,
, columnNameN ) VALUES ( value1 , value2, ,
valueN )?
24UPDATE Statement
- Modifies data in a table
- UPDATE tableName SET columnName1 value1,
columnName2 value2, , columnNameN valueN
WHERE criteria
25DELETE Statement
- Removes data from a table
- DELETE FROM tableName WHERE criteria
26CREATE Statement
- Creates a new table
- CREATE TABLE databaseName.books
- (ID VARCHAR( 10 ) NOT NULL ,
- title VARCHAR( 100 ) NOT NULL ,
- publisher VARCHAR( 50 ) NOT NULL ,
- price DOUBLE NOT NULL ,
- studentId INT NULL ,
- PRIMARY KEY ( isbn ) )?
27INSERT Statement
- Creates a new table
- INSERT INTO greenjay_tutorial.books (
- isbn, title, publisher, price,
studentId - )VALUES (
- '059610197X', 'Head First HTML with CSS XHTML
', 'O''Reilly Media, Inc.', '39.95', NULL - )?
28Interfacing with a database
- Seven languages that interface to database
modules - MySQL
- PostgreSQL
- Microsoft SQL Server
- Oracle
- Sybase
- FrontBase
- ODBC (Open Database Connectivity)?
29MySQL
- Multi-user and multi-threaded RDBMS server
- Uses SQL to interact with and manipulate data
- Supports various programming languages
- Access tables from different databases
- Handle large databases
30Database access and php
- We use a set of php functions to talk to the DB
- mysql_connect("db_location", "login",
"password") - mysql_error()?
- mysql_select_db("db_name", connection)?
- mysql_query("SELECT FROM students")?
- mysql_fetch_array(result_students)?
- mysql_close(connection)?
- We can then use a loop to go through each row of
the database results - This loop can then print out html around the
variables that we get from the MySQL results
31Web Resources
- www.sql.org
- www.mysql.com
- www.microsoft.com/sql
- www.microsoft.com/sql/downloads/default.asp
- www.postgresql.org
- www.interbase.com
- www.maverick-dbms.org
- www.devshed.com
- www.cql.com
- leap.sourceforge.net
- www.voicenet.com/gray/Home.html
- msdn.microsoft.com/library/devprods/vs6/vstudio/md
ac200/mdac3sc7.htm - www.w3schools.com/sql
- www.sqlmag.com