COGS 121 HCI Programming Studio. Week 03 - Tech Lecture

Similar documents
Chapter 4. Basic SQL. Copyright 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley

Chapter 4. Basic SQL. SQL Data Definition and Data Types. Basic SQL. SQL language SQL. Terminology: CREATE statement

EGCI 321: Database Systems. Dr. Tanasanee Phienthrakul

Slides by: Ms. Shree Jaswal

Copyright 2016 Ramez Elmasri and Shamkant B. Navathe

Basic SQL. Dr Fawaz Alarfaj. ACKNOWLEDGEMENT Slides are adopted from: Elmasri & Navathe, Fundamentals of Database Systems MySQL Documentation

Basic SQL. Basic SQL. Basic SQL

Outline. Textbook Chapter 6. Note 1. CSIE30600/CSIEB0290 Database Systems Basic SQL 2

CSIE30600 Database Systems Basic SQL 2. Outline

BASIC SQL CHAPTER 4 (6/E) CHAPTER 8 (5/E)

Introduction to SQL. ECE 650 Systems Programming & Engineering Duke University, Spring 2018

BASIC SQL CHAPTER 4 (6/E) CHAPTER 8 (5/E)

Chapter 8 SQL-99: Schema Definition, Basic Constraints, and Queries

ECE 650 Systems Programming & Engineering. Spring 2018

SQL (Structured Query Language)

SQL STRUCTURED QUERY LANGUAGE

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

SQL-99: Schema Definition, Basic Constraints, and Queries. Create, drop, alter Features Added in SQL2 and SQL-99

SQL DATA DEFINITION LANGUAGE

SQL: Data Definition Language

Chapter 8. Joined Relations. Joined Relations. SQL-99: Schema Definition, Basic Constraints, and Queries

CSEN 501 CSEN501 - Databases I

SQL DATA DEFINITION LANGUAGE

The Relational Model of Data (ii)

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

SQL DATA DEFINITION LANGUAGE

SQL. Copyright 2013 Ramez Elmasri and Shamkant B. Navathe

Principles of Data Management

CMPUT 291 File and Database Management Systems

The SQL database language Parts of the SQL language

COSC344 Database Theory and Applications. Lecture 5 SQL - Data Definition Language. COSC344 Lecture 5 1

Structured Query Language (SQL)

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

Chapter 3: Introduction to SQL. Chapter 3: Introduction to SQL

COSC344 Database Theory and Applications. Lecture 6 SQL Data Manipulation Language (1)

Chapter 3: Introduction to SQL

CSCC43H: Introduction to Databases. Lecture 4

WHAT IS SQL. Database query language, which can also: Define structure of data Modify data Specify security constraints

Introduction to Database Management Systems

D B M G. SQL language: basics. Managing tables. Creating a table Modifying table structure Deleting a table The data dictionary Data integrity

SQL Functionality SQL. Creating Relation Schemas. Creating Relation Schemas

QQ Group

DATABASE TECHNOLOGY - 1MB025

SQL Introduction. CS 377: Database Systems

CS2300: File Structures and Introduction to Database Systems

DATABASE DESIGN I - 1DL300

DATABASE TECHNOLOGY - 1MB025

Database design process

Introduction to Database Systems. Chapter 1. Instructor: . Database Management Systems, R. Ramakrishnan and J. Gehrke 1

DATABASTEKNIK - 1DL116

COSC 304 Introduction to Database Systems SQL DDL. Dr. Ramon Lawrence University of British Columbia Okanagan

SQL: DDL. John Ortiz Cs.utsa.edu

SQL Data Definition and Data Manipulation Languages (DDL and DML)

SQL Structured Query Language Introduction

Database Management Systems. Chapter 1

Lecture 3 SQL. Shuigeng Zhou. September 23, 2008 School of Computer Science Fudan University

Basic Structure Set Operations Aggregate Functions Null Values Nested Subqueries Derived Relations Views Modification of the Database Data Definition

SQL (Structured Query Language) Truong Tuan Anh CSE-HCMUT

Chapter 3: Introduction to SQL

SQL. Lecture 4 SQL. Basic Structure. The select Clause. The select Clause (Cont.) The select Clause (Cont.) Basic Structure.

DATABASE TECHNOLOGY. Spring An introduction to database systems

The SQL data-definition language (DDL) allows defining :

CPS510 Database System Design Primitive SYSTEM STRUCTURE

1) Introduction to SQL

Simple SQL. Peter Y. Wu. Dept of Computer and Information Systems Robert Morris University

Data Modelling and Databases. Exercise Session 7: Integrity Constraints

2.9 Table Creation. CREATE TABLE TableName ( AttrName AttrType, AttrName AttrType,... )

BBM371- Data Management. Lecture 1: Course policies, Introduction to DBMS

CS634 Architecture of Database Systems Spring Elizabeth (Betty) O Neil University of Massachusetts at Boston

CS2 Current Technologies Lecture 2: SQL Programming Basics

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

Lab # 4. Data Definition Language (DDL)

SQL. Char (30) can store ram, ramji007 or 80- b

UNIT III INTRODUCTION TO STRUCTURED QUERY LANGUAGE (SQL)

UFCEKG 20 2 : Data, Schemas and Applications

CSC Web Programming. Introduction to SQL

Database Management System

SQL language. Jaroslav Porubän, Miroslav Biňas, Milan Nosáľ (c)

SQL (Structured Query Language) Truong Tuan Anh CSE-HCMUT

More SQL: Complex Queries, Triggers, Views, and Schema Modification

SQL. SQL DDL Statements

Information Systems Engineering. SQL Structured Query Language DDL Data Definition (sub)language

CS 338 Basic SQL Part II

Page 1. Quiz 18.1: Flow-Control" Goals for Today" Quiz 18.1: Flow-Control" CS162 Operating Systems and Systems Programming Lecture 18 Transactions"

Introduction to Database Systems CS432. CS432/433: Introduction to Database Systems. CS432/433: Introduction to Database Systems

CGS 3066: Spring 2017 SQL Reference

SQL: The Query Language Part 1. Relational Query Languages

SQL: Data Definition Language. csc343, Introduction to Databases Diane Horton Fall 2017

Lab # 2. Data Definition Language (DDL) Eng. Alaa O Shama

Full file at

Relational Algebra and SQL

Review. The Relational Model. Glossary. Review. Data Models. Why Study the Relational Model? Why use a DBMS? OS provides RAM and disk

Comp 5311 Database Management Systems. 4b. Structured Query Language 3

After completing this unit, you should be able to: Define the terms

The Relational Model. Database Management Systems

MTAT Introduction to Databases

Database Technology. Topic 3: SQL. Olaf Hartig.

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

SQL: A COMMERCIAL DATABASE LANGUAGE. Data Change Statements,

CS275 Intro to Databases

Transcription:

COGS 121 HCI Programming Studio Week 03 - Tech Lecture

Housekeeping Assignment #1 extended to Monday night 11:59pm Assignment #2 to be released on Tuesday during lecture

Database Management Systems and SQL Week 03 - Tech Lecture

References and Acknowledgments https://pgexercises.com Prof. A. Vaisman ( U Toronto)

What Is a DBMS? A very large, integrated collection of data describing activities of organizations. Models real-world. Entities (e.g., students, courses) Relationships (e.g., Madonna is taking CS564) A Database Management System (DBMS) is a software package designed to store and manage databases.

Why Use a DBMS? Data independence and efficient access. Reduced application development time. Data integrity and security. Different users may access different data subsets. Uniform data administration. Concurrent access, recovery from crashes.

Describing Data: Data Models A data model is a collection of concepts and constructs for describing data. A schema is a description of a particular collection of data, using the a given data model. The relational model of data is the most widely used model today. Main concept: relation, basically a table with rows and columns. Every relation has a schema, which describes the columns, or fields.

The Relational Model (Introduction) Central construct: the RELATION : a set of records. Data is described through a SCHEMA specifying the name of the relation, and name and type of each field: Students(pid: string, name: string, login: string, age: integer, gpa:real) Actual data: instance of the relations : a set of tuples, v.g.: {<53666,Jones,jones@cs,18,3.4>, <53688,Smith,smith@ee,18,3.2>, <53650,Smith,jones@math,19,3.8>,...}

Example: University Database Conceptual schema: Students(pid: string, name: string, login: string, age: integer, gpa:real) Courses(cid: string, cname:string, credits:integer) Enrolled(pid:string, cid:string, grade:string) > describes data in terms of the data model of the DBMS Physical schema: Relations stored as unordered files. Index on first column of Students. External Schema (View): Course_info(pid:string,enrollment:integer)

Querying a DBMS A DBMS provides a Query Language. Query languages allow querying and updating a DBMS in a simple way. Most popular DML (Data Manipulation Language) : SQL(Structured Query Language). Queries: List the name of student with pid=a0967546 Name and age of students enrolled in COGS121

Basic SQL SQL language Considered one of the major reasons for the commercial success of relational databases SQL Structured Query Language Statements for data definitions, queries, and updates (both DDL and DML) Core specification Plus specialized extensions

SQL Data Definition and Data Types Terminology: Table, row, and column used for relational model terms relation, tuple, and attribute CREATE statement Main SQL command for data definition

SQL schema Schema and Catalog Concepts in SQL Identified by a schema name Includes an authorization identifier and descriptors for each element Schema elements include Tables, constraints, views, domains, and other constructs Each statement in SQL ends with a semicolon

Attribute Data Types and Domains in SQL Basic data types Numeric data types Integer numbers: INTEGER, INT, and SMALLINT Floating-point (real) numbers: FLOAT or REAL, and DOUBLE PRECISION Character-string data types Fixed length: CHAR(n), CHARACTER(n) Varying length: VARCHAR(n), CHAR VARYING(n), CHARACTER VARYING(n)

Attribute Data Types and Domains in SQL Bit-string data types Fixed length: BIT(n) Varying length: BIT VARYING(n) Boolean data type Values of TRUE or FALSE or NULL DATE data type Ten positions Components are YEAR, MONTH, and DAY in the form YYYY-MM- DD

Attribute Data Types and Domains in SQL Additional data types Timestamp data type (TIMESTAMP) Includes the DATE and TIME fields Plus a minimum of six positions for decimal fractions of seconds Optional WITH TIME ZONE qualifier INTERVAL data type Specifies a relative value that can be used to increment or decrement an absolute value of a date, time, or timestamp

Specifying Key and Referential Integrity Constraints PRIMARY KEY clause Specifies one or more attributes that make up the primary key of a relation Dnumber INT PRIMARY KEY; UNIQUE clause Specifies alternate (secondary) keys Dname VARCHAR(15) UNIQUE;

Specifying Key and Referential Integrity Constraints (cont d.) FOREIGN KEY clause Default operation: reject update on violation Attach referential triggered action clause Options include SET NULL, CASCADE, and SET DEFAULT Action taken by the DBMS for SET NULL or SET DEFAULT is the same for both ON DELETE and ON UPDATE CASCADE option suitable for relationship relations

Query Languages Employee Department Name Dept Dept Manager SQL SELECT Manager FROM Employee, Department WHERE Employee.name = "Clark Kent AND Employee.Dept = Department.Dept

The SELECT-FROM-WHERE Structure of Basic SQL Queries Basic form of the SELECT statement: SELECT FROM WHERE <attribute list> <table list> <condition>; where <attribute list> is a list of attribute names whose values are to be retrieved by the query. <table list> is a list of the relation names required to process the query. <condition> is a conditional (Boolean) expression that identifies the tuples to be retrieved by the query.

The SELECT-FROM-WHERE Structure of Basic SQL Queries (cont d.) Logical comparison operators =, <, <=, >, >=, and <> Projection attributes Attributes whose values are to be retrieved Selection condition Boolean condition that must be true for any retrieved tuple

Unspecified WHERE Clause and Use of the Asterisk Missing WHERE clause Indicates no condition on tuple selection CROSS PRODUCT All possible tuple combinations

Unspecified WHERE Clause and Use of the Asterisk Specify an asterisk (*) Retrieve all the attribute values of the selected tuples

Ordering of Query Results Use ORDER BY clause Keyword DESC to see result in a descending order of values Keyword ASC to specify ascending order explicitly ORDER BY D.Dname DESC, E.Lname ASC, E.Fname ASC

Substring Pattern Matching and Arithmetic Operators LIKE comparison operator Used for string pattern matching % replaces an arbitrary number of zero or more characters underscore (_) replaces a single character Standard arithmetic operators: Addition (+), subtraction ( ), multiplication (*), and division (/) BETWEEN comparison operator

Aggregate Functions in SQL Used to summarize information from multiple tuples into a single-tuple summary Grouping Create subgroups of tuples before summarizing Built-in aggregate functions COUNT, SUM, MAX, MIN, and AVG Functions can be used in the SELECT clause or in a HAVING clause

Grouping: The GROUP BY and HAVING Clauses Partition relation into subsets of tuples Based on grouping attribute(s) Apply function to each such group independently GROUP BY clause Specifies grouping attributes If NULLs exist in grouping attribute Separate group created for all tuples with a NULL value in grouping attribute

INSERT, DELETE, and UPDATE Statements in SQL Three commands used to modify the database: INSERT, DELETE, and UPDATE

The INSERT Command Specify the relation name and a list of values for the tuple

The DELETE Command Removes tuples from a relation Includes a WHERE clause to select the tuples to be deleted

The UPDATE Command Modify attribute values of one or more selected tuples Additional SET clause in the UPDATE command Specifies attributes to be modified and new values

Let s Play Download and Install PGAdmin > http://www.postgresql.org/ftp/pgadmin3/release/v1.22.0/ Setup two databases Tournament host: ticino.ucsd.edu, port: 5432, database: cogs121 username: cogs121, password sql4cogs121, schema: cd DELPHI: host:delphidata.ucsd.edu, port: 5432, database: delphibetadb username: cogs121_16_user, password mch8yjs_n#2(xp, schema: cogs121_16_raw

username: cogs121 password sql4cogs121 schema: cd username: cogs121_16_user, password mch8yjs_n#2(xp, schema: cogs121_16_raw

pgadmin Demo

TopHat Attendance

TopHat Tournament