603 Database Systems Senior Lecturer: Laurie Webster II, M.S.S.E.,M.S.E.E., M.S.BME, Ph.D., P.E. Lecture 18 A First Course in Database Systems.

Slides:



Advertisements
Similar presentations
SQL Group Members: Shijun Shen Xia Tang Sixin Qiang.
Advertisements

SQL Queries Principal form: SELECT desired attributes FROM tuple variables –– range over relations WHERE condition about tuple variables; Running example.
Database Modifications CIS 4301 Lecture Notes Lecture /30/2006.
Winter 2002Arthur Keller – CS 1806–1 Schedule Today: Jan. 22 (T) u SQL Queries. u Read Sections Assignment 2 due. Jan. 24 (TH) u Subqueries, Grouping.
SQL CSET 3300.
Database Modifications, Data Types, Views. Database Modifications A modification command does not return a result as a query does, but it changes the.
Database Modifications, Data Types, Views. Database Modifications A modification command does not return a result as a query does, but it changes the.
Subqueries Example Find the name of the producer of ‘Star Wars’.
IS698: Database Management Min Song IS NJIT. Overview  Query processing  Query Optmization  SQL.
Fall 2001Arthur Keller – CS 1808–1 Schedule Today Oct. 18 (TH) Schemas, Views. u Read Sections u Project Part 3 extended to Oct. 23 (T). Oct.
Winter 2002Arthur Keller – CS 1808–1 Schedule Today: Jan. 29 (T) u Modifications, Schemas, Views. u Read Sections Assignment 3 due. Jan. 31 (TH)
SQL. 1.SQL is a high-level language, in which the programmer is able to avoid specifying a lot of data-manipulation details that would be necessary in.
CMSC424: Database Design Instructor: Amol Deshpande
SQL SQL is a very-high-level language, in which the programmer is able to avoid specifying a lot of data-manipulation details that would be necessary in.
Database Modifications A modification command does not return a result as a query does, but it changes the database in some way. There are three kinds.
Joins Natural join is obtained by: R NATURAL JOIN S; Example SELECT * FROM MovieStar NATURAL JOIN MovieExec; Theta join is obtained by: R JOIN S ON Example.
CPSC-608 Database Systems Fall 2008 Instructor: Jianer Chen Office: HRBB 309B Phone: Notes #3.
CPSC-608 Database Systems Fall 2011 Instructor: Jianer Chen Office: HRBB 315C Phone: Notes #2.
SQL 2014, Fall Pusan National University Ki-Joune Li These slides are made from the materials that Prof. Jeffrey D. Ullman distributes via his course web.
CSCE 520- Relational Data Model Lecture 2. Relational Data Model The following slides are reused by the permission of the author, J. Ullman, from the.
SCUHolliday6–1 Schedule Today: u SQL Queries. u Read Sections Next time u Subqueries, Grouping and Aggregation. u Read Sections And then.
Databases : SQL-Introduction 2007, Fall Pusan National University Ki-Joune Li These slides are made from the materials that Prof. Jeffrey D. Ullman distributes.
Constraints on Relations Foreign Keys Local and Global Constraints Triggers Following lecture slides are modified from Jeff Ullman’s slides
Winter 2006Keller, Ullman, Cushing9–1 Constraints Commercial relational systems allow much more “fine-tuning” of constraints than do the modeling languages.
SQL 2015, Fall Pusan National University Ki-Joune Li These slides are made from the materials that Prof. Jeffrey D. Ullman distributes via his course web.
Introduction to Data Manipulation in SQL CIS 4301 Lecture Notes Lecture /03/2006.
Introduction to Indexes. Indexes An index on an attribute A of a relation is a data structure that makes it efficient to find those tuples that have a.
Computational Biology Dr. Jens Allmer Lecture Slides Week 6.
SCUHolliday - coen 1788–1 Schedule Today u Modifications, Schemas, Views. u Read Sections (except and 6.6.6) Next u Constraints. u Read.
603 Database Systems Senior Lecturer: Laurie Webster II, M.S.S.E.,M.S.E.E., M.S.BME, Ph.D., P.E. Lecture 17 A First Course in Database Systems.
1 Database Systems Defining Database Schema Views.
Databases 1 Second lecture.
1 More SQL uDatabase Modification uDefining a Database Schema uViews.
Referential Integrity checks, Triggers and Assertions Examples from Chapter 7 of Database Systems: the Complete Book Garcia-Molina, Ullman, & Widom.
Advanced SQL Concepts - Checking of Constraints CIS 4301 Lecture Notes Lecture /6/2006.
© D. Wong Normalization  Purpose: process to eliminate redundancy in relations due to functional or multi-valued dependencies.  Decompose relation.
603 Database Systems Senior Lecturer: Laurie Webster II, M.S.S.E.,M.S.E.E., M.S.BME, Ph.D., P.E. Lecture 10 A First Course in Database Systems.
1 Introduction to SQL Database Systems. 2 Why SQL? SQL is a very-high-level language, in which the programmer is able to avoid specifying a lot of data-manipulation.
Himanshu GuptaCSE 532-SQL-1 SQL. Himanshu GuptaCSE 532-SQL-2 Why SQL? SQL is a very-high-level language, in which the programmer is able to avoid specifying.
603 Database Systems Senior Lecturer: Laurie Webster II, M.S.S.E.,M.S.E.E., M.S.BME, Ph.D., P.E. Lecture 11 A First Course in Database Systems.
603 Database Systems Senior Lecturer: Laurie Webster II, M.S.S.E.,M.S.E.E., M.S.BME, Ph.D., P.E. Lecture 9 A First Course in Database Systems.
SQL Exercises – Part I April
Databases : SQL-Schema Definition and View 2007, Fall Pusan National University Ki-Joune Li These slides are made from the materials that Prof. Jeffrey.
The Relational Model of Data Prof. Yin-Fu Huang CSIE, NYUST Chapter 2.
The Database Language SQL Prof. Yin-Fu Huang CSIE, NYUST Chapter 6.
603 Database Systems Senior Lecturer: Laurie Webster II, M.S.S.E.,M.S.E.E., M.S.BME, Ph.D., P.E. Lecture 20 A First Course in Database Systems.
Databases : SQL Multi-Relations 2007, Fall Pusan National University Ki-Joune Li These slides are made from the materials that Prof. Jeffrey D. Ullman.
1 Constraints and Triggers in SQL. 2 Constraints are conditions that must hold on all valid relation instances SQL2 provides a variety of techniques for.
CPSC-310 Database Systems
A First Course in Database Systems
CPSC-310 Database Systems
Introduction to Structured Query Language (SQL)
THE RELATIONAL MODEL OF DATA
Introduction to Database Systems, CS420
CPSC-608 Database Systems
CPSC-608 Database Systems
Database Models Relational Model
CPSC-310 Database Systems
2018, Fall Pusan National University Ki-Joune Li
SQL OVERVIEW DEFINING A SCHEMA
2018, Fall Pusan National University Ki-Joune Li
2018, Fall Pusan National University Ki-Joune Li
Defining a Database Schema
CS4433 Database Systems SQL - Basics.
SQL – Constraints & Triggers
CPSC-608 Database Systems
CPSC-608 Database Systems
CMSC-461 Database Management Systems
Instructor: Zhe He Department of Computer Science
2019, Fall Pusan National University Ki-Joune Li
Presentation transcript:

603 Database Systems Senior Lecturer: Laurie Webster II, M.S.S.E.,M.S.E.E., M.S.BME, Ph.D., P.E. Lecture 18 A First Course in Database Systems

SQL Defining a Database Schema: CREATE TABLE name (list of elements). *Principal elements are attributes and their types, but key declarations and constraints also appear. *Similar CREATE X commands for other schema elements X: views, indexes, assertions, triggers.

SQL *“DROP X name” deletes the created element of kind X with that name Example: CREATE TABLE Sells ( bar CHAR (20), beer VARCHAR (20) price REAL ) ; DROP TABLE Sells;

SQL SQL includes some features from relational algebra but is based largely on TRC. Request: Get the first and last names of employees with Salaries greater than $50,000. TRC: {t.FNAME, t.LNAME | EMPLOYEE (t) and t.SALARY > $50,000} SQL: SELECTT.FNAME, T.LNAME FROMEMPLOYEE AS T WHERET.SALARY > 50,000 ;

SQL As a language, SQL has two major components: 1) DDL (Data Definition Language) to define the database structure 2) DML (Data Manipulation Language) for retrieving and updating data

SQL SQL: SELECTT.FNAME, T.LNAME FROMEMPLOYEE AS T WHERET.SALARY > 50,000 ; SELECT ==> extremely powerful command capable of performing the equivalent of the following three relational algebra statements in a single statement! 1. Selection 2. Projection 3. Join

SQL SQL Syntax: CREATE TABLE ( [NOT NULL] {, [NOT NULL]}) DROP TABLE. DROP VIEW

SQL SQL Queries: *Principal form: SELECTdesired attributes FROMtuple variables - range over relations WHEREcondition about tuple variables

SQL Example Database Schema: Beers (name, manf) Bars (name, addr, license) Drinkers (name, addr, phone) Likes (drinker, beer) Sells (bar, beer, price) Frequents (drinker, bar)

SQL Query: What beers are made by Anheuser-Busch? Beers ( name, manf) SELECTname FROMBeers WHEREmanf = ‘Anheuser-Busch’ ; Bud Bud Lite Michelob name Resulting Relation Note single quotes for strings

SQL SELECT* FROMBeers WHEREmanf = ‘Anheuser-Busch’ ; namemanf BudAnheuser-Busch Bud LiteAnheuser-Busch MichelobAnheuser-Busch * yields all of the attributes of Beers

The Database Language SQL Renaming Columns: Beers ( name, manf) SELECTname AS beer FROMBeers WHEREmanf = ‘Anheuser-Busch’ ; beer Bud Bud Lite Michelob Column label ‘name’ changed to ‘beer’

SQL Language Simple Queries in SQL: Perhaps the simplest form of query in SQL asks for those tuples of some one relation that satisfy a condition. Database Schema below about movies: Movie(title, year, length, inColor, studioName, producerC#) StarsIn(movieTitle, movieYear, starName) MovieExec(name, address, cert#, netWorth) Studio(name, address, presC#)

SQL Language Query (SQL): Ask about the relation Movie for all movies produced by Disney Studios in SELECT* FROMMovie WHEREstudioName = ‘Disney’ AND year = 1990 ; FROM clause ==> relation or relations to which the query refers. In our example, the query is about the relation Movie.

SQL SELECT* FROMMovie WHEREstudioName = ‘Disney’ AND year = 1990 ; WHERE clause ==> is a condition, much like the selection- condition in relational algebra. Tuples must satisfy the condition in order to match the query. studioName attribute has value ‘Disney’ year attribute has value 1990 Both must be TRUE Tuples with all attributes

SQL SELECT* FROMMovie WHEREstudioName = ‘Disney’ AND year = 1990 ; The result of the query is the Movie tuples for those movies produced by Disney in 1990, for example, Pretty Woman. title yearlength inColor studioName producerC# Pretty Women true Disney 999

SQL Projection (  ) in SQL: SELECTtitle, length FROMMovie WHEREstudioName = ‘Disney’ AND year = 1990 ; The results of this query is the table with two columns: titlelength Pretty Woman

SQL SELECTtitle, length FROMMovie WHEREstudioName = ‘Disney’ AND year = 1990 ; We can modify this query to produce a relation with attributes name and duration in place of title and length as follows: SELECTtitle AS name, length AS duration FROMMovie WHEREstudioName = ‘Disney’ AND year = 1990 ;

SQL SELECTtitle AS name, length AS duration FROMMovie WHEREstudioName = ‘Disney’ AND year = 1990 ; Results: nameduration Pretty Woman119

SQL SELECT title AS name, length* AS lengthInHours FROM Movie WHERE studioName = ‘Disney’ AND year = 1990 ; Results: name lengthInHours Pretty Woman 1

SQL SELECT title AS name, length* AS lengthInHours FROM Movie WHERE studioName = ‘Disney’ AND year = 1990 ; We allow constants as expressions in SELECT: SELECT title, length* AS length, ‘hrs.’ AS inHours FROM Movie WHERE studioName = ‘Disney’ AND year = 1990 ;

SQL SELECT title, length* AS length, ‘hrs.’ AS inHours FROM Movie WHERE studioName = ‘Disney’ AND year = 1990 ; Results: name length inHours Pretty Woman hrs.

SQL Next Lecture MORE SQL