CSC 120 Worksheet 12 Databases

Size: px
Start display at page:

Download "CSC 120 Worksheet 12 Databases"

Transcription

1 CSC 120 Worksheet 12 Databases 1 Format for SQLite Commands We will create tables and retrieve data from the tables using Python and SQLite. You can find a list of Python and SQLite commands at the end of this handout as well as the tables we will use as examples. You may even find it helpful to pull it o so that you can have it at your side. As always, to get more/better information on what is available to you, browse the documentation! 2 Creating Tables Let s write a function to read in a file and populate the table Precipitation that we saw earlier. def create_precipitation(db, data_file): (str, file open for reading) -> NoneType Populate the database with name/path db with the contents of data_file as follows: create a table called Precipitation, with four columns: City (text), Snow (real), Total (integer), Days (integer). (data_file contains one city, snowfall amount, total precipitation amount, and number of days, per line, separated by comma.) # Connect to database db. # Get cursor. # Create a new table. # Populate the Precipitation Table. # Loop through each line in the file: # Get the data from the file and insert into the table. # Commit the changes to the database. # Close cursor and connection. 1

2 3 Accessing Data How can we access the data in the database? def print_all_precipitation(db): (str) -> NoneType Print all records in database db (name/path to a database) in Precipitation table, one per line. # Open database. # Get cursor. # Select desired data. # Fetch and print everything selected. # Close cursor and database. 4 Simple Queries Let s write the following functions to retrieve data from the table. def city_snow(db): (str) -> list of tuple Return a list of tuples [(city, snow),...] from the Precipitation table in the database with name db. con = sqlite3.connect(db) cur = con.cursor() # Execute query. # Get all results. cur.close() con.close() return result 2

3 def city_total(db): (str) -> list of tuple Return a list of tuples [(city, total),...] from the Precipitation table in the database db. con = sqlite3.connect(db) cur = con.cursor() # Execute query. # Get all results. cur.close() con.close() return result Notice that the only line changing in the two functions is the one with cur.execute(). We can take advantage of this by writing a general run query function! def run_query(db, db_query): (str, str) -> list of tuple Return the results of executing query db_query on database with name db. con = sqlite3.connect(db) cur = con.cursor() # Execute query result = cur.fetchall() cur.close() con.close() return result We can now re-write our functions using run query(): def city_snow_v2(db): (str) -> list of tuple Return a list of tuples [(city, snow),...] from the Precipitation table in the database with name db. 3

4 def city_total_v2(db): (str) -> list of tuple Return a list of tuples [(city, total),...] from the Precipitation table in the database named db. Much better! 4.1 Adding a WHERE condition We can restrict the rows that we select by adding query conditions using WHERE. Think of this as adding a filter on the rows that the SELECT query returns. For example, it might be that we only want those cities with precipitation on more than 180 days of the year. We would execute the statement: cur.execute('select City, Days FROM Precipitation WHERE Days > 180') or (notice the tuple of one element!): cur.execute('select City, Days FROM Precipitation WHERE Days >?', (180,)) Let s write a function that returns all cities from Precipitation table where the total snowfall is greater than 200cm: def snow_over_200(db): (str) -> list of tuple Return a list of cities from the Precipitation table in the database with name db, where the amount of snowfall is > 200 cm. It might be nice to be able to make a more generalized function that allows us to specify amounts for the snow and total precipitation as arguments to the function. Complete the function snow total over below. def snow_total_over(db, x, y): (str, number, number) -> list of tuple Return the city names, snowfall amounts, and total precipitation of the cities with at least x cm of snowfall and y total precipitation from the Precipitation table of database with name db. con = sqlite3.connect(db) cur = con.cursor() 4

5 # write query here result = cur.fetchall() cur.close() con.close() return result Q. Can we use the helper function run query in this function? A. Let s improve run query() to allow us to pass query arguments. Notice the header: we are introducing a new way to pass parameters, args=none means if there isn t a third argument passed to run query() then assume that the value is None. That is, the third argument is optional. def run_query_v2(db, q, args=none): (str, str [, tuple]) -> list of tuple Return the results of running query q with arguments args on database db. con = sqlite3.connect(db) cur = con.cursor() if args is None: else: data = cur.fetchall() cur.close() con.close() return data Let s use our new run query v2 function to rewrite snow total over. def snow_total_over_v2(db, x, y): (str, number, number) -> list of tuple Return the cities and snowfall amounts of the cities with at least x cm of snowfall and y total precipitation from the Precipitation table of database db. Notice that we can still use run query v2 as we did run query for function city snow v2: def city_snow_v2(db): (str) -> list of tuple Return a list of tuples [(city, snow),...] from the Precipitation table in the database db (name/path to a database). 5

6 5 Joins Sometimes we want to select data from two or more di erent tables. Consider the following two tables, one which lists library card ID numbers with names and one which lists library card ID numbers with books on loan from the library. Table: Library ID ID Name Homer Marge Bart Lisa Table: Library Loans ID Book NULL Updos for the Modern Woman The Etymology of Slang Quantum Physics for Minors LSAT Prep Guide Suppose that we want to list the books taken out of the library for each student. This requires using one table to look up into another. We can do this by joining the tables. The join of two tables is their cross product. This means you match up every row of the left table with every row of the right table. The symbol for join is on. Here is the result of Library ID on Library Loans: ID Name ID Book Homer NULL Homer Updos for the Modern Woman Homer The Etymology of Slang Homer Quantum Physics for Minors Homer LSAT Prep Guide Marge NULL Marge Updos for the Modern Woman Marge The Etymology of Slang Marge Quantum Physics for Minors Marge LSAT Prep Guide Bart NULL Bart Updos for the Modern Woman Bart The Etymology of Slang Bart Quantum Physics for Minors Bart LSAT Prep Guide Lisa NULL Lisa Updos for the Modern Woman Lisa The Etymology of Slang Lisa Quantum Physics for Minors Lisa LSAT Prep Guide Notice that in this case, the only lines that are useful to us are the ones where the library IDs match. How can we get the list of Books taken out by a person, given their Name? 6

7 Let s do a concrete example. Consider another table Temperature related to our Precipitation table (see page 12 of this handout) populated from the file temperature.txt. First, let s add it to our database: def setup_temp(db, data_file): (str, file open for reading) -> Nonetype Populate the database db with the contents of data_file. Create a table called Temperature, with nine columns: City (text), AvgHigh (real), AvgLow (real), ColdMonth (text), ColdAvgHigh (real), ColdAvgLow (real), WarmMonth (text), WarmAvgHigh (real), WarmAvgLow (real). # Connect to database. con = sqlite3.connect(db) # Get cursor. cur = con.cursor() # Create the Temperature table. cur.execute('''create TABLE Temperature( City TEXT, AvgHigh REAL, AvgLow REAL, ColdMonth TEXT, ColdAvgHigh REAL, ColdAvgLow REAL, WarmMonth TEXT, WarmAvgHigh REAL, WarmAvgLow REAL)''') # Populate the Temperature Table. for line in data_file: data = line.split(",") cur.execute('''insert INTO Temperature VALUES(?,?,?,?,?,?,?,?,?)''', \ (data[0].strip(), float(data[1].strip()), float(data[2].strip()), data[3].strip(), float(data[4].strip()), float(data[5].strip()), data[6].strip(), float(data[7].strip()), float(data[8].strip()))) # Commit the changes to the database. con.commit() # Close cursor and connection. cur.close() con.close() We will also use a table Geography populated by the data in the file geography.txt. Can you do this one yourself? 7

8 def create_geography(db, data_file): (str, file open for reading) -> NoneType Populate the database db with the contents of data_file. Create a table called Geography, with two columns: City (text), Province (text). 5.1 Using JOINs with SELECT We will now practise writing SELECT statements with JOINs. Write a SELECT statement to pass to run query v2 that returns the names of cities which have an average low temperature less than 1 and at least 250cm of snow. What tables do you need to join here? Write a SELECT statement to pass to run query v2 that returns the names of cities and provinces, such that the city has average high temperature over 10 and total precipitation less than 900. What tables do you need to join here? We can also join a table with itself! What problem do you have when trying to write such a SELECT statement? We can solve this by... 8

9 Q. Write a query that returns the names of cities which have the same average low temperatures. Notice that there are duplicates, but the order is permuted we can get rid of these by doing some post processing (working with the results after). 5.2 Using DISTINCT Now consider the following example: Q. Write a query that returns the names of the provinces which have cities where the average low temperature is negative. Notice that this returns duplicates. We can get rid of them by using SELECT DISTINCT. 5.3 Aggregation There are several built-in column functions that we can use: they are AVG, MIN, MAX, SUM, COUNT. They are called aggregate functions and are used as SELECT FUNCTION NAME(column) etc... Q. Example: Use AVG to find the average snowfall amount in table Precipitation. 5.4 Using GROUP BY Suppose that we want to get the average days of precipitation for each province. This means we want to group the Days values according to the province the city is in, and then take the average of the Days belonging to the same province. For example, Ontario cities are Ottawa and Toronto and the total days precipitation are 159 and 139, giving an average of 149. We use the GROUP BY statement: SELECT Geography.Province, AVG(Precipitation.Days) FROM Precipitation JOIN Geography ON Precipitation.City = Geography.City GROUP BY Geography.Province 9

10 10

11 Python Commands import sqlite3: use SQLite to access a database. con = sqlite3.connect("weather.db"): connect to the database stored in file weather.db and name this connection con. cur = con.cursor(): Get a cursor to work with the database and name it cur. cur.execute("sql command"): Execute the given SQL command (string) on the database accessed with the cursor cur. cur.fetchall(): Get a list of rows of the table (tuples) from the columns that have been selected. cur.fetchone(): Get one row of the table (tuple) from the columns that have been selected. cur.close(): Close the cursor. con.commit(): Make our changes to the database permanent by committing them. con.close(): Close the connection. SQL Commands CREATE TABLE TableName(ColumnName 1 TYPE 1, ColumnName 2 TYPE 2,..., ColumnName N TYPE N) DROP TABLE TableName S INSERT INTO TableName VALUES(Val 1, Val 2,..., Val n) INSERT INTO TableName VALUES(?,?,...,?), (Val 1, Val 2,..., Val n) SELECT * FROM TableName SELECT Col 1, Col 2,..., Col n FROM TableName SELECT Col 1, Col 2,..., Col n FROM TableName WHERE condition 1 AND condition 2 AND... AND condition n SELECT TableName1.ColName, TableName2.ColName FROM TableName1 JOIN TableName2 ON condition WHERE condition 1 AND condition 2 AND... AND condition n SELECT DISTINCT TableName1.ColName, TableName2.ColName FROM TableName1 JOIN TableName2 ON condition WHERE condition 1 AND condition 2 AND... AND condition n SELECT TableName1.ColName1, TableName2.ColName2 FROM TableName1 JOIN TableName2 ON condition WHERE condition 1 AND condition 2 AND... AND condition n GROUP BY ColName i UPDATE TableName SET Col 1 = val 1, Col 2 = val 2,... WHERE condition 1 AND condition 2 AND... DELETE FROM TableName WHERE condition

12 NOTE: In the files given on the website, the headers have been stripped and the values are separated by commas. precipitation.txt geography.txt City Snow Total Days St.John s Charlottetown Halifax Fredericton Quebec Montreal Ottawa Toronto Winnipeg Regina Edmonton Calgary Vancouver Victoria Whitehorse Yellowknife City St.John s Charlottetown Halifax Fredericton Quebec Montreal Ottawa Toronto Winnipeg Regina Edmonton Calgary Vancouver Victoria Whitehorse Yellowknife Province Newfoundland PEI Nova Scotia New Brunswick Quebec Quebec Ontario Ontario Manitoba Saskatchewan Alberta Alberta BC BC Yukon NWT temperature.txt City AvgHigh AvgLow ColdMonth ColdAvgHigh ColdAvgLow WarmMonth WarmAvgHigh WarmAvgLow St.John s February July Charlottetown January July Halifax February July Fredericton January July Quebec January July Montreal January July Ottawa January July Toronto January July Winnipeg January July Regina January July Edmonton January July Calgary January July Vancouver January August Victoria January July Whitehorse January July Yellowknife January July

Introduction to pysqlite

Introduction to pysqlite Introduction to pysqlite A crash course to accessing SQLite from within your Python programs. Based on pysqlite 2.0. SQLite basics SQLite is embedded, there is no server Each SQLite database is stored

More information

UNIVERSITY OF TORONTO SCARBOROUGH. Fall 2015 EXAMINATIONS. CSC A20H Duration 3 hours. No Aids Allowed

UNIVERSITY OF TORONTO SCARBOROUGH. Fall 2015 EXAMINATIONS. CSC A20H Duration 3 hours. No Aids Allowed Student Number: Last Name: First Name: UNIVERSITY OF TORONTO SCARBOROUGH Fall 2015 EXAMINATIONS CSC A20H Duration 3 hours No Aids Allowed Do not turn this page until you have received the signal to start.

More information

UNIVERSITY OF TORONTO SCARBOROUGH. Wnter 2016 EXAMINATIONS. CSC A20H Duration 2 hours 45 mins. No Aids Allowed

UNIVERSITY OF TORONTO SCARBOROUGH. Wnter 2016 EXAMINATIONS. CSC A20H Duration 2 hours 45 mins. No Aids Allowed Student Number: Last Name: First Name: UNIVERSITY OF TORONTO SCARBOROUGH Wnter 2016 EXAMINATIONS CSC A20H Duration 2 hours 45 mins No Aids Allowed Do not turn this page until you have received the signal

More information

CSC Web Programming. Introduction to SQL

CSC Web Programming. Introduction to SQL CSC 242 - Web Programming Introduction to SQL SQL Statements Data Definition Language CREATE ALTER DROP Data Manipulation Language INSERT UPDATE DELETE Data Query Language SELECT SQL statements end with

More information

Exercise 1: Introduction to MapInfo

Exercise 1: Introduction to MapInfo Geog 578 Exercise 1: Introduction to MapInfo Page: 1/22 Geog 578: GIS Applications Exercise 1: Introduction to MapInfo Assigned on January 25 th, 2006 Due on February 1 st, 2006 Total Points: 10 0. Convention

More information

CSE 115. Introduction to Computer Science I

CSE 115. Introduction to Computer Science I CSE 115 Introduction to Computer Science I Road map Review (sorting) Persisting data Databases Sorting Given a sequence of values that can be ordered, sorting involves rearranging these values so they

More information

E.164 National Numbering for Canada as Part of Country Code 1

E.164 National Numbering for Canada as Part of Country Code 1 CANADA E.164 National Numbering for Canada as Part of Country Code 1 Canada is part of Country Code 1, and participates in the North American Number Plan (NANP) with the USA and 18 Caribbean nations. A

More information

Data Manipulation Language (DML)

Data Manipulation Language (DML) In the name of Allah Islamic University of Gaza Faculty of Engineering Computer Engineering Department ECOM 4113 DataBase Lab Lab # 3 Data Manipulation Language (DML) El-masry 2013 Objective To be familiar

More information

Explore Integer Subtraction

Explore Integer Subtraction Explore Integer Subtraction Focus on After this lesson, you will be able to... subtract integers using integer chips The system of 24 time zones was proposed by a Canadian engineer, Sir Sandford Fleming.

More information

SQL I: Introduction. Relational Databases. Attribute. Tuple. Relation

SQL I: Introduction. Relational Databases. Attribute. Tuple. Relation 1 SQL I: Introduction Lab Objective: Being able to store and manipulate large data sets quickly is a fundamental part of data science. The SQL language is the classic database management system for working

More information

postgresql postgresql in Flask in 15 or so slides 37 slides

postgresql postgresql in Flask in 15 or so slides 37 slides postgresql postgresql in Flask in 15 or so slides 37 slides but first Principle of Least Privilege A user (or process) should have the lowest level of privilege required in order to perform his/her assigned

More information

EXAM INFORMATION & FREQUENTLY ASKED QUESTIONS

EXAM INFORMATION & FREQUENTLY ASKED QUESTIONS EXAM INFORMATION & FREQUENTLY ASKED QUESTIONS CERTIFIED ASTHMA EDUCATOR (CAE) CERTIFIED RESPIRATORY EDUCATOR (CRE) AND CERTIFIED COPD EDUCATOR (CCE) CERTIFIED TOBACCO EDUCATOR (CTE) CERTIFICATION EXAMS

More information

Package networkd3. December 31, Type Package Title D3 JavaScript Network Graphs from R

Package networkd3. December 31, Type Package Title D3 JavaScript Network Graphs from R Type Package Title D3 JavaScript Network Graphs from R Package networkd3 December 31, 2015 Creates 'D3' 'JavaScript' network, tree, dendrogram, and Sankey graphs from 'R'. Version 0.2.8 Date 2015-12-31

More information

EXAM INFORMATION & FREQUENTLY ASKED QUESTIONS

EXAM INFORMATION & FREQUENTLY ASKED QUESTIONS EXAM INFORMATION & FREQUENTLY ASKED QUESTIONS CERTIFIED ASTHMA EDUCATOR (CAE) CERTIFIED RESPIRATORY EDUCATOR (CRE) AND CERTIFIED COPD EDUCATOR (CCE) CERTIFIED TOBACCO EDUCATOR (CTE) CERTIFICATION EXAMS

More information

UNIVERSITY OF TORONTO SCARBOROUGH. December 2017 EXAMINATIONS. CSCA20H3 Duration 3 hours. Examination Aids: Instructor: Bretscher

UNIVERSITY OF TORONTO SCARBOROUGH. December 2017 EXAMINATIONS. CSCA20H3 Duration 3 hours. Examination Aids: Instructor: Bretscher PLEASE HAND IN UNIVERSITY OF TORONTO SCARBOROUGH December 2017 EXAMINATIONS CSCA20H3 Duration 3 hours PLEASE HAND IN Examination Aids: None Student Number: Last (Family) Name(s): First (Given) Name(s):

More information

MariaDB Crash Course. A Addison-Wesley. Ben Forta. Upper Saddle River, NJ Boston. Indianapolis. Singapore Mexico City. Cape Town Sydney.

MariaDB Crash Course. A Addison-Wesley. Ben Forta. Upper Saddle River, NJ Boston. Indianapolis. Singapore Mexico City. Cape Town Sydney. MariaDB Crash Course Ben Forta A Addison-Wesley Upper Saddle River, NJ Boston Indianapolis San Francisco New York Toronto Montreal London Munich Paris Madrid Cape Town Sydney Tokyo Singapore Mexico City

More information

Announcements (September 14) SQL: Part I SQL. Creating and dropping tables. Basic queries: SFW statement. Example: reading a table

Announcements (September 14) SQL: Part I SQL. Creating and dropping tables. Basic queries: SFW statement. Example: reading a table Announcements (September 14) 2 SQL: Part I Books should have arrived by now Homework #1 due next Tuesday Project milestone #1 due in 4 weeks CPS 116 Introduction to Database Systems SQL 3 Creating and

More information

How to Register Your Continuing Education Units. Step by Step Manual For. Learners

How to Register Your Continuing Education Units. Step by Step Manual For. Learners How to Register Your Continuing Education Units Step by Step Manual For Learners 1 Table of Contents Access as a Learner... 3 Types of Reporting... 6 General Information - Courses... 7 IDCEC Approved...

More information

NULLs & Outer Joins. Objectives of the Lecture :

NULLs & Outer Joins. Objectives of the Lecture : Slide 1 NULLs & Outer Joins Objectives of the Lecture : To consider the use of NULLs in SQL. To consider Outer Join Operations, and their implementation in SQL. Slide 2 Missing Values : Possible Strategies

More information

NCSS: Databases and SQL

NCSS: Databases and SQL NCSS: Databases and SQL Tim Dawborn Lecture 2, January, 2017 Python/sqlite3 DB Design API JOINs 2 Outline 1 Connecting to an SQLite database using Python 2 What is a good database design? 3 A nice API

More information

CMP-3440 Database Systems

CMP-3440 Database Systems CMP-3440 Database Systems Relational DB Languages Relational Algebra, Calculus, SQL Lecture 05 zain 1 Introduction Relational algebra & relational calculus are formal languages associated with the relational

More information

/Keyboarding11/letters on plain paper/letters on plain paper formatting exercises.doc

/Keyboarding11/letters on plain paper/letters on plain paper formatting exercises.doc Jane Donahue, Supervisor Montclair Associates 180 Main Avenue Toronto, Ontario M6G 2G6 Today s date Alex Watson, Principal North Delta Secondary School 11447 82 Avenue Delta, BC V4C 5J6 Dear Mr. Watson

More information

SQL BASICS WITH THE SMALLBANKDB STEFANO GRAZIOLI & MIKE MORRIS

SQL BASICS WITH THE SMALLBANKDB STEFANO GRAZIOLI & MIKE MORRIS SQL BASICS WITH THE SMALLBANKDB STEFANO GRAZIOLI & MIKE MORRIS This handout covers the most important SQL statements. The examples provided throughout are based on the SmallBank database discussed in class.

More information

The CPA Reciprocity Education and Examination (CPARE) Program

The CPA Reciprocity Education and Examination (CPARE) Program The CPA Reciprocity Education and Examination (CPARE) Program Information for International Applicants seeking to qualify under the Public Accounting path for the Canadian CPA designation 1 Introduction...2

More information

ASSIGNMENT NO Computer System with Open Source Operating System. 2. Mysql

ASSIGNMENT NO Computer System with Open Source Operating System. 2. Mysql ASSIGNMENT NO. 3 Title: Design at least 10 SQL queries for suitable database application using SQL DML statements: Insert, Select, Update, Delete with operators, functions, and set operator. Requirements:

More information

Database Systems: Design, Implementation, and Management Tenth Edition. Chapter 7 Introduction to Structured Query Language (SQL)

Database Systems: Design, Implementation, and Management Tenth Edition. Chapter 7 Introduction to Structured Query Language (SQL) Database Systems: Design, Implementation, and Management Tenth Edition Chapter 7 Introduction to Structured Query Language (SQL) Objectives In this chapter, students will learn: The basic commands and

More information

CERTIFIED & CANDIDATE MEMBERSHIP APPLICATION

CERTIFIED & CANDIDATE MEMBERSHIP APPLICATION One Yonge Street #2401, Toronto, ON, Canada M5E 1E5 Phone: (416) 861-CIPS (2477) Fax: (416) 368-9972 E-mail: info@cips.ca http://www.cips.ca INFORMATION SYSTEMS PROFESSIONAL CERTIFIED & CANDIDATE MEMBERSHIP

More information

Lab 3 - Development Phase 2

Lab 3 - Development Phase 2 Lab 3 - Development Phase 2 In this lab, you will continue the development of your frontend by integrating the data generated by the backend. For the backend, you will compute and store the PageRank scores

More information

POSTGRESQL - PYTHON INTERFACE

POSTGRESQL - PYTHON INTERFACE POSTGRESQL - PYTHON INTERFACE http://www.tutorialspoint.com/postgresql/postgresql_python.htm Copyright tutorialspoint.com Installation The PostgreSQL can be integrated with Python using psycopg2 module.

More information

SQL functions fit into two broad categories: Data definition language Data manipulation language

SQL functions fit into two broad categories: Data definition language Data manipulation language Database Principles: Fundamentals of Design, Implementation, and Management Tenth Edition Chapter 7 Beginning Structured Query Language (SQL) MDM NUR RAZIA BINTI MOHD SURADI 019-3932846 razia@unisel.edu.my

More information

UNIVERSITY GRADING SYSTEMS SYSTÈMES DE NOTATION UNIVERSITAIRE

UNIVERSITY GRADING SYSTEMS SYSTÈMES DE NOTATION UNIVERSITAIRE Acadia A+ A+ A- + - 92-93 & after/& après 4.00 3.67 4.00 3.67 3.30 3.00 2.67 Acadia A+ A+ A A- + - efore/avant 92-93 4.33 3.70 4.30 4.00 3.70 3.30 3.00 2.70 Alberta A+ A+ A A- + After/après 09/03 4.00

More information

Transactions for web developers

Transactions for web developers Transactions for web developers Aymeric Augustin - @aymericaugustin DjangoCon Europe - May 17th, 2013 1 Transaction management tools are often made to seem like a black art. Christophe Pettus (2011) Life

More information

RELATIONAL QUERY LANGUAGES

RELATIONAL QUERY LANGUAGES RELATIONAL QUERY LANGUAGES These comments we make on the relational data model are a short introduction to the types of query languages which can be used against a relational database. Before we start

More information

Data Quality Documentation, Discharge Abstract Database

Data Quality Documentation, Discharge Abstract Database Data Quality Documentation, Discharge Abstract Database Current-Year Information 2016 2017 Production of this document is made possible by financial contributions from Health Canada and provincial and

More information

Chapter # 7 Introduction to Structured Query Language (SQL) Part II

Chapter # 7 Introduction to Structured Query Language (SQL) Part II Chapter # 7 Introduction to Structured Query Language (SQL) Part II Updating Table Rows UPDATE Modify data in a table Basic Syntax: UPDATE tablename SET columnname = expression [, columnname = expression]

More information

Travel Expenses for Fiscal 2018-Q3 (October 1, 2017 to December 31, 2017) Senior Management Committee Disclosures are based on reimbursement date

Travel Expenses for Fiscal 2018-Q3 (October 1, 2017 to December 31, 2017) Senior Management Committee Disclosures are based on reimbursement date Michael Denham, President and Chief Executive Officer Transportation Accomodation September 7, 2017 Operational Activities Toronto, ON 17 22 39 September 27-29, 2017 Operational Activities/Key Stakeholders

More information

Databases. Course October 23, 2018 Carsten Witt

Databases. Course October 23, 2018 Carsten Witt Databases Course 02807 October 23, 2018 Carsten Witt Databases Database = an organized collection of data, stored and accessed electronically (Wikipedia) Different principles for organization of data:

More information

Positions in Child Neurology Contact Information 2017

Positions in Child Neurology Contact Information 2017 Positions in Child Neurology Contact Information 2017 British Columbia Academic Positions BC Children s Hospital (University of British Columbia) Regional Positions Dr. Mary Connolly Email: mconnolly@cw.bc.ca

More information

PostgreSQL, Python, and Squid.

PostgreSQL, Python, and Squid. PostgreSQL, Python, and Squid. Christophe Pettus PostgreSQL Experts, Inc. thebuild.com pgexperts.com Let s Talk Squid. What is a squid, anyway? For our purposes, a squid has three attributes: length in

More information

Summary of Last Chapter. Course Content. Chapter 3 Objectives. Chapter 3: Data Preprocessing. Dr. Osmar R. Zaïane. University of Alberta 4

Summary of Last Chapter. Course Content. Chapter 3 Objectives. Chapter 3: Data Preprocessing. Dr. Osmar R. Zaïane. University of Alberta 4 Principles of Knowledge Discovery in Data Fall 2004 Chapter 3: Data Preprocessing Dr. Osmar R. Zaïane University of Alberta Summary of Last Chapter What is a data warehouse and what is it for? What is

More information

Programmers Guide. Adaptive Server Enterprise Extension Module for Python 15.7 SP100

Programmers Guide. Adaptive Server Enterprise Extension Module for Python 15.7 SP100 Programmers Guide Adaptive Server Enterprise Extension Module for Python 15.7 SP100 DOCUMENT ID: DC01692-01-1570100-01 LAST REVISED: May 2013 Copyright 2013 by Sybase, Inc. All rights reserved. This publication

More information

CS108 Lecture 19: The Python DBAPI

CS108 Lecture 19: The Python DBAPI CS108 Lecture 19: The Python DBAPI Sqlite3 database Running SQL and reading results in Python Aaron Stevens 6 March 2013 What You ll Learn Today Review: SQL Review: the Python tuple sequence. How does

More information

SQL 2 (The SQL Sequel)

SQL 2 (The SQL Sequel) Lab 5 SQL 2 (The SQL Sequel) Lab Objective: Learn more of the advanced and specialized features of SQL. Database Normalization Normalizing a database is the process of organizing tables and columns to

More information

HKTA TANG HIN MEMORIAL SECONDARY SCHOOL SECONDARY 3 COMPUTER LITERACY. Name: ( ) Class: Date: Databases and Microsoft Access

HKTA TANG HIN MEMORIAL SECONDARY SCHOOL SECONDARY 3 COMPUTER LITERACY. Name: ( ) Class: Date: Databases and Microsoft Access Databases and Microsoft Access Introduction to Databases A well-designed database enables huge data storage and efficient data retrieval. Term Database Table Record Field Primary key Index Meaning A organized

More information

Review. Objec,ves. Example Students Table. Database Overview 3/8/17. PostgreSQL DB Elas,csearch. Databases

Review. Objec,ves. Example Students Table. Database Overview 3/8/17. PostgreSQL DB Elas,csearch. Databases Objec,ves PostgreSQL DB Elas,csearch Review Databases Ø What language do we use to query databases? March 8, 2017 Sprenkle - CSCI397 1 March 8, 2017 Sprenkle - CSCI397 2 Database Overview Store data in

More information

Oracle Database 11g: SQL and PL/SQL Fundamentals

Oracle Database 11g: SQL and PL/SQL Fundamentals Oracle University Contact Us: +33 (0) 1 57 60 20 81 Oracle Database 11g: SQL and PL/SQL Fundamentals Duration: 5 Days What you will learn In this course, students learn the fundamentals of SQL and PL/SQL

More information

EXAM PREPARATION SECTION 1

EXAM PREPARATION SECTION 1 EXAM PREPARATION SECTION 1 HIGHER ORDER FUNCTIONS, ORDER OF EVALUATION, ENV. DIAGRAMS January 29 to February 2, 2018 1 Code Writing Problems Usually, we begin with a description of the problem to be solved.

More information

Computing for Medicine (C4M) Seminar 3: Databases. Michelle Craig Associate Professor, Teaching Stream

Computing for Medicine (C4M) Seminar 3: Databases. Michelle Craig Associate Professor, Teaching Stream Computing for Medicine (C4M) Seminar 3: Databases Michelle Craig Associate Professor, Teaching Stream mcraig@cs.toronto.edu Relational Model The relational model is based on the concept of a relation or

More information

Intro. Scheme Basics. scm> 5 5. scm>

Intro. Scheme Basics. scm> 5 5. scm> Intro Let s take some time to talk about LISP. It stands for LISt Processing a way of coding using only lists! It sounds pretty radical, and it is. There are lots of cool things to know about LISP; if

More information

CSCD43: Database Systems Technology. Lecture 4

CSCD43: Database Systems Technology. Lecture 4 CSCD43: Database Systems Technology Lecture 4 Wael Aboulsaadat Acknowledgment: these slides are based on Prof. Garcia-Molina & Prof. Ullman slides accompanying the course s textbook. Steps in Database

More information

Traffic violations revisited

Traffic violations revisited Traffic violations revisited November 9, 2017 In this lab, you will once again extract data about traffic violations from a CSV file, but this time you will use SQLite. First, download the following files

More information

DIRECTED (SIGNED) NUMBERS

DIRECTED (SIGNED) NUMBERS Mathematics Revision Guides Directed Numbers Page 1 of 7 M.K. HOME TUITION Mathematics Revision Guides Level: GCSE Higher Tier DIRECTED (SIGNED) NUMBERS Version: 1.4 Date: 21-09-2014 Mathematics Revision

More information

DATABASE MANAGEMENT SYSTEMS PREPARED BY: ENGR. MOBEEN NAZAR

DATABASE MANAGEMENT SYSTEMS PREPARED BY: ENGR. MOBEEN NAZAR DATABASE MANAGEMENT SYSTEMS PREPARED BY: ENGR. MOBEEN NAZAR SCHEME OF PRESENTATION LAB MARKS DISTRIBUTION LAB FILE DBMS PROJECT INSTALLATION STEPS FOR SQL SERVER 2008 SETTING UP SQL SERVER 2008 INTRODUCTION

More information

SQL - Subqueries and. Schema. Chapter 3.4 V4.0. Napier University

SQL - Subqueries and. Schema. Chapter 3.4 V4.0. Napier University SQL - Subqueries and Chapter 3.4 V4.0 Copyright @ Napier University Schema Subqueries Subquery one SELECT statement inside another Used in the WHERE clause Subqueries can return many rows. Subqueries can

More information

Data Quality Documentation, Discharge Abstract Database Current-Year Information,

Data Quality Documentation, Discharge Abstract Database Current-Year Information, Data Quality Documentation, Discharge Abstract Database Current-Year Information, 2012 2013 Standards and Data Submission Our Vision Better data. Better decisions. Healthier Canadians. Our Mandate To lead

More information

Workshop. Introducing SQL: A Foundation of Data Analytics. Robb Sombach University of Alberta Alberta School of Business

Workshop. Introducing SQL: A Foundation of Data Analytics. Robb Sombach University of Alberta Alberta School of Business Workshop Introducing SQL: A Foundation of Data Analytics Robb Sombach University of Alberta Alberta School of Business 1 Agenda Introduction Why SQL? What about Python? R? Data Analytics Relational Database

More information

Chapter-14 SQL COMMANDS

Chapter-14 SQL COMMANDS Chapter-14 SQL COMMANDS What is SQL? Structured Query Language and it helps to make practice on SQL commands which provides immediate results. SQL is Structured Query Language, which is a computer language

More information

My Query Builder Function

My Query Builder Function My Query Builder Function The My Query Builder function is used to build custom SQL queries for reporting information out of the TEAMS system. Query results can be exported to a comma-separated value file,

More information

T-SQL Training: T-SQL for SQL Server for Developers

T-SQL Training: T-SQL for SQL Server for Developers Duration: 3 days T-SQL Training Overview T-SQL for SQL Server for Developers training teaches developers all the Transact-SQL skills they need to develop queries and views, and manipulate data in a SQL

More information

ConnectWise User Guide

ConnectWise User Guide ConnectWise User Guide Document Version 1.0 Created on 4/6/11 Last modified on 4/12/2011 2:19 PM Page 1 Contents Document Information... 1 History of Revisions... 1 1 Preface... 1 2 Overview... 1 3 Requirements...

More information

Some Basic Aggregate Functions FUNCTION OUTPUT The number of rows containing non-null values The maximum attribute value encountered in a given column

Some Basic Aggregate Functions FUNCTION OUTPUT The number of rows containing non-null values The maximum attribute value encountered in a given column SQL Functions Aggregate Functions Some Basic Aggregate Functions OUTPUT COUNT() The number of rows containing non-null values MIN() The minimum attribute value encountered in a given column MAX() The maximum

More information

Inventory your Data. PPDM Data Management Symposium June 2012

Inventory your Data. PPDM Data Management Symposium June 2012 Inventory your Data PPDM Data Management Symposium June 2012 Recap PPDM Meta Model talks Practical Applications - June 2011 Know your Data Oct 2011 Group your Data March 2012 The vision: It will become

More information

SIT772 Database and Information Retrieval WEEK 6. RELATIONAL ALGEBRAS. The foundation of good database design

SIT772 Database and Information Retrieval WEEK 6. RELATIONAL ALGEBRAS. The foundation of good database design SIT772 Database and Information Retrieval WEEK 6. RELATIONAL ALGEBRAS The foundation of good database design Outline 1. Relational Algebra 2. Join 3. Updating/ Copy Table or Parts of Rows 4. Views (Virtual

More information

II. Structured Query Language (SQL)

II. Structured Query Language (SQL) II. Structured Query Language (SQL) Lecture Topics ffl Basic concepts and operations of the relational model. ffl The relational algebra. ffl The SQL query language. CS448/648 II - 1 Basic Relational Concepts

More information

Addressing Foreign Mail

Addressing Foreign Mail 80.25.1 REQUIREMENTS Envelope Customs Declaration Forms The U.S. Postal Service (USPS) requires complete adherence to the following regulations regarding addressing foreign mail. The sender must place

More information

Sql Server Syllabus. Overview

Sql Server Syllabus. Overview Sql Server Syllabus Overview This SQL Server training teaches developers all the Transact-SQL skills they need to create database objects like Tables, Views, Stored procedures & Functions and triggers

More information

INTERACTIVE SQL EXAMPLES

INTERACTIVE SQL EXAMPLES INTERACTIVE SQL EXAMPLES create a table to store information about weather observation stations: -- No duplicate ID fields allowed CREATE TABLE STATION (ID INTEGER PRIMARY KEY, CITY CHAR(20), STATE CHAR(2),

More information

Database Management Systems,

Database Management Systems, Database Management Systems SQL Query Language (3) 1 Topics Aggregate Functions in Queries count sum max min avg Group by queries Set Operations in SQL Queries Views 2 Aggregate Functions Tables are collections

More information

Developing Informix Applications in Python

Developing Informix Applications in Python Developing Informix Applications in Python Carsten Haese Unique Systems, Inc. Informix Forum 2006 Washington, DC December 8-9, 2006 Overview Python Features InformixDB Features Installing InformixDB Interactive

More information

Data about data is database Select correct option: True False Partially True None of the Above

Data about data is database Select correct option: True False Partially True None of the Above Within a table, each primary key value. is a minimal super key is always the first field in each table must be numeric must be unique Foreign Key is A field in a table that matches a key field in another

More information

SEE AUDITOR PROGRAM 2017 MANDATORY UPDATE GUIDE FOR LIFESAVING SOCIETY AFFILIATE DELIVERY PARTNERS AND SEE AUDITORS

SEE AUDITOR PROGRAM 2017 MANDATORY UPDATE GUIDE FOR LIFESAVING SOCIETY AFFILIATE DELIVERY PARTNERS AND SEE AUDITORS SEE AUDITOR PROGRAM 2017 MANDATORY UPDATE GUIDE FOR AFFILIATE DELIVERY PARTNERS AND SEE AUDITORS SEE AUDITOR PROGRAM 2017 MANDATORY UPDATE GUIDE FOR AFFILIATE DELIVERY PARTNERS AND SEE AUDITORS Published

More information

Querying Data with Transact SQL

Querying Data with Transact SQL Course 20761A: Querying Data with Transact SQL Course details Course Outline Module 1: Introduction to Microsoft SQL Server 2016 This module introduces SQL Server, the versions of SQL Server, including

More information

CSCB20 Week 4. Introduction to Database and Web Application Programming. Anna Bretscher Winter 2017

CSCB20 Week 4. Introduction to Database and Web Application Programming. Anna Bretscher Winter 2017 CSCB20 Week 4 Introduction to Database and Web Application Programming Anna Bretscher Winter 2017 Last Week Intro to SQL and MySQL Mapping Relational Algebra to SQL queries Focused on queries to start

More information

CPA Canada Path to Post Designation Licensing for Legacy Members applicable in BC until September 1, 2018

CPA Canada Path to Post Designation Licensing for Legacy Members applicable in BC until September 1, 2018 Questions? Contact: PDPA@cpawsb.ca CPA Canada Path to Post Designation Licensing for Legacy Members applicable in BC until September 1, 2018 PLEASE NOTE: There are both education and practical experience

More information

Microsoft Power Tools for Data Analysis #7 Power Query 6 Types of Merges/ Joins 9 Examples Notes from Video:

Microsoft Power Tools for Data Analysis #7 Power Query 6 Types of Merges/ Joins 9 Examples Notes from Video: Table of Contents: Microsoft Power Tools for Data Analysis #7 Power Query 6 Types of Merges/ Joins 9 Examples Notes from Video: 1. Power Query Has Six Types of Merges / Joins... 2 2. What is a Merge /

More information

SQL Part 2. Kathleen Durant PhD Northeastern University CS3200 Lesson 6

SQL Part 2. Kathleen Durant PhD Northeastern University CS3200 Lesson 6 SQL Part 2 Kathleen Durant PhD Northeastern University CS3200 Lesson 6 1 Outline for today More of the SELECT command Review of the SET operations Aggregator functions GROUP BY functionality JOIN construct

More information

INTERMEDIATE SQL GOING BEYOND THE SELECT. Created by Brian Duffey

INTERMEDIATE SQL GOING BEYOND THE SELECT. Created by Brian Duffey INTERMEDIATE SQL GOING BEYOND THE SELECT Created by Brian Duffey WHO I AM Brian Duffey 3 years consultant at michaels, ross, and cole 9+ years SQL user What have I used SQL for? ROADMAP Introduction 1.

More information

Think about these queries for exam

Think about these queries for exam Think about these queries for exam Write SQL queries specified below in a manner that is consistent with the table definitions. a) Write a SQL query that lists all of the individual water readings recorded

More information

CS 2316 Exam 4 Fall 2012

CS 2316 Exam 4 Fall 2012 CS 2316 Exam 4 Fall 2012 Name : Section TA: Integrity: By taking this exam, you pledge that this is your work and you have neither given nor received inappropriate help during the taking of this exam in

More information

II. Structured Query Language (SQL)

II. Structured Query Language (SQL) II. Structured Query Language () Lecture Topics Basic concepts and operations of the relational model. The relational algebra. The query language. CS448/648 1 Basic Relational Concepts Relating to descriptions

More information

G64DBS Database Systems. Lecture 7 SQL SELECT. The Data Dictionary. Data Dictionaries. Different Sections of SQL (DDL) Different Sections of SQL (DCL)

G64DBS Database Systems. Lecture 7 SQL SELECT. The Data Dictionary. Data Dictionaries. Different Sections of SQL (DDL) Different Sections of SQL (DCL) G64DBS Database Systems Lecture 7 SQL SELECT Tim Brailsford Different Sections of SQL (DDL) The Data Definition Language (DDL): CREATE TABLE - creates a new database table ALTER TABLE - alters (changes)

More information

Add CF-5106 to Importer/Consignee File

Add CF-5106 to Importer/Consignee File Add CF-5106 to Importer/Consignee File This chapter provides record formats to permit users to add data from Customs Form (CF) 5106 (Notification of Importer's Number or Notice of Change of Name or ) to

More information

Lecture 10(-ish) Web [Application] Frameworks

Lecture 10(-ish) Web [Application] Frameworks Lecture 10(-ish) Web [Application] Frameworks Minimal Python server import SocketServer import SimpleHTTPServer class Reply(SimpleHTTPServer.SimpleHTTPRequestHandler): def do_get(self): # query arrives

More information

WHAT IS A DATABASE? There are at least six commonly known database types: flat, hierarchical, network, relational, dimensional, and object.

WHAT IS A DATABASE? There are at least six commonly known database types: flat, hierarchical, network, relational, dimensional, and object. 1 WHAT IS A DATABASE? A database is any organized collection of data that fulfills some purpose. As weather researchers, you will often have to access and evaluate large amounts of weather data, and this

More information

Chapter 7. Introduction to Structured Query Language (SQL) Database Systems: Design, Implementation, and Management, Seventh Edition, Rob and Coronel

Chapter 7. Introduction to Structured Query Language (SQL) Database Systems: Design, Implementation, and Management, Seventh Edition, Rob and Coronel Chapter 7 Introduction to Structured Query Language (SQL) Database Systems: Design, Implementation, and Management, Seventh Edition, Rob and Coronel 1 In this chapter, you will learn: The basic commands

More information

II (The Sequel) We will use the following database as an example throughout this lab, found in students.db.

II (The Sequel) We will use the following database as an example throughout this lab, found in students.db. 2 SQL II (The Sequel) Lab Objective: Since SQL databases contain multiple tables, retrieving information about the data can be complicated. In this lab we discuss joins, grouping, and other advanced SQL

More information

Chapter 16: Databases

Chapter 16: Databases Chapter 16: Databases Starting Out with Java: From Control Structures through Objects Fifth Edition by Tony Gaddis Chapter Topics Chapter 16 discusses the following main topics: Introduction to Database

More information

CLOUD BASE PHONE SYSTEM

CLOUD BASE PHONE SYSTEM CLOUD BASE PHONE SYSTEM Cloud Connexions s new Cloud Based Phone System has all of the features of the best telephone and voicemail systems, with no equipment to buy, maintain or outgrow. Ours is a Cloud

More information

SQL grouping, views & modifying data

SQL grouping, views & modifying data SQL grouping, views & modifying data Grouping (GROUP BY) Views INSERT UPDATE DELETE Steen Jensen, autumn 2017 SQL query - grouping Grouping makes it possible to show information listed in groups Conditions

More information

NCSS: Databases and SQL

NCSS: Databases and SQL NCSS: Databases and SQL Tim Dawborn Lecture 1, January, 2016 Motivation SQLite SELECT WHERE JOIN Tips 2 Outline 1 Motivation 2 SQLite 3 Searching for Data 4 Filtering Results 5 Joining multiple tables

More information

DS Introduction to SQL Part 1 Single-Table Queries. By Michael Hahsler based on slides for CS145 Introduction to Databases (Stanford)

DS Introduction to SQL Part 1 Single-Table Queries. By Michael Hahsler based on slides for CS145 Introduction to Databases (Stanford) DS 1300 - Introduction to SQL Part 1 Single-Table Queries By Michael Hahsler based on slides for CS145 Introduction to Databases (Stanford) Overview 1. SQL introduction & schema definitions 2. Basic single-table

More information

CS 2316 Exam 4 Fall 2011

CS 2316 Exam 4 Fall 2011 CS 2316 Exam 4 Fall 2011 Name : Grading TA: Integrity: By taking this exam, you pledge that this is your work and you have neither given nor received inappropriate help during the taking of this exam in

More information

Chapter 4: SQL. Basic Structure

Chapter 4: SQL. Basic Structure Chapter 4: SQL Basic Structure Set Operations Aggregate Functions Null Values Nested Subqueries Derived Relations Views Modification of the Database Joined Relations Data Definition Language Embedded SQL

More information

In This Lecture. Yet More SQL SELECT ORDER BY. SQL SELECT Overview. ORDER BY Example. ORDER BY Example. Yet more SQL

In This Lecture. Yet More SQL SELECT ORDER BY. SQL SELECT Overview. ORDER BY Example. ORDER BY Example. Yet more SQL In This Lecture Yet More SQL Database Systems Lecture 9 Natasha Alechina Yet more SQL ORDER BY Aggregate functions and HAVING etc. For more information Connoly and Begg Chapter 5 Ullman and Widom Chapter

More information

The Structured Query Language Get Started

The Structured Query Language Get Started The Structured Query Language Get Started Himadri Barman 0. Prerequisites: A database is an organized collection of related data that can easily be retrieved and used. By data, we mean known facts that

More information

SQL - Basics. SQL Overview

SQL - Basics. SQL Overview SQL - Basics Davood Rafiei 1 SQL Overview Structured Query Language standard query language for relational system. developed in IBM Almaden (system R) Some features Declarative: specify the properties

More information

Relational Data Structure and Concepts. Structured Query Language (Part 1) The Entity Integrity Rules. Relational Data Structure and Concepts

Relational Data Structure and Concepts. Structured Query Language (Part 1) The Entity Integrity Rules. Relational Data Structure and Concepts Relational Data Structure and Concepts Structured Query Language (Part 1) Two-dimensional tables whose attributes values are atomic. At every row-and-column position within the table, there always exists

More information

Relational Model, Relational Algebra, and SQL

Relational Model, Relational Algebra, and SQL Relational Model, Relational Algebra, and SQL August 29, 2007 1 Relational Model Data model. constraints. Set of conceptual tools for describing of data, data semantics, data relationships, and data integrity

More information

Relational Algebra and SQL

Relational Algebra and SQL Relational Algebra and SQL Relational Algebra. This algebra is an important form of query language for the relational model. The operators of the relational algebra: divided into the following classes:

More information

Database Design and Programming

Database Design and Programming Database Design and Programming Jan Baumbach jan.baumbach@imada.sdu.dk http://www.baumbachlab.net JDBC Java Database Connectivity (JDBC) is a library similar for accessing a DBMS with Java as the host

More information