Big Data Yuan Xue CS 292 Special topics on.

Slides:



Advertisements
Similar presentations
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 5 More SQL: Complex Queries, Triggers, Views, and Schema Modification.
Advertisements

SQL Rohit Khokher.
COMP 3715 Spring 05. Working with data in a DBMS Any database system must allow user to  Define data Relations Attributes Constraints  Manipulate data.
Database Design -- Basic SQL
Database Systems: Design, Implementation, and Management Tenth Edition
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 5 More SQL: Complex Queries, Triggers, Views, and Schema Modification.
Introduction to Structured Query Language (SQL)
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 4 SQL: Data Definition, Constraints, and Basic Queries and Updates.
Introduction to Structured Query Language (SQL)
CSE 190: Internet E-Commerce Lecture 10: Data Tier.
Structured query language This is a presentation by JOSEPH ESTRada on the beauty of Structured Query Language.
CS 104 Introduction to Computer Science and Graphics Problems Introduction to Database (2) Basic SQL 12/05/2008 Yang Song.
Fundamentals, Design, and Implementation, 9/e Chapter 6 Introduction to Structured Query Language (SQL)
Murali Mani SQL DDL and Oracle utilities. Murali Mani Datatypes in SQL INT (or) INTEGER FLOAT (or) REAL DECIMAL (n, m) CHAR (n) VARCHAR (n) DATE, TIME.
Database Systems More SQL Database Design -- More SQL1.
Introduction to Structured Query Language (SQL)
Database Systems: Design, Implementation, and Management Eighth Edition Chapter 7 Introduction to Structured Query Language (SQL)
Jennifer Widom SQL Introduction. Jennifer Widom SQL: Intro  “S.Q.L.” or “sequel”  Supported by all major commercial database systems  Standardized.
Chapter 7: SQL, the Structured Query Language Soid Quintero & Ervi Bongso CS157B.
DATABASES AND SQL. Introduction Relation: Relation means table(data is arranged in rows and columns) Domain : A domain is a pool of values appearing in.
Chapter 3: SQL Data Definition Language Data Definition Language Basic Structure of SQL Basic Structure of SQL Set Operations Set Operations Aggregate.
SQL Basics. SQL SQL (Structured Query Language) is a special-purpose programming language designed from managing data in relational database management.
Introduction to SQL J.-S. Chou Assistant Professor.
Chapter 5 Introduction to SQL. Structured Query Language = the “programming language” for relational databases SQL is a nonprocedural language = the user.
CSE314 Database Systems Lecture 4 Basic SQL Doç. Dr. Mehmet Göktürk src: Elmasri & Navanthe 6E Pearson Ed Slide Set.
AL-MAAREFA COLLEGE FOR SCIENCE AND TECHNOLOGY INFO 232: DATABASE SYSTEMS CHAPTER 7 INTRODUCTION TO STRUCTURED QUERY LANGUAGE (SQL) Instructor Ms. Arwa.
CSE314 Database Systems More SQL: Complex Queries, Triggers, Views, and Schema Modification Doç. Dr. Mehmet Göktürk src: Elmasri & Navanthe 6E Pearson.
Constraints  Constraints are used to enforce rules at table level.  Constraints prevent the deletion of a table if there is dependencies.  The following.
CS 3630 Database Design and Implementation. Your Oracle Account UserName is the same as your UWP username Followed Not case sensitive Initial.
Chapter 8 Part 1 SQL-99 Schema Definition, Constraints, Queries, and Views.
SQL SQL Server : Overview SQL : Overview Types of SQL Database : Creation Tables : Creation & Manipulation Data : Creation & Manipulation Data : Retrieving.
7 1 Chapter 7 Introduction to Structured Query Language (SQL) Database Systems: Design, Implementation, and Management, Seventh Edition, Rob and Coronel.
Nitin Singh/AAO RTI ALLAHABAD 1 SQL Nitin Singh/AAO RTI ALLAHABAD 2 OBJECTIVES §What is SQL? §Types of SQL commands and their function §Query §Index.
6 1 Lecture 8: Introduction to Structured Query Language (SQL) J. S. Chou, P.E., Ph.D.
BIS Database Systems School of Management, Business Information Systems, Assumption University A.Thanop Somprasong Chapter # 7 Introduction to Structured.
Database Systems Design, Implementation, and Management Coronel | Morris 11e ©2015 Cengage Learning. All Rights Reserved. May not be scanned, copied or.
SQL Basics. What is SQL? SQL stands for Structured Query Language. SQL lets you access and manipulate databases.
Database Management COP4540, SCS, FIU Structured Query Language (Chapter 8)
Database Systems: Design, Implementation, and Management Eighth Edition Chapter 7 Introduction to Structured Query Language (SQL)
Advanced Database CS-426 Week 1 - Introduction. Database Management System DBMS contains information about a particular enterprise Collection of interrelated.
Carnegie Mellon Carnegie Mellon Univ. Dept. of Computer Science Database Applications C. Faloutsos Rel. model - SQL part3.
Prince Sultan University Dept. of Computer & Information Sciences CS 340 Introduction to Database Systems.
Visual Programing SQL Overview Section 1.
AL-MAAREFA COLLEGE FOR SCIENCE AND TECHNOLOGY INFO 232: DATABASE SYSTEMS CHAPTER 7 (Part II) INTRODUCTION TO STRUCTURED QUERY LANGUAGE (SQL) Instructor.
1/18/00CSE 711 data mining1 What is SQL? Query language for structural databases (esp. RDB) Structured Query Language Originated from Sequel 2 by Chamberlin.
CMPT 258 Database Systems The Relationship Model (Chapter 3)
Mining real world data RDBMS and SQL. Index RDBMS introduction SQL (Structured Query language)
1 CS 430 Database Theory Winter 2005 Lecture 10: Introduction to SQL.
1 MySQL and SQL. 2 Topics  Introducing Relational Databases  Terminology  Managing Databases MySQL and SQL.
Oracle & SQL. Oracle Data Types Character Data Types: Char(2) Varchar (20) Clob: large character string as long as 4GB Bolb and bfile: large amount of.
الفصل السادس لغة Structured Query Language) SQL الفصل السادس لغة Structured Query Language) SQL.
7 1 Database Systems: Design, Implementation, & Management, 7 th Edition, Rob & Coronel 7.6 Advanced Select Queries SQL provides useful functions that.
LM 5 Introduction to SQL MISM 4135 Instructor: Dr. Lei Li.
Big Data Yuan Xue CS 292 Special topics on.
Big Data Yuan Xue CS 292 Special topics on.
SQL, the Structured Query Language
More SQL: Complex Queries, Triggers, Views, and Schema Modification
More SQL: Complex Queries,
CS 3630 Database Design and Implementation
Chapter 5 Introduction to SQL.
CS 480: Database Systems Lecture 13 February 13,2013.
SQL: Advanced Options, Updates and Views Lecturer: Dr Pavle Mogin
SQL Introduction.
More SQL: Complex Queries, Triggers, Views, and Schema Modification
Database systems Lecture 3 – SQL + CRUD
Chapter 7 Introduction to Structured Query Language (SQL)
C1. SQL BAsic.
Session - 6 Sequence - 1 SQL: The Structured Query Language:
Contents Preface I Introduction Lesson Objectives I-2
SQL (Structured Query Language)
Presentation transcript:

Big Data Yuan Xue CS 292 Special topics on

Part I Relational Database (SQL) Yuan Xue

Creating and Using a Relational Database  Steps in creating and using a (relational) database 1. Design schema (using DDL – data definition language) 2. Initialization: “Bulk load” initial data 3. Operation: execute queries and modifications (using DML – data manipulation language) Data Meta-data: database definition

SQL Introduction  Programming language for data management in a relational database management system(RDBMS)  Both Data Definition Language (DDL) and Data Manipulation Language (DML)  DDL: create, drop table  DML: query (select), insert, update and delete data from table  Standardized and supported by all major commercial database systems  One of the major reasons for commercial success of RDBMS  Interactive via GUI or command line, or embedded in programs

Data Definition in SQL

CREATE in SQL CREATE TABLE MiniTwitter.User (IDVARCHAR(20)NOT NULL, NameVARCHAR(20)NOT NULL, … PRIMARY KEY (ID) FOREIGN KEY (ID) REFERENCE Follow(Followee) FOREIGN KEY (ID) REFERENCE Follow(Follower) ); User IDName Password Aadf1234 com qwer6789 CREATE SCHEMA MiniTwitter; FolloweeFollowerTimestamp Alice00Bob Bob2013Cathy Alice00Cathy Cathy123Alice Bob2013Alice Follow

CREATE in SQL  Data types in SQL  Numeric  INT, FLOAT, DEC  Character, or String  CHAR, VARCHAR  Bit-string  BIT, BLOB (binary large object)  Boolean  Date, Time  DATE, TIME, TIMESTAMP CREATE TABLE MiniTwitter.Tweet (IDVARCHAR(20)NOT NULL, TimestampTIMESTAMPNOT NULL, … PRIMARY KEY (ID) ); Tweet IDTimestampAuthorContent Alice00Hello Bob2013Nice weather Not sure..

CREATE in SQL CREATE TABLE MiniTwitter.Follow (FolloweeVARCHAR(20)NOT NULL, FollowerVARCHAR(20)NOT NULL, TimestampTIMESTAMPNOT NULL, PRIMARY KEY (Followee, Follower) ); FolloweeFollowerTimestamp Alice00Bob Bob2013Cathy Alice00Cathy Cathy123Alice Bob2013Alice Follow

Data Manipulation in SQL

SELECT in SQL  SELECT-FROM-WHERE structure of basic SQL queries SELECT A 1, A 2,…,A n FROM R 1, R 2,…,R m WHERE Condition; Attribute to return Relationship/table Conditional expression

Example  Retrieve the timestamp and content of all tweets whose author is “alice00” User Tweet Follow IDName Password Aadf1234 com qwer6789 IDTimestampAuthorContent Alice00Hello Bob2013Nice weather Not sure.. FolloweeFollowerTimestamp Alice00Bob Bob2013Cathy Alice00Cathy Cathy123Alice Bob2013Alice

Example IDName Password Aadf1234 com qwer6789 IDTimestampAuthorContent Alice00Hello Bob2013Nice weather Not sure.. User Tweet FolloweeFollowerTimestamp Alice00Bob Bob2013Cathy Alice00Cathy Cathy123Alice Bob2013Alice Follow SELECT Timestamp, Content FROM Tweet WHERE Author = ‘Alice00’; Select condition

Example  Retrieve the content of all tweets whose author is followed by “Alice00” User Tweet Follow IDName Password Aadf1234 com qwer6789 IDTimestampAuthorContent Alice00Hello Bob2013Nice weather Not sure.. FolloweeFollowerTimestamp Alice00Bob Bob2013Cathy Alice00Cathy Cathy123Alice Bob2013Alice

Example IDName Password Aadf1234 com qwer6789 IDTimestampAuthorContent Alice00Hello Bob2013Nice weather Not sure.. User Tweet FolloweeFollowerTimestamp Alice00Bob Bob2013Cathy Alice00Cathy Cathy123Alice Bob2013Alice Follow SELECT content FROM Tweet, Follow WHERE Follower = ‘Alice00’ AND Author = Follower; Select condition Join condition Select-project-join query

Example  Retrieve the timestamp and content of all tweets whose author is followed by “Alice00” User Tweet Follow IDName Password Aadf1234 com qwer6789 IDTimestampAuthorContent Alice00Hello Bob2013Nice weather Not sure.. FolloweeFollowerTimestamp Alice00Bob Bob2013Cathy Alice00Cathy Cathy123Alice Bob2013Alice Qualify the attribute name to prevent ambiguity

Example IDName Password Aadf1234 com qwer6789 IDTimestampAuthorContent Alice00Hello Bob2013Nice weather Not sure.. User Tweet FolloweeFollowerTimestamp Alice00Bob Bob2013Cathy Alice00Cathy Cathy123Alice Bob2013Alice Follow SELECT Tweet.Timestamp, Content FROM Tweet, Follow WHERE Follower = ‘Alice00’ AND Author = Follower; Select condition Join condition

Aggregate Functions in SQL  Aggregate function: summarize information from multiple tuples  Basic aggregate operations in SQL  COUNT, SUM, MAX, MIN, AVG  Retrieve the number of people that “Alice00” is following  Retrieve the number of people who are following “Alice00”

Aggregate Functions in SQL  Aggregate function: summarize information from multiple tuples  Basic aggregate operations in SQL  COUNT, SUM, MAX, MIN, AVG SELECT COUNT(*) FROM Follow WHERE Follower = ‘Alice00’;  Retrieve the number of people that “Alice00” is following SELECT COUNT(*) FROM Follow WHERE Followee = ‘Alice00’;  Retrieve the number of people who are following “Alice00”

Nested SQL query  Show the names of users with more than 10 followers User Tweet Follow IDName Password Aadf1234 com qwer6789 IDTimestampAuthorContent Alice00Hello Bob2013Nice weather Not sure.. FolloweeFollowerTimestamp Alice00Bob Bob2013Cathy Alice00Cathy Cathy123Alice Bob2013Alice

Nested SQL query User Tweet Follow IDName Password Aadf1234 com qwer6789 IDTimestampAuthorContent Alice00Hello Bob2013Nice weather Not sure.. FolloweeFollowerTimestamp Alice00Bob Bob2013Cathy Alice00Cathy Cathy123Alice Bob2013Alice SELECT Name FROM User WHERE (SELECT COUNT (*) FROM Follow WHERE Followee = ID)>10);

GROUP in SQL  Show the names of all users with the number of tweets from them User Tweet Follow IDName Password Aadf1234 com qwer6789 IDTimestampAuthorContent Alice00Hello Bob2013Nice weather Not sure.. FolloweeFollowerTimestamp Alice00Bob Bob2013Cathy Alice00Cathy Cathy123Alice Bob2013Alice

GROUP in SQL User Tweet Follow IDName Password Aadf1234 com qwer6789 IDTimestampAuthorContent Alice00Hello Bob2013Nice weather Not sure.. FolloweeFollowerTimestamp Alice00Bob Bob2013Cathy Alice00Cathy Cathy123Alice Bob2013Alice SELECT User.Name, COUNT(Tweet.ID) FROM User, Tweet WHERE User.ID = Tweet.Author GROUP BY Tweet.Author;

ORDER BY in SQL  Show the names of users who follow “Alice00” based on the time of “following” relationship User Tweet Follow IDName Password Aadf1234 com qwer6789 IDTimestampAuthorContent Alice00Hello Bob2013Nice weather Not sure.. FolloweeFollowerTimestamp Alice00Bob Bob2013Cathy Alice00Cathy Cathy123Alice Bob2013Alice

ORDER BY in SQL User Tweet Follow IDName Password Aadf1234 com qwer6789 IDTimestampAuthorContent Alice00Hello Bob2013Nice weather Not sure.. FolloweeFollowerTimestamp Alice00Bob Bob2013Cathy Alice00Cathy Cathy123Alice Bob2013Alice SELECT User.Name, FROM User, Follow WHERE User.ID = Follow.Follower AND Follow.Followee = “Alice00” ORDER BY Follow.Timestamp;

INSERT in SQL INSERT INTO Follow VALUES (“Cathy123”, “Bob2013”, ) ; Follow FolloweeFollowerTimestamp Alice00Bob Bob2013Cathy Alice00Cathy Cathy123Alice Bob2013Alice Cathy123Bob Follow FolloweeFollowerTimestamp Alice00Bob Bob2013Cathy Alice00Cathy Cathy123Alice Bob2013Alice

DELETE in SQL DELETE FROM Follow WHERE Followee = ‘Alice00’ AND FOllower = ‘Bob2013’; Follow FolloweeFollowerTimestamp Alice00Bob Bob2013Cathy Alice00Cathy Cathy123Alice Bob2013Alice Follow FolloweeFollowerTimestamp Bob2013Cathy Alice00Cathy Cathy123Alice Bob2013Alice

UPDATE in SQL UPDATE Follow SET Timestamp = ‘ ’ WHERE Followee = ‘Alice00’ AND Follower = ‘Bob2013’; Follow FolloweeFollowerTimestamp Alice00Bob Bob2013Cathy Alice00Cathy Cathy123Alice Bob2013Alice Follow FolloweeFollowerTimestamp Alice00Bob Bob2013Cathy Alice00Cathy Cathy123Alice Bob2013Alice

More on SQL  Drop table  Outer Join  Indexes, Constraints, Views, Triggers, Transactions, Authorization  Substring Pattern Matching and Arithmetic Operators Check out: