18
Database Fred Durao [email protected]

Database Fred Durao [email protected]. What is a database? A database is any organized collection of data. Some examples of databases you may encounter in

Embed Size (px)

Citation preview

Database

Fred [email protected]

What is a database?A database is any organized collection of data.

Some examples of databases you may encounter in your daily life are:

a telephone book T.V. Guide airline reservation system papers in your filing cabinet files on your computer hard drive. 

Why do we need a database?Keep records of our:

ClientsStaffVolunteers

To keep a record of activities and interventions;

Keep sales records;Develop reports;Perform researchLongitudinal tracking

Database management system (DBMS)Software Programs which capable to:store,modifydeleteask questions (or queries) about the data stored in the database and produce

reportssummarizing selected contents.

Examples: MS/Access, FileMaker, Lotus Notes, Oracle, SQL Server and MySQL

Tables comprise the fundamental building blocks of any database.  If you're familiar with spreadsheets, you'll find database tables extremely similar. 

The table above contains the employee information for our organization -- characteristics like name, date of birth and title. 

Fundamental building blocks

- A relational database is a collection of tables of data, each of which has one special column that stores the primary keys of the table -The rows are the input values for each column, sometimes called entities;

- Usually tables contain PRIMARY KEY, which uniquely identify each row in a table.

Relational Databases

CPR NAME AGE

1710813015 FRED 90

1410481015 THOMAS 34

0545413015 ULLA 34

TABLE TEACHER

CPR is the primary key of table teacher

CPR NAME AGE

1710813015 FRED 90

1410481015 THOMAS 34

0545413015 ULLA 34

TABLE TEACHER

COURSE ID COURSE_NAME

CPR

111 WEB DESIGN 1710813015

222 SPANISH 1410481015

333 ENGLISH 0545413015

TABLE COURSE

CPR is the COLUMN/FIELD which relates both tables

• A relational database management system (RDBMS) that runs as a server providing multi-user access to a number of databases.

• MySQL is a popular choice of database for use in web applications.

• PHP based application, for instance can access MySQL to maintain data.

• MySQL provides a User Interface Application called MySQL Workbench.

• Users can visualize and manipulate data though MySQL Workbench.

Starting MySQL Workbench in your Windows Machine:

START -> Programs -> MySQL -> MySQL Workbench

(1) Click to open a connection

(2) Enter your credentials

-A standard language to create, query, and modify relational databases

-More like structured English than a programming language

-We will cover only six basic commands:

-CREATE TABLE,- SELECT,- INSERT,- UPDATE,- DELETE, and -DROP

SQL - Structured Query Language

- To create a database

- General form:

CREATE DATABASE database_name

EX: CREATE DATABASE web;

Hint: IF working on the same database use sql command:

Use database_name

EX: USE WEB;

The CREATE DATABASE Command

- To create tables in the database

- General form:

CREATE TABLE table_name ( column_name1 data_type constraints )

EX:

CREATE TABLE `teacher` ( `cpr` INT NOT NULL PRIMARY KEY, `name` VARCHAR(45), `age` INT );

The CREATE TABLE Command

- Used to insert data into the table

- Three clauses: SELECT, FROM, and WHERE

- General form:

INSERT INTO table name (column names ) VALUES (values) - The correspondence between column names and values is positional

EX:INSERT INTO TEACHER(CPR,NAME,AGE)VALUES(1710718736, 'JOHN', 17);

INSERT INTO TEACHER(CPR,NAME,AGE)VALUES(1710811981, 'FRED', 24);

INSERT INTO TEACHER(CPR,NAME,AGE)VALUES(1230718736, 'ULLA', 35);

The INSERT Command

- Used to specify queries

- Three clauses: SELECT, FROM, and WHERE

- General form:

SELECT column names FROM table name WHERE condition

Ex: SELECT name FROM TEACHER;

Ex: SELECT name FROM TEACHER WHERE age > 20;

The SELECT Command

- To change/update/modify one or more values of a row in a table

- General form:

UPDATE table_name SET col_name1 = value1 WHERE col_name = value

Ex: UPDATE TEACHER SET AGE=23 where CPR = 1230718736;

The UPDATE Command

- To delete one or more values of a row in a table

- General form:

DELETE FROM table name where condition

- The WHERE clause could specify more than one row of the table

EX: DELETE FROM TEACHER WHERE NAME = 'FRED';

The DELETE Command

-To drop a table in the database

- General form:

DROP TABLE table_name

EX: DROP TABLE TEACHER

The DROP TABLE Command

- To drop a existing database

- General form:

DROP database_name

EX: DROP DATABASE WEB;

The DROP DATABASE Command