Relational Databases: Basic Concepts BCHB524 2014 Lecture 21 11/12/2014BCHB524 - 2014 - Edwards.

Slides:



Advertisements
Similar presentations
Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 15 Introduction to Rails.
Advertisements

XP Chapter 3 Succeeding in Business with Microsoft Office Access 2003: A Problem-Solving Approach 1 Analyzing Data For Effective Decision Making.
Introduction to Structured Query Language (SQL)
Introduction to Structured Query Language (SQL)
Attribute databases. GIS Definition Diagram Output Query Results.
1 Chapter 2 Reviewing Tables and Queries. 2 Chapter Objectives Identify the steps required to develop an Access application Specify the characteristics.
Concepts of Database Management Sixth Edition
Relational Databases: Object Relational Mappers - SQLObject BCHB Lecture 22 11/14/2014BCHB Edwards.
Web-Applications: TurboGears II BCHB Lecture 26 12/03/2014BCHB Edwards.
CSCI 6962: Server-side Design and Programming
Relational Databases: Object Relational Mappers – SQLObject II BCHB Lecture 23 11/20/2013BCHB Edwards.
ASP.NET Programming with C# and SQL Server First Edition
Introduction to SQL Steve Perry
Mr. Justin “JET” Turner CSCI 3000 – Fall 2015 CRN Section A – TR 9:30-10:45 CRN – Section B – TR 5:30-6:45.
Databases. Database A database is an organized collection of related data.
Lecture Set 14 B new Introduction to Databases - Database Processing: The Connected Model (Using DataReaders)
INFO 344 Web Tools And Development CK Wang University of Washington Spring 2014.
Analyzing Data For Effective Decision Making Chapter 3.
CHAPTER:14 Simple Queries in SQL Prepared By Prepared By : VINAY ALEXANDER ( विनय अलेक्सजेंड़र ) PGT(CS),KV JHAGRAKHAND.
CSC 405: Web Application And Engineering II7.1 Database Programming with SQL Aggregation and grouping with GROUP BY Aggregation and grouping with GROUP.
Using Special Operators (LIKE and IN)
Concepts of Database Management Seventh Edition
7 1 Chapter 7 Introduction to Structured Query Language (SQL) Database Systems: Design, Implementation, and Management, Seventh Edition, Rob and Coronel.
Database Design and Management CPTG /23/2015Chapter 12 of 38 Functions of a Database Store data Store data School: student records, class schedules,
6 1 Lecture 8: Introduction to Structured Query Language (SQL) J. S. Chou, P.E., Ph.D.
Lecture Set 14 B new Introduction to Databases - Database Processing: The Connected Model (Using DataReaders)
Database Systems Design, Implementation, and Management Coronel | Morris 11e ©2015 Cengage Learning. All Rights Reserved. May not be scanned, copied or.
Course FAQ’s I do not have any knowledge on SQL concepts or Database Testing. Will this course helps me to get through all the concepts? What kind of.
Using SQL Connecting, Retrieving Data, Executing SQL Commands, … Svetlin Nakov Technical Trainer Software University
9/28/2015BCHB Edwards Basic Python Review BCHB Lecture 8.
Concepts of Database Management Seventh Edition Chapter 3 The Relational Model 2: SQL.
ITEC 3220A Using and Designing Database Systems Instructor: Prof. Z. Yang Course Website: 3220a.htm
SqlExam1Review.ppt EXAM - 1. SQL stands for -- Structured Query Language Putting a manual database on a computer ensures? Data is more current Data is.
Databases and ADO.NET Programming Right from the Start with Visual Basic.NET 1/e 11.
Relational Databases: Basic Concepts BCHB Lecture 21 By Edwards & Li Slides:
Microsoft Access Database Creation and Management.
Web-Applications: TurboGears II BCHB Lecture 26 12/7/2015BCHB Edwards.
Web-Applications: TurboGears BCHB Lecture 25 12/02/2015BCHB Edwards.
IS6146 Databases for Management Information Systems Lecture 1: Introduction to IS6146 Rob Gleasure robgleasure.com.
9/2/2015BCHB Edwards Introduction to Python BCHB524 Lecture 1.
DAY 18: MICROSOFT ACCESS – CHAPTER 3 CONTD. Akhila Kondai October 21, 2013.
Relational Databases and MySQL. Relational Databases Relational databases model data by storing rows and columns in tables. The power of the relational.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 14 Web Database Programming Using PHP.
7 1 Database Systems: Design, Implementation, & Management, 7 th Edition, Rob & Coronel 7.6 Advanced Select Queries SQL provides useful functions that.
LM 5 Introduction to SQL MISM 4135 Instructor: Dr. Lei Li.
1 Section 1 - Introduction to SQL u SQL is an abbreviation for Structured Query Language. u It is generally pronounced “Sequel” u SQL is a unified language.
Introduction to Database Programming with Python Gary Stewart
Marketing Analytics: Database Query with MySQL Disclaimer: All logos, photos, etc. used in this presentation are the property of their respective copyright.
Chapter 12 Introducing Databases. Objectives What a database is and which databases are typically used with ASP.NET pages What SQL is, how it looks, and.
Relational Databases: Basic Concepts
Introduction to Python
Design Patterns for SSIS Performance
Web-Applications: TurboGears
Relational Databases: Object Relational Mappers - SQLObject
Introduction to Python
ISC440: Web Programming 2 Server-side Scripting PHP 3
Basic Python Review BCHB524 Lecture 8 BCHB524 - Edwards.
SQL DATA CONSTRAINTS.
Relational Databases: Object Relational Mappers – SQLObject II
Relational Databases: Basic Concepts
Relational Databases: Object Relational Mappers - SQLObject
Relational Databases: Basic Concepts
Basic Python Review BCHB524 Lecture 8 BCHB524 - Edwards.
Charles Severance Single Table SQL.
Relational Databases: Object Relational Mappers – SQLObject II
Introduction to Python
Relational Databases: Object Relational Mappers – SQLObject II
SQL Basics BCHB697.
Relational Databases: Object Relational Mappers - SQLObject
Indexes and Performance
Presentation transcript:

Relational Databases: Basic Concepts BCHB Lecture 21 11/12/2014BCHB Edwards

11/12/2014BCHB Edwards2 Outline What is a (relational) database? When are relational databases used? Commonly used database management systems Using existing databases Creating and populating new databases Python and relational databases Exercises

11/12/2014BCHB Edwards3 (Relational) Databases Databases store information Bioinformatics has lots of file-based information: FASTA sequence databases Genbank format sequences Store sequence, annotation, references, annotation Good as archive or comprehensive reference Poor for a few items Relational databases also store information Good for a few items at a time Flexible on which items

11/12/2014BCHB Edwards4 Relational Databases Store information in a table Rows represent items Columns represent items' properties or attributes NameContinentRegionSurface AreaPopulationGNP BrazilSouth America IndonesiaAsiaSoutheast Asia IndiaAsiaSouthern and Central Asia ChinaAsiaEastern Asia PakistanAsiaSouthern and Central Asia United StatesNorth America

11/12/2014BCHB Edwards5 Relational Databases Tables can be millions of rows Can access a few rows fast Countries more than 100,000,000 in population? Countries on the “Asia” continent? Countries that start with “U”? Countries with GNP = NameContinentRegionSurface AreaPopulationGNP BrazilSouth America IndonesiaAsiaSoutheast Asia IndiaAsiaSouthern and Central Asia ChinaAsiaEastern Asia PakistanAsiaSouthern and Central Asia United StatesNorth America

11/12/2014BCHB Edwards6 When are Relational Databases Used? LARGE datasets Does data fit in memory? Store data first ask questions later Lookup or sort by many keys For single key, simple data structures often work Store results of expensive compute or data-cleanup Compute once and return results many times "Random" or unknown access patterns Specialized data-structures not appropriate Use string/sequence indexes for sequence data

11/12/2014BCHB Edwards7 Common DBMS Oracle Commercial, market leader, widely used in businesses MySQL Free, open-source, widely used in bioinformatics, suitable for large scale deployment Sqlite Free, open-source, minimal installation requirements, no users, suitable for small scale deployment

11/12/2014BCHB Edwards8 Lets look at some examples We'll use a third-party program to "look at" Sqlite databases: SqliteStudio (Linux), SqliteSpy (Windows), … Download examples: World.db3, taxa.db3 from Course data folder Use SqliteStudio to look at examples World.db3, taxa.db3

11/12/2014BCHB Edwards9 Using existing databases Use the "select" SQL command to find relevant rows select * from Country where Population > ; select * from Country where Continent = 'Asia'; select * from Country where Name like 'U%'; select * from Country where GNP = ; Each command ends in semicolon ";". "where" specifies the condition/constraint/rule. "*" asks for all attributes from the relevant rows. Lets experiment with world and taxa databases.

11/12/2014BCHB Edwards10 Using existing databases Select can combine (“join”) multiple tables Use the where condition to match rows from each table and “link” corresponding rows… select * from taxonomy, name where taxonomy.rank = 'species' and name.name_class = 'misspelling' and name.tax_id = taxonomy.tax_id

11/12/2014BCHB Edwards11 Using existing databases Select can sort and/or return top 10 select * from taxonomy limit 10; select * from taxonomy order by scientific_name; select * from taxonomy order by tax_id desc limit 10;

11/12/2014BCHB Edwards12 Using existing databases Select can count and do string matching. "like" uses special symbols: % matches zero or more symbols _ match exactly one symbol Some RDBMS support regular expressions MySQL, for example. select count(*) from taxonomy where scientific_name like 'D%';

11/12/2014BCHB Edwards13 Creating databases Use the "create" SQL command to create tables CREATE TABLE taxonomy ( tax_id INTEGER PRIMARY KEY, scientific_name TEXT, rank TEXT, parent_id INT ); CREATE TABLE name ( id INTEGER PRIMARY KEY, tax_id INT, name TEXT, name_class TEXT );

11/12/2014BCHB Edwards14 Populating databases Use the "insert" SQL command to add rows to tables Usually, the special id column is initialized automatically INSERT INTO name (tax_id,name,name_class) VALUES (9606,'H. sapiens','synonym'); SELECT * from name where tax_id = 9606;

11/12/2014BCHB Edwards15 Python and Relational Databases Issue select statements from python and iterate through the results Sometimes it is easiest to make Python do some of the work! import sqlite3 conn = sqlite3.connect('taxa.db3') c = conn.cursor() c.execute(""" select * from name where name like 'D%' limit 10; """) for row in c: print row

11/12/2014BCHB Edwards16 Python and Relational Databases Use parameter substitution for run-time values import sys import sqlite3 tid = int(sys.argv[1]) conn = sqlite3.connect('taxa.db3') params = [tid,'scientific name'] c = conn.cursor() c.execute(""" select * from name where tax_id = ? and name_class = ?; """,params) for row in c: print row

11/12/2014BCHB Edwards17 Next-time: Object-relational mappers Setup python to treat tables as classes, rows as objects # Set up data-model from model import * hs = Taxonomy.get(9606) for n in hs.names: print n.name, "|", n.nameClass condition = Name.q.name.startswith('Da') for n in Name.select(condition): print n.name, "|", n.nameClass

11/12/2014BCHB Edwards18 Lab exercises Read through an online course in SQL sqlcourse.com, sql-tutorial.net,... Write a python program to lookup the scientific name for a user-supplied organism name.