Using Relational Databases and SQL
Steven EmoryDepartment of Computer Science
California State University, Los Angeles
Lecture 1:Introduction to Relational Databases and
MySQL
Database Origin
Database comes from the open compound word “Data Base”
Data Base was a military term (circa 1964)Data Base implies data that is both persistent and shared (think Air Force Base)The military funded much of the research into the early electronic computers of the 40’s and 50’s because of World War II and the Korean War
What is a Database?
A structured collection of persistent data that is typically meant to be sharedUsed to model organizational activitiesStructure is defined through a database modelNo database model, no database!Examples:
Airlines, Banks, Stores and Universities
Database Models
The Two Levels of a Database ModelPhysical Level (how data is stored)
The things we don’t care about
Logical Level (how data is generalized)The things we do care about
The Basic ModelsHierarchical Model (IBM’s IMS)Network Model (CODASYL)Relational Model (ALPHA, SEQUEL)
Physical/Logical Separation
Previous to the relational model, one had to write a program that traversed pointers at the physical level to extract data from a database (think like programming in assembly language)By abstracting the physical level and writing a program at the logical level instead (think like programming in Java), extracting data from a database became easierFirst proposed by Dr. Edgar Frank Codd.
Dr. Edgar F(rank) Codd
MA Mathematics, MA ChemistryMS and PhD in Communication SciencesACM Turing Award (1981)
Relational Model
Proposed by Edgar F. Codd (circa 1969)Database is a collection of tables (relations)Relational comes from ‘Relational Algebra/Calculus’ and not from ‘Relationships’Relational model is very mathematicalDominant database model
Thanks to Larry Ellison, founder of Oracle, who was first to aggressively market a commercial relational database product (Ellison is currently the 4th richest person in the world)
TablesArtists = Table (Relation)ArtistID, City, Region, ... = Columns (Attributes)Each row is called a Record (Tuple)
Data Types
Determines storage requirementsCommon attribute types
StringNumeric (float, double, real)Date and TimeBlobs and Clobs (images and other binary data)
Database Schemas
The definition of the database, where you defineThe name of the databaseTables
Column names, types, and constraints
Relationships between tablesStored functions and procedures
Schemas are typically represented by a schema diagram
Database Schemas
Database Management Systems (DBMS)
Software (programs) to manage databasesCreation/DeletionMaintenance (inserting, updating, and deleting records)Security (encryption, user access control)
Common DBMSsMySQL, PostreSQL (open source)Oracle, DB2, MS SQL Server (commercial)
Database Management Systems (DBMS)
You can have multiple databases, each with a single schema
A separate database for each applicationToystore (First database)Bookstore (Second database)Furniture Store (Third database)Etc.
You can also have a single database, with multiple schemas
DBMS Diagram
Query Languages
Query Language = A language used to extract data from a databaseDomain-Specific Language
Only for databases
HistoryCodd, Alpha (1971)Chamberlin and Boyce, SEQUEL (1974)
Eventually renamed to SQL
QL Examples
Alpha (Codd)
SEQUEL (Chamberlin, Boyce)
SQL
Stands for Structured Query LanguageA non-procedural, domain-specific language (not like C or C++)An open ANSI standardSupported by most major DBMSSome variations in implementationsUsed by programmers, managers, and database administrators
SQL Functions
View information from relational databasesSingle and multiple table selectionsCalculation and analysis
Manipulate information in relational databasesInsert and delete recordsUpdate records
Create relational databasesCreate databases, tables, constraints, ...
Other Interesting Facts
Question: Why is a database always represented by an aluminum can or some type of cylinder?
Other Interesting Facts
Answer: Because that’s what disk storage looked like back in the old days!
Other Interesting Facts
Since IBM already had a database product called IMS, which was currently being used in the Apollo space program (1969 – 1972), Dr. Codd was asked by IBM not to disparage IMS nor promote his model over IMS since it might hurt sales of IMS.Many people to this day believe that hindered IBM and Dr. Codd from making all the money that Larry Ellison of Oracle has made.
Downloading MySQL
Go to CS122 Wiki page and under the Required Software section, click on the links to
MySQL (client and server program)MySQL GUI Tools (alternative client program)MySQL Workbench (schema utility)
Download the versions for Windows, without the installerExtract all three to a flash drive (preferably)
Important Notes!!!
You can put MySQL directly onto these computers, but be aware that other students may delete your stuff (by accident or otherwise)Do not leave homework, labs, or programs on our computers as other students may find and mishandle your stuffAlways back up your work onto a personal flash drive before you leaveDon’t forget your flash drives