8
A non-violent introduction to Relational Databases (part 1) 1. Introduction to Relational Databases 2. Fundamentals of Relational Databases 3. Using Relational Databases (SQL) 4. Using Relational Databases (DBI) 5. Designing Relational Databases

A non-violent introduction to Relational Databases (part 1)

  • Upload
    others

  • View
    3

  • Download
    0

Embed Size (px)

Citation preview

Page 1: A non-violent introduction to Relational Databases (part 1)

A non-violent introduction to Relational Databases

(part 1)

1.  Introduction to Relational Databases 2.  Fundamentals of Relational Databases 3.  Using Relational Databases (SQL) 4.  Using Relational Databases (DBI) 5.  Designing Relational Databases

Page 2: A non-violent introduction to Relational Databases (part 1)

1.  Introduction to Relational Databases 2.  Fundamentals of Relational Databases 3.  Using Relational Databases 4.  Using Relational Databases 5.  Designing Relational Databases

Databases n  Databases are everywhere

n  Bank account data n  Hospital patient data n  University student course data n  Video Rental store customer data n  Biology

n  Experimental: (microArray, Mass Spec, Shotgun sequencing ) n  Genomic: (Genbank, SwissProt, PIR, PlasmoDB, etc.) n  Used to organize lab data (R, SQLITE, etc.)

Page 3: A non-violent introduction to Relational Databases (part 1)

Database models n  Common Database models

n  Tabular (flat-file) - data in a single table or an especially formatted

text file n  Hierarchical -- data structured into a tree (e.g. a file system) n  Relational -- set of tables, n  Logic-based -- suited to the representation of knowledge n  Object-oriented --

n  The relational model is the most widely used (~90%) n  Relational algebra invented by E.F. Codd at IBM

"A relational model of data for large shared data banks” , Communications of the ACM (1970)

Some history

n  1970’s – 1985 -- PIR protein database and Los Alamos GenBank distributed as “flat files”

n  ~1990, NCBI takes over GenBank and migrates to relational model (Sybase)

n  ~1991 (human) Genome Database (GDB, Sybase) at JHU, now at www.gdb.org)

n  ~1993 Mouse Genome Database (MGD) at informatics.jax.org n  Major public databases, e.g. GenBank, EMBL, Uniprot, PIR,

ENSEMBL etc. are all relational

Page 4: A non-violent introduction to Relational Databases (part 1)

Relational Database Management Systems (RDBMS)

n  A software layer between the actual databases and the users n  Typically a client/server model n  Typically, a RDBMS manages several databases n  An RDBMS provides the following facilities

§  A high-level query language (e.g. SQL) §  Integrity-checking to detect invalid updates §  Security by limiting access §  Backup and recovery from crashes §  Concurrency control so users don�t stomp on each other�s data

n  Commonly used RDBMS n  Oracle, Sybase, IBM, Informix, CA-Ingres, Microsoft Access, PostgreSQL,

MySQL and SQLITE n  MySQL, PostgreSQL and SQLITE are open source systems

n  We will focus on SQLITE and MySQL

1.  Introduction to Relational Databases 2.  Fundamentals of Relational Databases 3.  Using Relational Databases (SQL) 4.  Using Relational Databases (DBI) 5.  Designing Relational Databases

Page 5: A non-violent introduction to Relational Databases (part 1)

What�s the main idea? n  A relational database is a collection of tables

ID name course grade

92918 Peterson BioComputing I A

71665 Smith BioComputing I A

18374 Wing Intro. Biochemistry B

99378 Fernandez MMI Lab Rotation I

37262 Wald Relativistic Quantum Field Theory D

table (relation)

heading, (schema)

rows, (tuples, instances)

columns (fields, attributes) Unique ID (key)

Basic operations (Relational Algebra)

n  Restriction (remove rows) n  Projection (remove columns) n  Rename (an attribute) n  Set Difference n  Set Union n  Cartesian (outer) product n  Join (inner) product

Page 6: A non-violent introduction to Relational Databases (part 1)

The walton database with SQLITE

mkdir ~/exampledb cd ~/exampledb DBDIR=/users/sph140636/shared/code_examples/15_databases/walton_demo cp $DBDIR/walton . sqlite3 walton https://www.cheatography.com/richardjh/cheat-sheets/sqlite3/pdf sqlite3 walton .tables .schema EMPLOYEE select * from EMPLOYEE where JOB = ‘CLERK’ <cntl> -d

1.  Introduction to Relational Databases 2.  Fundamentals of Relational Databases 3.  Using Relational Databases (SQL) 4.  Using Relational Databases (DBI) 5.  Designing Relational Databases

Page 7: A non-violent introduction to Relational Databases (part 1)

SQL

n  Structured Query Language (SQL) is used for relational database �programming.�

n  First implemented at IBM n  it is alleged that SQL is the most commonly used

programming language in the world n  SQL is a declarative language, i.e. describes

what is wanted rather than how to obtain it.

n  SQL is essentially divided into two sublanguages n  Data Manipulation Language (DML) n  Data Definition Language (DDL)

n  We will focus on DML in this course n  SELECT

SQL: a little formality

n  SQL implements a so-called relational algebra n  Set operators: Union, Intersection, Difference,

Cartesian product n  Relational Operators: Restrict, Project, Join, Divide

n  Operators in the algebra have the property of closure, i.e. the input to the operators is a table (a relation) AND the output of the operators is another table.

Page 8: A non-violent introduction to Relational Databases (part 1)