NCSS: Databases and SQL

Size: px
Start display at page:

Download "NCSS: Databases and SQL"

Transcription

1 NCSS: Databases and SQL Tim Dawborn Lecture 2, January, 2017

2 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 4 ore on joins and subqueries...

3 Python/sqlite3 DB Design API JOINs 3 Database Application Programming Python standard library contains a module for interacting with SQLite databases: sqlite3 You work primarily with Connection and Cursor objects The connect method creates a Connection object to a SQLite database 1 >>> import sqlite3 2 >>> conn = sqlite3.connect('sports.db') 3 >>> conn 4 <sqlite3.connection object at 0x312720> 5 >>> Once you are finished, the connection should be closed 6 >>> conn.close() 7 >>>

4 Python/sqlite3 DB Design API JOINs 4 Cursor Objects Cursors are the standard way to interact with a database from within a programming language Cursor objects allow you to execute a query and iterate through the results of a query A Connection object allows you to obtain a cursor which points into the database 1 >>> cur = conn.cursor() 2 >>> cur 3 <sqlite3.cursor object at 0x387b00> 4 >>>

5 Python/sqlite3 DB Design API JOINs 5 Executing Queries The cursor has an execute method which allows you to execute one SQL query at a result The cursor object itself can then be iterated through to obtain the resultant rows 1 >>> cur.execute('select * FRO events;') 2 >>> for row in cur: 3... print(row) 4 5 (0, '100m',, '', '09:10') 6 (1, '200m',, '', '09:15') 7 (2, '100m', 17, '', '09:00') 8 (3, '100m', 17, 'F', '09:05') 9 >>>

6 Python/sqlite3 DB Design API JOINs 6 Executing Queries The fetchone method returns one row at a result, or None The previous is equivalent to the following 1 >>> cur.execute('select * FRO events;') 2 >>> while True: 3... row = cur.fetchone() 4... if row is None: 5... break 6... print(row) 7 8 (0, '100m',, '', '09:10') 9 (1, '200m',, '', '09:15') 10 (2, '100m', 17, '', '09:00') 11 (3, '100m', 17, 'F', '09:05') 12 >>>

7 Python/sqlite3 DB Design API JOINs 7 Data Types: Python vs. SQL We know SQLite has 5 data types However, Python has a lot more than these five... str, int, float, list, dict, set, tuple,... How do we coerce Python data types to SQLite and vice-versa?

8 Python/sqlite3 DB Design API JOINs 7 Data Types: Python vs. SQL We know SQLite has 5 data types However, Python has a lot more than these five... str, int, float, list, dict, set, tuple,... How do we coerce Python data types to SQLite and vice-versa? SQLite Python NULL INTEGER REAL TEXT BLOB None int float str bytes

9 Python/sqlite3 DB Design API JOINs 8 Joining tables Why do we need to join tables together?

10 Python/sqlite3 DB Design API JOINs 8 Joining tables Why do we need to join tables together? Why not store all data in just one huge table?

11 Python/sqlite3 DB Design API JOINs 8 Joining tables id Why do we need to join tables together? Why not store all data in just one huge table? fname Barry Barry Prue Andrew athew ara Scott Alec Karen Grant lname Schultz Schultz Robinson Varvel Nemes Barber Herdman Newton Barber Ovzinsky gender F F F age ename 100m 200m 100m 100m 100m 100m 100m 100m 200m eage egender F F at 09:10 09:15 09:05 09:10 09:10 09:05 09:10 09:10 09:00 result 00:15 00:40 00:20 00:17 00:20 00:21

12 Python/sqlite3 DB Design API JOINs 8 Joining tables id Why do we need to join tables together? Why not store all data in just one huge table? fname Barry Barry Prue Andrew athew ara Scott Alec Karen Grant lname Schultz Schultz Robinson Varvel Nemes Barber Herdman Newton Barber Ovzinsky gender F F F age ename 100m 200m 100m 100m 100m 100m 100m 100m 200m eage egender F F at 09:10 09:15 09:05 09:10 09:10 09:05 09:10 09:10 09:00 result 00:15 00:40 00:20 00:17 00:20 00:21 Problem: A lot of data is repeated and too many NULLs...

13 Python/sqlite3 DB Design API JOINs 9 Central goal: minimizing redundancy Central goal of database design: minimizing data redundancy There s a large body of theoretical work on this Data Normalization in a nutshell: Keep a table about data of just one concept. (such as persons or events) Use foreign keys to link tables in your schema

14 Python/sqlite3 DB Design API JOINs 9 Central goal: minimizing redundancy Central goal of database design: minimizing data redundancy There s a large body of theoretical work on this Data Normalization in a nutshell: Keep a table about data of just one concept. (such as persons or events) Use foreign keys to link tables in your schema people id fname lname gender age results event person result events id name age gender at

15 Python/sqlite3 DB Design API JOINs 10 A well-done database schema The Good: each table is about a well defined concept only updates affect (typically) a single row only The Bad: many tables tendency to introduce unique IDs a lot of joins... The Ugly: it s not always possible and very experience-driven

16 Python/sqlite3 DB Design API JOINs 11 Piecing it all together How are we going to integrate all of this into our NCSSBook? odel-view-controller mentality Loading and writing data to and from a SQLite database Database is stored in a single flatfile Ease of setup no server required Convenient for version control Correct data modelling is important

17 Python/sqlite3 DB Design API JOINs 12 Example: Account table id What do you think about the following users table design? user steve elaine miranda jesse mathew tim pass 1234 abcdef foobar 1Two3 156ytfv1h8 joshua s@my.home eora@yahoo.com m123@gmail.com jesse@town.org mat@hotmail.com tim@iinet.net.au school St. ary s St. ary s X Public School Y State High Y State High ercedes College city Sydney Sydney Glebe Townsville Townsville Perth friends 2,3 1 1,4,5 3,5 3,4,6,10 5,10

18 Python/sqlite3 DB Design API JOINs 12 Example: Account table What do you think about the following users table design? id user pass school city friends steve elaine miranda jesse mathew tim 1234 abcdef foobar 1Two3 156ytfv1h8 joshua s@my.home eora@yahoo.com m123@gmail.com jesse@town.org mat@hotmail.com tim@iinet.net.au St. ary s St. ary s X Public School Y State High Y State High ercedes College Sydney Sydney Glebe Townsville Townsville Perth 2,3 1 1,4,5 3,5 3,4,6,10 5,10 friends should be a separate table rather than a CSV-string Better also have schools in a separate table Unencrypted passwords? Seriously!?

19 Python/sqlite3 DB Design API JOINs 13 Example: Login code What do you think about the following login code? 1 import sqlite3 2 def login(username, password): 3 conn = sqlite3.connect('ncssbook.db') 4 cur = conn.execute('select user, pass FRO users') 5 found = False 6 for row in cur: 7 if row[0] == username and row[1] == password: 8 found = True 9 conn.close() 10 return found

20 Python/sqlite3 DB Design API JOINs 13 Example: Login code What do you think about the following login code? 1 import sqlite3 2 def login(username, password): 3 conn = sqlite3.connect('ncssbook.db') 4 cur = conn.execute('select user, pass FRO users') 5 found = False 6 for row in cur: 7 if row[0] == username and row[1] == password: 8 found = True 9 conn.close() 10 return found Do not scan a table and filter in Python use SQL! row[0] or row[1] relies on the positions; use row["user"] Use just one connection for the whole program Store passwords hashed or encrypted!

21 Python/sqlite3 DB Design API JOINs 14 Example: Login code a better approach 1 import sqlite3 2 3 conn = sqlite3.connect('ncssbook.db') 4 5 def login(username, password): 6 cur = conn.execute(''' 7 SELECT id 8 FRO users 9 WHERE user=? AND pass=? 10 ''', (username, password)) 11 row = cur.fetchone() 12 user_id = None if row is None else row['id'] 13 conn.commit() 14 return user_id

22 Python/sqlite3 DB Design API JOINs 15 aking others lives easier There are some operations that we ll do a lot: Create a (user) row in a table Find a (user) row in a table Update a (user) row in a table Delete a (user) row in a table It s painful to have to write SQL every time we need to do this for every single type of table in the database!

23 Python/sqlite3 DB Design API JOINs Idea 1: Let s use functions 1 def find_user(username, conn): 2 cur = conn.execute('''select * FRO users 3 WHERE user=?''', (username,)) 4 row = cur.fetchone() 5 return row What s wrong with this?

24 Python/sqlite3 DB Design API JOINs Idea 1: Let s use functions 1 def find_user(username, conn): 2 cur = conn.execute('''select * FRO users 3 WHERE user=?''', (username,)) 4 row = cur.fetchone() 5 return row What s wrong with this? The user of the function has to process the tuple Exposes changes in the database schema This is ugly and prone to failure

25 Python/sqlite3 DB Design API JOINs 17 Idea 2: Let s use classes and objects 1 class User: 2 def init (self, username, fname, lname): 3 self.username = username 4 self.fname = fname 5 self.lname = lname 6 8 def find(username): 9 cur = conn.execute('''select * FRO users 10 WHERE user=?''', (username,)) 11 row = cur.fetchone() 12 if row is None: 13 raise UserNotFound('{} does not exist'.format(username)) 14 return User(row[0], row[1], row[2])

26 Python/sqlite3 DB Design API JOINs 18 Idea 2: Let s use classes and objects 2 def create(username, fname, lname): 3 cur = conn.execute('''insert INTO users 4 VALUES (?,?,?)''', (username, fname, lname)) 5 return User(username, fname, lname) 6 8 def delete(username): 9 cur = conn.execute('''delete FRO users 10 WHERE username =?''', (username,))

27 Python/sqlite3 DB Design API JOINs 19 An API abstracts away from the database Defining the User object makes life much nicer for other programmers No one else has to write SQL (like the function approach) Internalise the tuple processing and produce a standardized object representation We can transparently make changes to the database schema without affecting anyone else You should consider creating an object like this for each table in your database And if you re really good, you could try and figure out how to avoid rewriting for every new database table

28 Python/sqlite3 DB Design API JOINs 20 ore Joins Okay, back to more complex SQL We can join more than two tables together Example: List the names of all females who ran the 100m in alphabetical order.

29 Python/sqlite3 DB Design API JOINs 20 ore Joins Okay, back to more complex SQL We can join more than two tables together Example: List the names of all females who ran the 100m in alphabetical order. 1 SELECT fname, lname 2 FRO people p 3 JOIN results r ON p.id = r.person 4 JOIN events e ON e.id = r.event 5 WHERE e.name = '100m' 6 AND e.gender = 'F' 7 ORDER BY lname;

30 Python/sqlite3 DB Design API JOINs 21 Nested SQL queries Remember: Every SQL query returns its result as a table. This means we can nest SQL queries: an outer query can check the results of an inner (nested) sub-query. We can build complex query from smaller building blocks.

31 Python/sqlite3 DB Design API JOINs 22 Nesting SQL Queries (continued) Example: Which females ran in the 100m?

32 Python/sqlite3 DB Design API JOINs 22 Nesting SQL Queries (continued) Example: Which females ran in the 100m? 1 SELECT r.person 2 FRO results r 3 JOIN events e ON e.id = r.event 4 WHERE e.name = '100m' AND e.gender = 'F'

33 Python/sqlite3 DB Design API JOINs 22 Nesting SQL Queries (continued) Example: Which females ran in the 100m? 1 SELECT r.person 2 FRO results r 3 JOIN events e ON e.id = r.event 4 WHERE e.name = '100m' AND e.gender = 'F' Use this as a sub-query to answer the original question: 1 SELECT fname, lname 2 FRO people 3 WHERE id IN ( 4 SELECT r.person 5 FRO results r 6 JOIN events e ON e.id = r.event 7 WHERE e.name = '100m' AND e.gender = 'F' 8 ) 9 ORDER BY lname;

34 Python/sqlite3 DB Design API JOINs 23 Scientific Databases: How complex SQL can become... Part of our work here at Sydney Uni is to look at how databases and SQL can help answering scientific questions. For example in the context of genomics: Another good example: SkyServer

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

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

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

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

Intro to Programming. Unit 7. What is Programming? What is Programming? Intro to Programming

Intro to Programming. Unit 7. What is Programming? What is Programming? Intro to Programming Intro to Programming Unit 7 Intro to Programming 1 What is Programming? 1. Programming Languages 2. Markup vs. Programming 1. Introduction 2. Print Statement 3. Strings 4. Types and Values 5. Math Externals

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

15-388/688 - Practical Data Science: Relational Data. J. Zico Kolter Carnegie Mellon University Spring 2018

15-388/688 - Practical Data Science: Relational Data. J. Zico Kolter Carnegie Mellon University Spring 2018 15-388/688 - Practical Data Science: Relational Data J. Zico Kolter Carnegie Mellon University Spring 2018 1 Announcements Piazza etiquette: Changing organization of threads to be easier to search (starting

More information

CIS 192: Lecture 11 Databases (SQLite3)

CIS 192: Lecture 11 Databases (SQLite3) CIS 192: Lecture 11 Databases (SQLite3) Lili Dworkin University of Pennsylvania In-Class Quiz app = Flask( main ) @app.route('/') def home():... app.run() 1. type(app.run) 2. type(app.route( / )) Hint:

More information

Carnegie Mellon Univ. Dept. of Computer Science /615 - DB Applications. Today's Party. Example Database. Faloutsos/Pavlo CMU /615

Carnegie Mellon Univ. Dept. of Computer Science /615 - DB Applications. Today's Party. Example Database. Faloutsos/Pavlo CMU /615 Carnegie Mellon Univ. Dept. of Computer Science 15-415/615 - DB Applications C. Faloutsos A. Pavlo Lecture#6: Fun with SQL (part2) Today's Party DDLs Complex Joins Views Nested Subqueries Triggers Database

More information

DATABASE MANAGEMENT SYSTEMS

DATABASE MANAGEMENT SYSTEMS www..com Code No: N0321/R07 Set No. 1 1. a) What is a Superkey? With an example, describe the difference between a candidate key and the primary key for a given relation? b) With an example, briefly describe

More information

Database Systems CSE 414

Database Systems CSE 414 Database Systems CSE 414 Lecture 15-16: Basics of Data Storage and Indexes (Ch. 8.3-4, 14.1-1.7, & skim 14.2-3) 1 Announcements Midterm on Monday, November 6th, in class Allow 1 page of notes (both sides,

More information

INTRODUCTION TO DATA SCIENCE

INTRODUCTION TO DATA SCIENCE INTRODUCTION TO DATA SCIENCE JOHN P DICKERSON Lecture #7 2/16/2017 CMSC320 Tuesdays & Thursdays 3:30pm 4:45pm ANNOUNCEMENTS Anant s office hours have changed: Old: 2PM-3PM on Tuesdays New: 11AM-12PM on

More information

Introduction to Programming in C Department of Computer Science and Engineering. Lecture No. #16 Loops: Matrix Using Nested for Loop

Introduction to Programming in C Department of Computer Science and Engineering. Lecture No. #16 Loops: Matrix Using Nested for Loop Introduction to Programming in C Department of Computer Science and Engineering Lecture No. #16 Loops: Matrix Using Nested for Loop In this section, we will use the, for loop to code of the matrix problem.

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 HTML injection SQL injection Persisting data Central Processing Unit CPU Random Access Memory RAM persistent storage (e.g. file or database) Persisting

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

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

L6 Application Programming. Thibault Sellam Fall 2018

L6 Application Programming. Thibault Sellam Fall 2018 L6 Application Programming Thibault Sellam Fall 2018 Topics Interfacing with applications Database APIs (DBAPIS) Cursors SQL!= Programming Language Not a general purpose programming language Tailored for

More information

Midterm 1: CS186, Spring 2012

Midterm 1: CS186, Spring 2012 Midterm 1: CS186, Spring 2012 Prof. J. Hellerstein You should receive a double- sided answer sheet and a 7- page exam. Mark your name and login on both sides of the answer sheet. For each question, place

More information

Text Input and Conditionals

Text Input and Conditionals Text Input and Conditionals Text Input Many programs allow the user to enter information, like a username and password. Python makes taking input from the user seamless with a single line of code: input()

More information

CSC 120 Worksheet 12 Databases

CSC 120 Worksheet 12 Databases 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

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

CSE 414 Midterm. April 28, Name: Question Points Score Total 101. Do not open the test until instructed to do so.

CSE 414 Midterm. April 28, Name: Question Points Score Total 101. Do not open the test until instructed to do so. CSE 414 Midterm April 28, 2017 Name: Question Points Score 1 35 2 15 3 30 4 21 Total 101 Do not open the test until instructed to do so. The test is closed book and electronics. You are allowed only one

More information

Principles of Data Management

Principles of Data Management Principles of Data Management Alvin Lin August 2018 - December 2018 Structured Query Language Structured Query Language (SQL) was created at IBM in the 80s: SQL-86 (first standard) SQL-89 SQL-92 (what

More information

python-tds Documentation

python-tds Documentation python-tds Documentation Release 1.6 Mikhail Denisenko Dec 09, 2017 Contents 1 pytds main module 3 2 pytds.login login with NTLM and SSPI 9 3 pytds.tz timezones 11 4 pytds.extensions Extensions to the

More information

High Level Database Models

High Level Database Models ICS 321 Fall 2011 High Level Database Models Asst. Prof. Lipyeow Lim Information & Computer Science Department University of Hawaii at Manoa 9/21/2011 Lipyeow Lim -- University of Hawaii at Manoa 1 Database

More information

Introduction to Data Management CSE 344

Introduction to Data Management CSE 344 Introduction to Data Management CSE 344 Lectures 4 and 5: Aggregates in SQL Dan Suciu - CSE 344, Winter 2012 1 Announcements Homework 1 is due tonight! Quiz 1 due Saturday Homework 2 is posted (due next

More information

Database Application Development

Database Application Development CS 500: Fundamentals of Databases Database Application Development supplementary material: Database Management Systems Sec. 6.2, 6.3 DBUtils.java, Student.java, Registrar.java, RegistrarServlet.java, PgRegistrar.sql

More information

CS 405G: Introduction to Database Systems. Storage

CS 405G: Introduction to Database Systems. Storage CS 405G: Introduction to Database Systems Storage It s all about disks! Outline That s why we always draw databases as And why the single most important metric in database processing is the number of disk

More information

DATABASE SYSTEMS. Introduction to MySQL. Database System Course, 2016

DATABASE SYSTEMS. Introduction to MySQL. Database System Course, 2016 DATABASE SYSTEMS Introduction to MySQL Database System Course, 2016 AGENDA FOR TODAY Administration Database Architecture on the web Database history in a brief Databases today MySQL What is it How to

More information

Introduction to Database Systems CSE 344

Introduction to Database Systems CSE 344 Introduction to Database Systems CSE 344 Lecture 6: Basic Query Evaluation and Indexes 1 Announcements Webquiz 2 is due on Tuesday (01/21) Homework 2 is posted, due week from Monday (01/27) Today: query

More information

Data Storage. Query Performance. Index. Data File Types. Introduction to Data Management CSE 414. Introduction to Database Systems CSE 414

Data Storage. Query Performance. Index. Data File Types. Introduction to Data Management CSE 414. Introduction to Database Systems CSE 414 Introduction to Data Management CSE 414 Unit 4: RDBMS Internals Logical and Physical Plans Query Execution Query Optimization Introduction to Database Systems CSE 414 Lecture 16: Basics of Data Storage

More information

CSE 344 FEBRUARY 14 TH INDEXING

CSE 344 FEBRUARY 14 TH INDEXING CSE 344 FEBRUARY 14 TH INDEXING EXAM Grades posted to Canvas Exams handed back in section tomorrow Regrades: Friday office hours EXAM Overall, you did well Average: 79 Remember: lowest between midterm/final

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

Find All Tables Containing Column With Specified Name Oracle

Find All Tables Containing Column With Specified Name Oracle Find All Tables Containing Column With Specified Name Oracle I'M TRYING to find a column called author_last_name in oracle-apex I want to find a possible duplicate of I want to show all tables that have

More information

Enterprise Reporting -- APEX

Enterprise Reporting -- APEX Quick Reference Enterprise Reporting -- APEX This Quick Reference Guide documents Oracle Application Express (APEX) as it relates to Enterprise Reporting (ER). This is not an exhaustive APEX documentation

More information

SQL: Concepts. Todd Bacastow IST 210: Organization of Data 2/17/ IST 210

SQL: Concepts. Todd Bacastow IST 210: Organization of Data 2/17/ IST 210 SQL: Concepts Todd Bacastow IST 210: Organization of Data 2/17/2004 1 Design questions How many entities are there? What are the major entities? What are the attributes of each entity? Is there a unique

More information

LABORATORY OF DATA SCIENCE. Data Access: Relational Data Bases. Data Science and Business Informatics Degree

LABORATORY OF DATA SCIENCE. Data Access: Relational Data Bases. Data Science and Business Informatics Degree LABORATORY OF DATA SCIENCE Data Access: Relational Data Bases Data Science and Business Informatics Degree RDBMS data access 2 Protocols and API ODBC, OLE DB, ADO, ADO.NET, JDBC Python DBAPI with ODBC

More information

pglib Documentation Release Michael Kleehammer

pglib Documentation Release Michael Kleehammer pglib Documentation Release 2.4.0 Michael Kleehammer Dec 26, 2017 Contents 1 Quick Start 3 1.1 Connecting................................................ 3 1.2 Basic Selecting..............................................

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

University of California, Berkeley. (2 points for each row; 1 point given if part of the change in the row was correct)

University of California, Berkeley. (2 points for each row; 1 point given if part of the change in the row was correct) University of California, Berkeley CS 186 Intro to Database Systems, Fall 2012, Prof. Michael J. Franklin MIDTERM II - Questions This is a closed book examination but you are allowed one 8.5 x 11 sheet

More information

DB tutorial using Database.NET dbforge Studio Express and SQLiteSpy

DB tutorial using Database.NET dbforge Studio Express and SQLiteSpy DB tutorial using Database.NET dbforge Studio Express and SQLiteSpy SQLite SQLite is a open source file-based database which used in a lot of applications on both desktop and mobile It is easy to play

More information

Using Relational Databases for Digital Research

Using Relational Databases for Digital Research Using Relational Databases for Digital Research Definition (using a) relational database is a way of recording information in a structure that maximizes efficiency by separating information into different

More information

DATABASE SYSTEMS. Database programming in a web environment. Database System Course,

DATABASE SYSTEMS. Database programming in a web environment. Database System Course, DATABASE SYSTEMS Database programming in a web environment Database System Course, 2016-2017 AGENDA FOR TODAY The final project Advanced Mysql Database programming Recap: DB servers in the web Web programming

More information

Multiple-Choice. 3. When you want to see all of the awards, even those not yet granted to a student, replace JOIN in the following

Multiple-Choice. 3. When you want to see all of the awards, even those not yet granted to a student, replace JOIN in the following Database Design, CSCI 340, Spring 2015 Final, May 12 Multiple-Choice 1. Which of the following is not part of the vocabulary of database keys? (3 pts.) a. Referential key b. Composite key c. Primary key

More information

MySQL. A practical introduction to database design

MySQL. A practical introduction to database design MySQL A practical introduction to database design Dr. Chris Tomlinson Bioinformatics Data Science Group, Room 126, Sir Alexander Fleming Building chris.tomlinson@imperial.ac.uk Database Classes 24/09/18

More information

Carnegie Mellon Univ. Dept. of Computer Science Database Applications. General Overview - rel. model. Overview - detailed - SQL

Carnegie Mellon Univ. Dept. of Computer Science Database Applications. General Overview - rel. model. Overview - detailed - SQL Faloutsos 15-415 Carnegie Mellon Univ. Dept. of Computer Science 15-415 - Database Applications C. Faloutsos Lecture#7 (cont d): Rel. model - SQL part3 General Overview - rel. model Formal query languages

More information

Physical Database Design and Tuning. Review - Normal Forms. Review: Normal Forms. Introduction. Understanding the Workload. Creating an ISUD Chart

Physical Database Design and Tuning. Review - Normal Forms. Review: Normal Forms. Introduction. Understanding the Workload. Creating an ISUD Chart Physical Database Design and Tuning R&G - Chapter 20 Although the whole of this life were said to be nothing but a dream and the physical world nothing but a phantasm, I should call this dream or phantasm

More information

Recursive Search with Backtracking

Recursive Search with Backtracking CS 311 Data Structures and Algorithms Lecture Slides Friday, October 2, 2009 Glenn G. Chappell Department of Computer Science University of Alaska Fairbanks CHAPPELLG@member.ams.org 2005 2009 Glenn G.

More information

Beyond Blocks: Python Session #1

Beyond Blocks: Python Session #1 Beyond Blocks: Session #1 CS10 Spring 2013 Thursday, April 30, 2013 Michael Ball Beyond Blocks : : Session #1 by Michael Ball adapted from Glenn Sugden is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike

More information

Hash table example. B+ Tree Index by Example Recall binary trees from CSE 143! Clustered vs Unclustered. Example

Hash table example. B+ Tree Index by Example Recall binary trees from CSE 143! Clustered vs Unclustered. Example Student Introduction to Database Systems CSE 414 Hash table example Index Student_ID on Student.ID Data File Student 10 Tom Hanks 10 20 20 Amy Hanks ID fname lname 10 Tom Hanks 20 Amy Hanks Lecture 26:

More information

MASSACHUSETTS INSTITUTE OF TECHNOLOGY Database Systems: Fall 2009 Quiz I Solutions

MASSACHUSETTS INSTITUTE OF TECHNOLOGY Database Systems: Fall 2009 Quiz I Solutions Department of Electrical Engineering and Computer Science MASSACHUSETTS INSTITUTE OF TECHNOLOGY 6.830 Database Systems: Fall 2009 Quiz I Solutions There are 15 questions and 12 pages in this quiz booklet.

More information

Introduction to Database Systems CSE 414

Introduction to Database Systems CSE 414 Introduction to Database Systems CSE 414 Lectures 4 and 5: Aggregates in SQL CSE 414 - Spring 2013 1 Announcements Homework 1 is due on Wednesday Quiz 2 will be out today and due on Friday CSE 414 - Spring

More information

Relational Databases

Relational Databases Relational Databases Lecture 2 Chapter 3 Robb T. Koether Hampden-Sydney College Fri, Jan 18, 2013 Robb T. Koether (Hampden-Sydney College) Relational Databases Fri, Jan 18, 2013 1 / 26 1 Types of Databases

More information

Midterm 1: CS186, Spring 2012

Midterm 1: CS186, Spring 2012 Midterm 1: CS186, Spring 2012 Prof. J. Hellerstein You should receive a double- sided answer sheet and a 7- page exam. Mark your name and login on both sides of the answer sheet. For each question, place

More information

ORACLE DATABASE 12C INTRODUCTION

ORACLE DATABASE 12C INTRODUCTION SECTOR / IT NON-TECHNICAL & CERTIFIED TRAINING COURSE In this training course, you gain the skills to unleash the power and flexibility of Oracle Database 12c, while gaining a solid foundation of database

More information

Introduction to Database Systems CSE 344

Introduction to Database Systems CSE 344 Introduction to Database Systems CSE 344 Lecture 10: Basics of Data Storage and Indexes 1 Student ID fname lname Data Storage 10 Tom Hanks DBMSs store data in files Most common organization is row-wise

More information

The Big Python Guide

The Big Python Guide The Big Python Guide Big Python Guide - Page 1 Contents Input, Output and Variables........ 3 Selection (if...then)......... 4 Iteration (for loops)......... 5 Iteration (while loops)........ 6 String

More information

Lecture 04: SQL. Monday, April 2, 2007

Lecture 04: SQL. Monday, April 2, 2007 Lecture 04: SQL Monday, April 2, 2007 1 Outline The Project Nulls (6.1.6) Outer joins (6.3.8) Database Modifications (6.5) 2 NULLS in SQL Whenever we don t have a value, we can put a NULL Can mean many

More information

origin destination duration New York London 415 Shanghai Paris 760 Istanbul Tokyo 700 New York Paris 435 Moscow Paris 245 Lima New York 455

origin destination duration New York London 415 Shanghai Paris 760 Istanbul Tokyo 700 New York Paris 435 Moscow Paris 245 Lima New York 455 CS50 Beyond Databases origin destination duration New York London 415 Shanghai Paris 760 Istanbul Tokyo 700 New York Paris 435 Moscow Paris 245 Lima New York 455 SQL SQL Databases MySQL PostgreSQL SQLite...

More information

JSON Home Improvement. Christophe Pettus PostgreSQL Experts, Inc. SCALE 14x, January 2016

JSON Home Improvement. Christophe Pettus PostgreSQL Experts, Inc. SCALE 14x, January 2016 JSON Home Improvement Christophe Pettus PostgreSQL Experts, Inc. SCALE 14x, January 2016 Greetings! Christophe Pettus CEO, PostgreSQL Experts, Inc. thebuild.com personal blog. pgexperts.com company website.

More information

Previously everyone in the class used the mysql account: Username: csci340user Password: csci340pass

Previously everyone in the class used the mysql account: Username: csci340user Password: csci340pass Database Design, CSCI 340, Spring 2016 SQL, Transactions, April 15 Previously everyone in the class used the mysql account: Username: csci340user Password: csci340pass Personal mysql accounts have been

More information

Introduction to Database Systems CSE 414. Lecture 26: More Indexes and Operator Costs

Introduction to Database Systems CSE 414. Lecture 26: More Indexes and Operator Costs Introduction to Database Systems CSE 414 Lecture 26: More Indexes and Operator Costs CSE 414 - Spring 2018 1 Student ID fname lname Hash table example 10 Tom Hanks Index Student_ID on Student.ID Data File

More information

Basic PHP. Lecture 19. Robb T. Koether. Hampden-Sydney College. Mon, Feb 26, 2108

Basic PHP. Lecture 19. Robb T. Koether. Hampden-Sydney College. Mon, Feb 26, 2108 Basic PHP Lecture 19 Robb T. Koether Hampden-Sydney College Mon, Feb 26, 2108 Robb T. Koether (Hampden-Sydney College) Basic PHP Mon, Feb 26, 2108 1 / 27 1 PHP 2 The echo Statement 3 Variables 4 Operators

More information

Efficient Object-Relational Mapping for JAVA and J2EE Applications or the impact of J2EE on RDB. Marc Stampfli Oracle Software (Switzerland) Ltd.

Efficient Object-Relational Mapping for JAVA and J2EE Applications or the impact of J2EE on RDB. Marc Stampfli Oracle Software (Switzerland) Ltd. Efficient Object-Relational Mapping for JAVA and J2EE Applications or the impact of J2EE on RDB Marc Stampfli Oracle Software (Switzerland) Ltd. Underestimation According to customers about 20-50% percent

More information

LABORATORY OF DATA SCIENCE. Data Access: Relational Data Bases. Data Science and Business Informatics Degree

LABORATORY OF DATA SCIENCE. Data Access: Relational Data Bases. Data Science and Business Informatics Degree LABORATORY OF DATA SCIENCE Data Access: Relational Data Bases Data Science and Business Informatics Degree RDBMS data access 2 Protocols and API ODBC, OLE DB, ADO, ADO.NET, JDBC Python DBAPI with ODBC

More information

Friday, 11 April 14. Advanced methods for creating decorators Graham Dumpleton PyCon US - April 2014

Friday, 11 April 14. Advanced methods for creating decorators Graham Dumpleton PyCon US - April 2014 Advanced methods for creating decorators Graham Dumpleton PyCon US - April 2014 Intermission Rant about the history of this talk and why this topic matters. Python decorator syntax @function_wrapper def

More information

Overview of Query Processing and Optimization

Overview of Query Processing and Optimization Overview of Query Processing and Optimization Source: Database System Concepts Korth and Silberschatz Lisa Ball, 2010 (spelling error corrections Dec 07, 2011) Purpose of DBMS Optimization Each relational

More information

SELECT Product.name, Purchase.store FROM Product JOIN Purchase ON Product.name = Purchase.prodName

SELECT Product.name, Purchase.store FROM Product JOIN Purchase ON Product.name = Purchase.prodName Announcements Introduction to Data Management CSE 344 Lectures 5: More SQL aggregates Homework 2 has been released Web quiz 2 is also open Both due next week 1 2 Outline Outer joins (6.3.8, review) More

More information

Database extensions for fun and profit. Andrew Dalke Andrew Dalke Scientific, AB Gothenburg, Sweden

Database extensions for fun and profit. Andrew Dalke Andrew Dalke Scientific, AB Gothenburg, Sweden Database extensions for fun and profit Andrew Dalke Andrew Dalke Scientific, AB Gothenburg, Sweden Set the Wayback Machine to 1997! Relational databases - strings and numbers - SQL - clients written in

More information

Project 4 Query Optimization Part 2: Join Optimization

Project 4 Query Optimization Part 2: Join Optimization Project 4 Query Optimization Part 2: Join Optimization 1 Introduction Out: November 7, 2017 During this semester, we have talked a lot about the different components that comprise a DBMS, especially those

More information

Databases in Python. MySQL, SQLite. Accessing persistent storage (Relational databases) from Python code

Databases in Python. MySQL, SQLite. Accessing persistent storage (Relational databases) from Python code Databases in Python MySQL, SQLite Accessing persistent storage (Relational databases) from Python code Goal Making some data 'persistent' When application restarts When computer restarts Manage big amounts

More information

Database Applications (15-415)

Database Applications (15-415) Database Applications (15-415) The Relational Model Lecture 3, January 18, 2015 Mohammad Hammoud Today Last Session: The entity relationship (ER) model Today s Session: ER model (Cont d): conceptual design

More information

Please pick up your name card

Please pick up your name card L06: SQL 233 Announcements! Please pick up your name card - always come with your name card - If nobody answers my question, I will likely pick on those without a namecard or in the last row Polls on speed:

More information

WELCOME CSCA20 REVIEW SEMINAR

WELCOME CSCA20 REVIEW SEMINAR WELCOME CSCA20 REVIEW SEMINAR Copyright 2018 Kara Autumn Jiang What is the difference between return() and print() - You can only return from inside a function. - Values that are returned can be saved

More information

HW1 is due tonight HW2 groups are assigned. Outline today: - nested queries and witnesses - We start with a detailed example! - outer joins, nulls?

HW1 is due tonight HW2 groups are assigned. Outline today: - nested queries and witnesses - We start with a detailed example! - outer joins, nulls? L05: SQL 183 Announcements! HW1 is due tonight HW2 groups are assigned Outline today: - nested queries and witnesses - We start with a detailed example! - outer joins, nulls? 184 Small IMDB schema (SQLite)

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

CSC 215 PROJECT 2 DR. GODFREY C. MUGANDA

CSC 215 PROJECT 2 DR. GODFREY C. MUGANDA CSC 215 PROJECT 2 DR. GODFREY C. MUGANDA 1. Project Overview In this project, you will create a PHP web application that you can use to track your friends. Along with personal information, the application

More information

1z Oracle Database SQL Expert

1z Oracle Database SQL Expert 1z0-047 Oracle Database SQL Expert Version 1.6 QUESTION NO: 1 Which three possible values can be set for the TIME_ZONE session parameter by using the ALTER SESSION command? (Choose three.) E. 'os' local

More information

Database Systems CSE 414

Database Systems CSE 414 Database Systems CSE 414 Lecture 10: Basics of Data Storage and Indexes 1 Reminder HW3 is due next Tuesday 2 Motivation My database application is too slow why? One of the queries is very slow why? To

More information

Essential SQLite3. Section Title Page

Essential SQLite3. Section Title Page One Introduction to SQL 2 Definition of SQL 3 Definition of a Database 4 Two Database Tables 5 Three The SQLite Interface 10 Introduction 11 Running SQLite 12 DOS commands 14 Copying and Pasting 17 Exiting

More information

Midterm 1: CS186, Spring I. Storage: Disk, Files, Buffers [11 points] cs186-

Midterm 1: CS186, Spring I. Storage: Disk, Files, Buffers [11 points] cs186- Midterm 1: CS186, Spring 2016 Name: Class Login: cs186- You should receive 1 double-sided answer sheet and an 11-page exam. Mark your name and login on both sides of the answer sheet, and in the blanks

More information

CMSC424: Database Design. Instructor: Amol Deshpande

CMSC424: Database Design. Instructor: Amol Deshpande CMSC424: Database Design Instructor: Amol Deshpande amol@cs.umd.edu Databases Data Models Conceptual representa1on of the data Data Retrieval How to ask ques1ons of the database How to answer those ques1ons

More information

Clojure. The Revenge of Data. by Vjeran Marcinko Kapsch CarrierCom

Clojure. The Revenge of Data. by Vjeran Marcinko Kapsch CarrierCom Clojure The Revenge of Data by Vjeran Marcinko Kapsch CarrierCom Data Processing is what we do Most programs receive, transform, search, and send data Data is raw, immutable information In its essence,

More information

Administrivia. Physical Database Design. Review: Optimization Strategies. Review: Query Optimization. Review: Database Design

Administrivia. Physical Database Design. Review: Optimization Strategies. Review: Query Optimization. Review: Database Design Administrivia Physical Database Design R&G Chapter 16 Lecture 26 Homework 5 available Due Monday, December 8 Assignment has more details since first release Large data files now available No class Thursday,

More information

CSC326 Persistent Programming i. CSC326 Persistent Programming

CSC326 Persistent Programming i. CSC326 Persistent Programming i CSC326 Persistent Programming ii REVISION HISTORY NUMBER DATE DESCRIPTION NAME 1.0 2011-09 JZ iii Contents 1 Agenda 1 2 Persistent Programming 1 3 File 1 4 File names and Path 2 5 Catching Exception

More information

SQL: Programming. Introduction to Databases CompSci 316 Fall 2018

SQL: Programming. Introduction to Databases CompSci 316 Fall 2018 SQL: Programming Introduction to Databases CompSci 316 Fall 2018 2 Announcements (Thu., Oct. 11) Dean Khary McGhee, Office of Student Conduct, speaks about the Duke Community Standard Project milestone

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

CS317 File and Database Systems

CS317 File and Database Systems CS317 File and Database Systems Lecture 3 Relational Model & Languages Part-1 September 7, 2018 Sam Siewert More Embedded Systems Summer - Analog, Digital, Firmware, Software Reasons to Consider Catch

More information

Announcements. What is Datalog? Why Do We Learn Datalog? Database Systems CSE 414. Midterm. Datalog. Lecture 13: Datalog (Ch

Announcements. What is Datalog? Why Do We Learn Datalog? Database Systems CSE 414. Midterm. Datalog. Lecture 13: Datalog (Ch Announcements Database Systems CSE 414 Lecture 13: Datalog (Ch 5.3 5.4) HW3 is due Tomorrow WQ4 moved to Sunday it will be useful review for the midterm finish it early if you have time Midterm on Friday,

More information

pybdg Documentation Release 1.0.dev2 Outernet Inc

pybdg Documentation Release 1.0.dev2 Outernet Inc pybdg Documentation Release 1.0.dev2 Outernet Inc April 17, 2016 Contents 1 Source code 3 2 License 5 3 Documentation 7 Python Module Index 15 i ii Bitloads, or bit payloads, are compact payloads containing

More information

GIS 4653/5653: Spatial Programming and GIS. More Python: Statements, Types, Functions, Modules, Classes

GIS 4653/5653: Spatial Programming and GIS. More Python: Statements, Types, Functions, Modules, Classes GIS 4653/5653: Spatial Programming and GIS More Python: Statements, Types, Functions, Modules, Classes Statement Syntax The if-elif-else statement Indentation and and colons are important Parentheses and

More information

Examples of Physical Query Plan Alternatives. Selected Material from Chapters 12, 14 and 15

Examples of Physical Query Plan Alternatives. Selected Material from Chapters 12, 14 and 15 Examples of Physical Query Plan Alternatives Selected Material from Chapters 12, 14 and 15 1 Query Optimization NOTE: SQL provides many ways to express a query. HENCE: System has many options for evaluating

More information

CSIT5300: Advanced Database Systems

CSIT5300: Advanced Database Systems CSIT5300: Advanced Database Systems L11: Physical Database Design Dr. Kenneth LEUNG Department of Computer Science and Engineering The Hong Kong University of Science and Technology Hong Kong SAR, China

More information

LECTURE 21. Database Interfaces

LECTURE 21. Database Interfaces LECTURE 21 Database Interfaces DATABASES Commonly, Python applications will need to access a database of some sort. As you can imagine, not only is this easy to do in Python but there is a ton of support

More information

Fundamentals of Database Systems

Fundamentals of Database Systems Fundamentals of Database Systems Assignment: 1 Due Date: 8th August, 2017 Instructions This question paper contains 15 questions in 5 pages. Q1: The users are allowed to access different parts of data

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

Oracle EXAM - 1Z Oracle Database SQL Expert. Buy Full Product.

Oracle EXAM - 1Z Oracle Database SQL Expert. Buy Full Product. Oracle EXAM - 1Z0-047 Oracle Database SQL Expert Buy Full Product http://www.examskey.com/1z0-047.html Examskey Oracle 1Z0-047 exam demo product is here for you to test the quality of the product. This

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

POSTGRESQL FOR PYTHONISTAS. Tuesday, 9 July 13

POSTGRESQL FOR PYTHONISTAS. Tuesday, 9 July 13 POSTGRESQL FOR PYTHONISTAS WHAT DO I DO? Working as a senior Python developer for Artirix. Building backend systems and services. Organiser of Python Glasgow. Maximising the Value of Content, Data & Information

More information

1 Lecture 5: Advanced Data Structures

1 Lecture 5: Advanced Data Structures L5 June 14, 2017 1 Lecture 5: Advanced Data Structures CSCI 1360E: Foundations for Informatics and Analytics 1.1 Overview and Objectives We ve covered list, tuples, sets, and dictionaries. These are the

More information