1 SY306 Web and Databases for Cyber Operations SQL: Structured Query Language.

Slides:



Advertisements
Similar presentations
Database Management Systems, R. Ramakrishnan and J. Gehrke1 The Relational Model Chapter 3.
Advertisements

Virtual training week 4 structured query language (SQL)
Introduction to Structured Query Language (SQL)
DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition © 2006 Pearson Prentice Hall 2-1 David M. Kroenke’s Chapter Two: Introduction to Structured Query.
SQL Basics Based on the relational algebra we just learned. Nonprocedural language – what to be done not how Simple, powerful language Used for both data.
The Relational Model Lecture 3 Book Chapter 3 Relational Data Model Relational Query Language (DDL + DML) Integrity Constraints (IC) From ER to Relational.
1ISM - © 2010 Houman Younessi Lecture 3 Convener: Houman Younessi Information Systems Spring 2011.
INFORMATION TECHNOLOGY IN BUSINESS AND SOCIETY SESSION 16 – SQL SEAN J. TAYLOR.
DAY 21: MICROSOFT ACCESS – CHAPTER 5 MICROSOFT ACCESS – CHAPTER 6 MICROSOFT ACCESS – CHAPTER 7 Akhila Kondai October 30, 2013.
1 IT420: Database Management and Organization SQL: Structured Query Language 25 January 2006 Adina Crăiniceanu
CPS120: Introduction to Computer Science Information Systems: Database Management Nell Dale John Lewis.
ASP.NET Programming with C# and SQL Server First Edition
1 IT420: Database Management and Organization SQL - Data Manipulation Language 27 January 2006 Adina Crăiniceanu
LOGO 1 Lab_02: Basic SQL. 2 Outline  Database Tables  SQL Statements  Semicolon after SQL Statements?  SQL DML and DDL  SQL SELECT Statement  SQL.
CHAPTER 7 Database: SQL, MySQL. Topics  Introduction  Relational Database Model  Relational Database Overview: Books.mdb Database  SQL (Structured.
 SQL stands for Structured Query Language.  SQL lets you access and manipulate databases.  SQL is an ANSI (American National Standards Institute) standard.
The Relational Model. Review Why use a DBMS? OS provides RAM and disk.
DBS201: Introduction to Database Design and SQL
Introduction to databases and SQL. What is a database?  A database is an organized way of holding together pieces of information  A database refers.
Lecture6:Data Manipulation in SQL, Simple SQL queries Prepared by L. Nouf Almujally Ref. Chapter5 Lecture6 1.
Database: SQL and MySQL
CPS120: Introduction to Computer Science Lecture 19 Introduction to SQL.
Structure Query Language SQL. Database Terminology Employee ID 3 3 Last name Small First name Tony 5 5 Smith James
SQL SQL Server : Overview SQL : Overview Types of SQL Database : Creation Tables : Creation & Manipulation Data : Creation & Manipulation Data : Retrieving.
SQL: DDL. SQL Statements DDL - data definition language –Defining and modifying data structures (metadata): database, tables, views, etc. DML - data manipulation.
Topic 1: Introduction to SQL. SQL stands for Structured Query Language. SQL is a standard computer language for accessing and manipulating databases SQL.
SQL Unit – 2 Base Knowledge Presented By Mr. R.Aravindhan.
DAT602 Database Application Development Lecture 3 Review of SQL Language.
5. Simple SQL using Oracle1 Simple SQL using Oracle 5. Working with Tables: Data management and Retrieval 6. Working with Tables: Functions and Grouping.
1 DBS201: Introduction to Structure Query Language (SQL) Lecture 1.
Database Management COP4540, SCS, FIU Structured Query Language (Chapter 8)
SQL Basic. What is SQL? SQL (pronounced "ess-que-el") stands for Structured Query Language. SQL is used to communicate with a database.
SQL. คำสั่ง SQL SQL stands for Structured Query Language is a standard language for accessing and manipulating databases.
CIS 375—Web App Dev II SQL. 2 Introduction SQL (Structured _______ Language) is an ANSI standard language for accessing databases.ANSI SQL can execute.
Database Fundamental & Design by A.Surasit Samaisut Copyrights : All Rights Reserved.
The Relational Model Content based on Chapter 3 Database Management Systems, (Third Edition), by Raghu Ramakrishnan and Johannes Gehrke. McGraw Hill, 2003.
CIS 375—Web App Dev II SQL. 2 Introduction SQL (Structured _______ Language) is an ANSI standard language for accessing databases.ANSI SQL can execute.
SQL Jan 20,2014. DBMS Stores data as records, tables etc. Accepts data and stores that data for later use Uses query languages for searching, sorting,
5. Simple SQL using Oracle1 Simple SQL using Oracle 5. Working with Tables: Data management and Retrieval 6. Working with Tables: Functions and Grouping.
1 IT420: Database Management and Organization SQL part 3 7 February 2006 Adina Crăiniceanu
CMPT 258 Database Systems The Relationship Model (Chapter 3)
IS6146 Databases for Management Information Systems Lecture 1: Introduction to IS6146 Rob Gleasure robgleasure.com.
1 SY306 Web and Databases for Cyber Operations Set #13: SQL SELECT Grouping and sub-queries.
Distribution of Marks For Second Semester Internal Sessional Evaluation External Evaluation Assignment /Project QuizzesClass Attendance Mid-Term Test Total.
Introduction to Database SEM I, AY Department of Information Technology Salalah College of Technology Chapter No.3 SQL.
7 1 Database Systems: Design, Implementation, & Management, 7 th Edition, Rob & Coronel 7.6 Advanced Select Queries SQL provides useful functions that.
MICROSOFT ACCESS – CHAPTER 5 MICROSOFT ACCESS – CHAPTER 6 MICROSOFT ACCESS – CHAPTER 7 Sravanthi Lakkimsety Mar 14,2016.
Chapter 3 The Relational Model. Why Study the Relational Model? Most widely used model. Vendors: IBM, Informix, Microsoft, Oracle, Sybase, etc. “Legacy.
Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke1 The Relational Model Chapter 3.
1 SQL: The Query Language. 2 Example Instances R1 S1 S2 v We will use these instances of the Sailors and Reserves relations in our examples.
COM621: Advanced Interactive Web Development Lecture 11 MySQL – Data Manipulation Language.
 MySQL is a database system used on the web  MySQL is a database system that runs on a server  MySQL is ideal for both small and large applications.
ORDER BY Clause The result of a query can be sorted in ascending or descending order using the optional ORDER BY clause. The simplest form of.
Web Systems & Technologies
CHAPTER 7 DATABASE ACCESS THROUGH WEB
Introduction to Structured Query Language(SQL)
JDBC.
Web Programming Week 3 Old Dominion University
Structured Query Language (SQL) William Klingelsmith
The Relational Model Relational Data Model
CS 405G: Introduction to Database Systems
The Basics of Data Manipulation
Introduction To Structured Query Language (SQL)
Copyright © 2012 Pearson Education, Inc. Publishing as Prentice Hall
SQL Queries Chapter No 3.
SQL.
Introduction To Structured Query Language (SQL)
Web Programming Week 3 Old Dominion University
Structured Query Language – The Basics
Web Programming Week 3 Old Dominion University
Presentation transcript:

1 SY306 Web and Databases for Cyber Operations SQL: Structured Query Language

2 SQL - The Language of Databases  Developed by IBM in the 1970s  Create and process database data  SQL programming is a critical skill !!!

3 Facebook and Databases  Relational databases are accessed in much the same way across the board: SQL. Learning how SQL works is crucial to getting anything done in databases, and any GUI is largely a wrapper around the SQL statements one uses to make those actions happen.  Knowing a little about database design (layout, B-trees, file storage, normalization) is good, mostly for helping you understand good queries.  We run the LAMP stack here, so we primarily use MySQL databases across the site.  I hope this helps a little. Another good motivation may be found in the requirements for most engineering positions here on ;) Thanks! Nick from Facebook (a few years ago)

4 Relational Query Languages  A major strength of the relational model:  supports simple, powerful querying of data  Ad-hoc queries  High-level (declarative) languages  Queries can be written intuitively  DBMS is responsible for efficient evaluation.

5 SQL DDL and DML  SQL statements can be divided into two categories:  Data definition language (DDL) statements  Used for creating and modifying tables, views, and other structures  CREATE, DROP, ALTER  Data manipulation language (DML) statements.  Used for queries and data modification  INSERT, DELETE, UPDATE, SELECT

6 The SQL SELECT Statement  Basic SQL Query: SELECT[DISTINCT] column_name(s) | * FROMtable_name(s) [WHEREconditions] [ORDER BY column_name1 [ASC|DSC], …]

7 Selecting All Columns: The Asterisk (*) Keyword SELECT* FROM Students; Student Number Student LastName Student FirstName PhoneNumberMajor

8 Specific Columns and Rows from One Table SELECTStudentNumber, StudentLastName, StudentFirstName FROMStudents WHEREMajor = ‘SCY’; Student Number Student LastName Student FirstName 190SmithJohn 673DoeJane

9 The DISTINCT Keyword SELECT StudentLastName FROM Students; StudentLastName Smith Doe SELECT DISTINCT StudentLastName FROM Students; StudentLastName Smith Doe

10 Class Exercise  Department(DeptName, ChairName, WebAddress, DivName)  Find the name of the Chair of the ‘Math’ Department

11 WHERE Clause Options  AND, OR  IN, NOT IN, BETWEEN  LIKE Wild cards:  SQL-92 Standard (SQL Server, Oracle, etc.):  _ = Exactly one character  % = Any set of characters (zero or more)  MS Access  ? = Exactly one character  * = Any set of characters (zero or more)  Example: Students(SNb, SName, , Major) Find alpha and name of SCY or SCS students with SNb starting with ‘16’ SELECT SNb, SName FROM Students WHERE SNb LIKE ’16%’ AND Major IN (‘SCY’, ‘SCS’)

12 Sorting the Results SELECT[DISTINCT] column_name(s) | * FROMtable_name(s) [WHEREconditions] [ORDER BY column_name(s) [ASC/DESC]] Example: Students(SNb, SName, , Major) SELECT SNb, SName FROM Students ORDER BY SName ASC, SNb DESC

13 Summary (partial)  SELECT [DISTINCT] column_name(s) FROM table_name WHERE conditions ORDER BY column_name(s) [ASC/DESC]

14 SELECT from Two or More Tables SNbSName CidCNameCDept SY306WebDbScyComSci SY301Data StructuresComSci SM121Calculus1Math SNbCidSemester 190SY301Fall SY306Spring2015 SELECT SName FROM Students S, Enrolled E WHERE S.Snb = E.SNb AND E.Cid = ‘SY306’ Find the names of students enrolled in SY306 Students Courses Enrolled

15 SELECT - Conceptual Evaluation Strategy  Semantics of an SQL query defined in terms of the following conceptual evaluation strategy:  Compute the cross-product of table_names  Discard resulting rows if they fail condition  Delete columns that are not in column_names  If DISTINCT is specified, eliminate duplicate rows  This strategy is probably the least efficient way to compute a query!  An optimizer will find more efficient strategies to compute the same answers.

16 Example Conceptual Evaluation S.SNbSName E.SNbCidSemester SELECT SName FROM Students S, Enrolled E WHERE S.Snb = E.SNb AND E.Cid = ‘SY306’

17 Example Conceptual Evaluation S.SNbSName E.SNbCidSemester SELECT SName FROM Students S, Enrolled E WHERE S.Snb = E.SNb AND E.Cid = ‘SY306’

18 Example Conceptual Evaluation S.SNbSName E.SNbCidSemester SELECT SName FROM Students S, Enrolled E WHERE S.Snb = E.SNb AND E.Cid = ‘SY306’ SName Doe

19 Modified Query SELECT S.SNb FROM Students S, Enrolled E WHERE S.SNb = E.SNb AND E.Cid =‘SY306’  Would the result be different with DISTINCT?

20 Class Exercise  Students(SNb, SName, )  Courses(Cid,CName, Dept)  Enrolled(SNb,Cid, Semester)  Find the student number and name for each student enrolled in ‘Spring2015’ semester  Find the names of all students enrolled in ‘ComSci’ courses

21 Summary (partial)  SELECT [DISTINCT] column_name(s) FROM table_name(s) WHERE conditions ORDER BY column_name(s) [ASC/DESC]