1 Structured Query Language (SQL) CIS*2450 Advanced Programming Concepts.

Slides:



Advertisements
Similar presentations
What is a Database By: Cristian Dubon.
Advertisements

The Relational Model and Relational Algebra Nothing is so practical as a good theory Kurt Lewin, 1945.
CIT 613: Relational Database Development using SQL Introduction to SQL.
Structure Query Language (SQL) COMSATS INSTITUTE OF INFORMATION TECHNOLOGY, VEHARI.
Maintenance Modifying the data –Add records –Delete records –Update records Modifying the design –Add fields into tables –Remove fields from a table –Change.
Introduction to Structured Query Language (SQL). Origins & history Early 1970’s – IBM develops Sequel as part of the System R project at its San Hose.
Fundamentals, Design, and Implementation, 9/e COS 346 Day 11.
Introduction to Structured Query Language (SQL)
Fundamentals, Design, and Implementation, 9/e Chapter 6 Introduction to Structured Query Language (SQL)
Introduction to Structured Query Language (SQL)
1 Chapter 2 Reviewing Tables and Queries. 2 Chapter Objectives Identify the steps required to develop an Access application Specify the characteristics.
Concepts of Database Management Sixth Edition
Chapter 7 Managing Data Sources. ASP.NET 2.0, Third Edition2.
Microsoft Access 2010 Chapter 7 Using SQL.
Dale Roberts 1 Department of Computer and Information Science, School of Science, IUPUI Dale Roberts, Lecturer Computer Science, IUPUI
Nichelle K. Norris IS 373: World Wide Web Standards.
Copyright © 2003 by Prentice Hall Module 4 Database Management Systems 1.What is a database? Data hierarchy and data organization Field, record, file,
Copyright © 2003 by Prentice Hall Computers: Tools for an Information Age Chapter 13 Database Management Systems: Getting Data Together.
AL-MAAREFA COLLEGE FOR SCIENCE AND TECHNOLOGY INFO 232: DATABASE SYSTEMS CHAPTER 7 INTRODUCTION TO STRUCTURED QUERY LANGUAGE (SQL) Instructor Ms. Arwa.
Data Manipulation 11 After this lecture, you should be able to:  Understand the differences between SQL (Structured Query Language) and other programming.
Chapter 1 Overview of Database Concepts Oracle 10g: SQL
Concepts of Database Management, Fifth Edition Chapter 4: The Relational Model 3: Advanced Topics.
Lecture 2 An Overview of Relational Database IST 318 – DB Admin.
© 2007 by Prentice Hall (Hoffer, Prescott & McFadden) 1 Introduction to SQL.
© 2009 Pearson Education, Inc. Publishing as Prentice Hall 1 UNIT 6: Chapter 7: Introduction to SQL Modern Database Management 9 th Edition Jeffrey A.
Relational Databases (MS Access)
Professor Michael J. Losacco CIS 1110 – Using Computers Database Management Chapter 9.
SQL SQL Server : Overview SQL : Overview Types of SQL Database : Creation Tables : Creation & Manipulation Data : Creation & Manipulation Data : Retrieving.
Key Applications Module Lesson 21 — Access Essentials
Using Special Operators (LIKE and IN)
Concepts of Database Management Seventh Edition
1 Structured Query Language (SQL). 2 Contents SQL – I SQL – II SQL – III SQL – IV.
1-1 Homework 3 Practical Implementation of A Simple Rational Database Management System.
“INTRODUCTION TO DATABASE AND SQL”. Outlines 2  Introduction To Database  Database Concepts  Database Properties  What is Database Management System.
7 1 Chapter 7 Introduction to Structured Query Language (SQL) Database Systems: Design, Implementation, and Management, Seventh Edition, Rob and Coronel.
6 1 Lecture 8: Introduction to Structured Query Language (SQL) J. S. Chou, P.E., Ph.D.
Data Manipulation 21 After this lecture, you should be able to:  Use SQL SELECT statement effectively to retrieve the data from multiple related tables.
Concepts of Database Management Eighth Edition Chapter 3 The Relational Model 2: SQL.
Database Systems Design, Implementation, and Management Coronel | Morris 11e ©2015 Cengage Learning. All Rights Reserved. May not be scanned, copied or.
1 DBS201: Introduction to Structure Query Language (SQL) Lecture 1.
Introduction to Oracle In June 1970,Dr E.F.Codd’s a published A paper entitled A relational model of Data for large shared data banks. This relational.
Algebra1 After this lecture, you should be able to:  Understand the differences between SQL (Structured Query Language) and Relational Algebra expressions.
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,
Chapter 4 An Introduction to SQL. Copyright © 2004 Pearson Addison-Wesley. All rights reserved.4-2 Topics in this Chapter SQL: History and Overview The.
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.
SQL - miscellaneous D. Christozov / G.Tuparov INF 280 Database Systems: SQL – miscellaneous 1.
An Introduction to SQL For CS Overview of SQL  It is the standard language for relational systems, although imperfect  Supports data definition.
CIT 613: Relational Database Development using SQL Introduction to SQL DeSiaMorePowered by DeSiaMore 1.
ITS232 Introduction To Database Management Systems Siti Nurbaya Ismail Faculty of Computer Science & Mathematics, Universiti Teknologi MARA (UiTM), Kedah.
Relational Database Management System(RDBMS) Structured Query Language(SQL)
Starting with Oracle SQL Plus. Today in the lab… Connect to SQL Plus – your schema. Set up two tables. Find the tables in the catalog. Insert four rows.
1 SQL II CIS*2450 Advanced Programming Concepts. 2 Data Types INTEGER –numbers without a decimal point –range is to SMALLINT –like.
1 A Very Brief Introduction to Relational Databases.
SQL Introduction to database and SQL. Chapter 1: Databases and Database Users 6 Introduction to Databases Databases touch all aspects of our lives. Examples:
7 1 Database Systems: Design, Implementation, & Management, 7 th Edition, Rob & Coronel 7.6 Advanced Select Queries SQL provides useful functions that.
CSC314 DAY 8 Introduction to SQL 1. Chapter 6 © 2013 Pearson Education, Inc. Publishing as Prentice Hall SQL OVERVIEW  Structured Query Language  The.
Chapter 4 An Introduction to SQL. Copyright © 2004 Pearson Addison-Wesley. All rights reserved.4-2 Topics in this Chapter SQL: History and Overview The.
1 Section 1 - Introduction to SQL u SQL is an abbreviation for Structured Query Language. u It is generally pronounced “Sequel” u SQL is a unified language.
Concepts of Database Management, Fifth Edition Chapter 3: The Relational Model 2: SQL.
COM621: Advanced Interactive Web Development Lecture 11 MySQL – Data Manipulation Language.
© Virtual University of Pakistan Database Management System Lecture - 24.
Chapter 4 An Introduction to SQL.
Chapter 10 SQL DDL.
STRUCTURE OF PRESENTATION :
“Introduction To Database and SQL”
Lecture 3 : Structured Query Language (SQL)
“Introduction To Database and SQL”
Structured Query Language
Databases and Information Management
Presentation transcript:

1 Structured Query Language (SQL) CIS*2450 Advanced Programming Concepts

2 Structured Query Language SQL consists of a set of commands for defining, accessing, and managing relational databases. In 1970, E.F. Codd at IBM Research Labs in San Jose, California published “A Relational Model of Data for Large Shared Data Banks” (Communications of the ACM, Vol. 13, No. 6, June 1970) in which he described a set of abstract principles for database management - the relational model. The field of relational database technology has its origins in that paper.

3 Structured Query Language This research described several relational languages which implement some/all of the features of the abstract relational model. One of these languages which was created in was the “Structured English Query Language” (SEQUEL), defined by Donald Chamberlin and others at IBM Labs. The first IBM prototype was called SEQUEL-XRM ( ).

4 Structured Query Language A revised version of SEQUEL-XRM was defined in and named SEQUEL/Z. The name was changed to SQL for legal reasons. A prototype of this became operational in 1977 called System R. Due to the success of System R, vendors rushed to create their own SQL products. The Oracle database was released before IBM's own product.

5 Structured Query Language In 1982, the American National Standards Institute (ANSI) chartered its Database Committee (X3H2) to develop a standard for a relational language. In 1986, the X3H2 proposal was ratified by ANSI which consisted essentially of the IBM dialect of SQL. In 1987, the ANSI standard was accepted as an international standard by the International Organization for Standards (ISO).

6 Structured Query Language The original standard is also known as SQL/86. Enhancements were made over time –SQL/89 - included an Integrity Enhancement Feature –SQL/92 - ISO and ANSI developed a revised standard also known as SQL2 –SQL/99 - “SQL3” incorporates object-oriented access –A consortium of vendors known as the SQL Access Group has been working to enhance interoperability across different systems

7 SQL as a Standard Since SQL is such a pervasive standard, let us review some information on standards - their good points and their not so good points.

8 Are Standards Good? -- Good Points Standards reduce training costs. They promote application portability. Standards promote application longevity. –Standards have a reasonably long life, so applications using them should as well.

9 Are Standards Good? -- Good Points Intersystem Communications –are more easily achieved. –Different database management systems can function equally well on a single database if they support the same standard interface. Customer Choice –If products support the same interface then customers can focus on the implementation that best meets their own needs without having to choose among different interfaces.

10 Are Standards Good? -- Bad Points Standards can stifle creativity - system implementers may be prevented from providing “the best” solution because the standard prescribes some alternative. SQL has some flaws in its design, some of which are considered severe.

11 SQL Overview SQL is used to define, manipulate, and control data in relational databases. A relational database is one which is perceived as a collection of tables by the user. A table is an unordered collection of rows.

12 A Suppliers-and-Part Database Example Tables –S : suppliers –P : parts (and where to ship an order) –SP : shipment of parts by suppliers

13 Table S S1Smith20London S2Jones10Paris S3Blake30Paris S4Clark20London SNO SNAME STATUS CITY Primary Key = SNO

14 Table P P1NutRed12London P2BoltGreen17Paris P3ScrewBlue17Rome P4ScrewRed14London PNO PNAME COLOUR WEIGHT CITY Primary Key = PNO

15 Table SP S1P1300 S1P2200 S2P1300 S3P2200 S4P4400 SNO PNO QTY Primary Key = SNO and PNO

16 Tables Tables can be thought of as files, with rows representing records and the columns as fields. The SQL standard always uses the terms table, row and column. SQL statements can be invoked either interactively or from within an application. –Interactive SQL generally displays the results on the screen. –Invocation from a program means the results are made available as input to the program.

17 The Select Statement SQL Query: SELECT S.CITY FROM S WHERE S.SNO = 'S4' Result: CITY London

18 SELECT SELECT is used for data retrieval. FROM indicates the table from which to retrieve the data. WHERE is used to describe column features that are desired in the retrieved data. –No WHERE statement will cause all rows to be returned. –You can use all of the standard comparisons (,>=,=). –Literal strings must appear in single quotes.

19 Creating Tables Empty tables are constructed using the CREATE TABLE statement. Data must be entered later using INSERT. CREATE TABLE S ( SNO CHAR(5), SNAME CHAR(20), STATUS DECIMAL(3), CITY CHAR(15), PRIMARY KEY (SNO) )

20 Creating Tables A table name and unique column names must be specified. Columns which are defined as primary keys will never have two rows with the same key value. Primary key may consist of more than one column (values unique in combination) called composite key.

21 Creating Tables CREATE TABLE SP ( SNO CHAR(5), PNO CHAR(5), QTY DECIMAL(5), PRIMARY KEY (SNO,PNO), FOREIGN KEY (SNO) REFERENCES S, FOREIGN KEY (PNO) REFERENCES P ) Foreign keys refer to other tables. –Any key in SP.SNO must also appear in S.SNO and any key in SP.PNO must appear in P.PNO - a shipment cannot exist unless the supplier and part also exist.

22 Data Manipulation There are four basic SQL data manipulation operations. –SELECT - retrieves data –INSERT - add a new row –UPDATE - change values in existing records –DELETE - remove row(s)

23 INSERT INTO SP ( SNO, PNO, QTY ) VALUES ( 'S4', 'P1', 1000 ) Row added to Table SP.

24 UPDATE UPDATE S SET STATUS = 2 * S.STATUS WHERE S.CITY = 'London' Status doubled for suppliers in London (S1 and S4)

25 DELETE FROM P WHERE P.WEIGHT > 15 Rows deleted from P where WEIGHT > 15 (P2 and P3)

26 SELECT SELECT has the general form SELECT-FROM-WHERE. The result is another (new) table.

27 SELECT SELECT DISTINCT P.COLOUR, P.CITY FROM P WHERE P.WEIGHT > 10 AND P.CITY <> 'Paris' results in the table, COLOUR CITY Red London Blue Rome [ Red London ] - eliminated because of DISTINCT statement which removes multiple copies of rows

28 SELECT DISTINCT - no duplicate rows. No WHERE - all rows of FROM table are returned. SELECT * is short for select the entire row (all columns).