Database Fred Durao
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: Clients Staff Volunteers To keep a record of activities and interventions; Keep sales records; Develop reports; Perform research Longitudinal tracking
Database management system (DBMS) Software Programs which capable to: store, modify delete ask questions (or queries) about the data stored in the database and produce reports summarizing 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 CPRNAMEAGE FRED THOMAS ULLA34 TABLE TEACHER CPR is the primary key of table teacher
CPRNAMEAGE FRED THOMAS ULLA34 TABLE TEACHER COURSE IDCOURSE_NAMECPR 111 WEB DESIGN SPANISH ENGLISH TABLE COURSE CPR is the COLUMN/FIELD which relates both tables Why Relational Databases?
MySql – A OpenSource Database 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
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_name 1 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( , 'JOHN', 17); INSERT INTO TEACHER(CPR,NAME,AGE)VALUES( , 'FRED', 24); INSERT INTO TEACHER(CPR,NAME,AGE)VALUES( , '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_name 1 = value 1 WHERE col_name = value Ex: UPDATE TEACHER SET AGE=23 where CPR = ; 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