An Introduction to SQL Prof. Yin-Fu Huang CSIE, NYUST Chapter 4.

Slides:



Advertisements
Similar presentations
Basic SQL Introduction Presented by: Madhuri Bhogadi.
Advertisements

Chapter 2 Database System Concepts and Architecture
CSC343 – Introduction to databases – A. Vaisman1 Database Application Development.
Embedded SQL John Ortiz. Lecture 15Embedded SQL2 Why Isn’t Interactive SQL Enough?  How to do this using interactive SQL?  Print a well-formatted transcript.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 13 Introduction to SQL Programming Techniques.
End of SQL: Triggers, Impedance Mismatch and Transactions February 6 th, 2004.
SPRING 2004CENG 3521 SQL: Constraints, Triggers, Embedded SQL Chapters: 5, 6.
Winter 2002Arthur Keller – CS 18011–1 Schedule Today: Feb. 7 (TH) u PL/SQL, Embedded SQL, CLI, JDBC. u Read Sections 8.1, Feb. 12 (T) Advising.
COMP 5138 Relational Database Management Systems Semester 2, 2007 Lecture 8A Transaction Concept.
SEMESTER 1, 2013/2014 DB2 APPLICATION DEVELOPMENT OVERVIEW.
Jump-Start Embedded SQL into RPG Presented by: Robert Arce.
SQL Within PL / SQL Chapter 4. 2 SQL Within PL / SQL SQL Statements DML in PL / SQL Pseudocolums Transaction Control.
1 Section 6 Embedded SQL. 6-2 CA306 Embedded SQL Section Content 6.1Embedded SQL 6.2Java Database Connectivity 6.3Web Databases.
DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition © 2006 Pearson Prentice Hall 7-1 David M. Kroenke’s Chapter Seven: SQL for Database Construction and.
Announcements Read JDBC Project Step 5, due Monday.
Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe Slide 9- 1 DATADABASE PROGRAMMING 2Chapter 13 from our text.
Chapter 8 Using SQL in an Application. Copyright © 2005 Pearson Addison-Wesley. All rights reserved. 8-2 CSC 4480 outline Intro (3-9) Static SQL (10-11)
4B-1 Wei-Pang Yang, Information Management, NDHU Introduction to Database CHAPTER 4B ( 補 ) DB2 and SQL  Overview  Data Definition  Data Manipulation.
©Silberschatz, Korth and Sudarshan4.1Database System Concepts Modification of the Database – Deletion Delete all tuples from the loan relation. delete.
Course materials may not be reproduced in whole or in part without the prior written permission of IBM. 5.1 © Copyright IBM Corporation 2008 DB2 9 Fundamentals.
An Introduction to Relational Databases Prof. Yin-Fu Huang CSIE, NYUST Chapter 3.
Triggers and Stored Procedures in DB 1. Objectives Learn what triggers and stored procedures are Learn the benefits of using them Learn how DB2 implements.
Stored Procedures Week 9. Test Details Stored Procedures SQL can call code written in iSeries High Level Languages –Called stored procedures SQL has.
ICS 321 Fall 2009 DBMS Application Programming Asst. Prof. Lipyeow Lim Information & Computer Science Department University of Hawaii at Manoa 10/06/20091Lipyeow.
Winter 2006 Keller, Ullman, Cushing 11–1 Embedded SQL Add to a conventional programming language (C in our examples) certain statements that represent.
ICS 321 Fall 2010 SQL in a Server Environment (i) Asst. Prof. Lipyeow Lim Information & Computer Science Department University of Hawaii at Manoa 11/1/20101Lipyeow.
Programmatic SQL Shaista Khan CS 157B. Topic Embedded SQL statements in high-level programming languages.
SQL in a Programming Environment CIS 4301 Lecture Notes Lecture /11/2006.
Chapter 15 Introduction to PL/SQL. Chapter Objectives  Explain the benefits of using PL/SQL blocks versus several SQL statements  Identify the sections.
Database Technology Jing Shen.
Database System Architecture Prof. Yin-Fu Huang CSIE, NYUST Chapter 2.
Chapter 8 Advanced SQL Database Systems: Design, Implementation, and Management, Seventh Edition, Rob and Coronel.
Chapter 4: SQL Complex Queries Complex Queries Views Views Modification of the Database Modification of the Database Joined Relations Joined Relations.
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.
Different Constraint Types Type Where Declared When activated Guaranteed to hold? Attribute with attribute on insertion not if CHECK or update subquery.
DBMS_Week 3-4 DBMS. Three-Schema Architecture – Internal schema (one view) describes physical storage structures access paths, indexes used Typically.
Retrieving Data in PL/SQL. 2 home back first prev next last What Will I Learn? In this lesson, you will learn to: –Recognize the SQL statements that can.
Relations Prof. Yin-Fu Huang CSIE, NYUST Chapter 6.
Types Prof. Yin-Fu Huang CSIE, NYUST Chapter 5. Advanced Database SystemYin-Fu Huang Relation, tuple, cardinality, attribute, degree, domain, primary.
Constraining Attribute Values Constrain invalid values –NOT NULL –gender CHAR(1) CHECK (gender IN (‘F’, ‘M’)) –MovieName CHAR(30) CHECK (MovieName IN (SELECT.
© 1997 UW CSE 10/27/97H-1 Embedded SQL and the CLI Chapter 7.7.
Integrity Prof. Yin-Fu Huang CSIE, NYUST Chapter 9.
IT420: Database Management and Organization Triggers and Stored Procedures 24 February 2006 Adina Crăiniceanu
Lu Wei1 Outline Introduction Basic SQL Setting Up and Using PostgreSQL Advanced SQL Embeded SQL.
Views Prof. Yin-Fu Huang CSIE, NYUST Chapter 10. Advanced Database System Yin-Fu Huang 10.1Introduction Example: Var Good_Supplier View (S Where Status.
1 Section 10 - Embedded SQL u Many computer languages allow you to embed SQL statements within the code (e.g. COBOL, PowerBuilder, C++, PL/SQL, etc.) u.
Copyright © 2016 Ramez Elmasri and Shamkant B. Navathe.
Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke1 Database Application Development Chapter 6.
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.
Chapter 4 An Introduction to SQL.
Introduction to SQL Programming Techniques
SQL Environment.
Introduction to Database Systems, CS420
REV 00 Chapter 4 SQL and QBE DDC 2483 – Database Systems.
Advanced Accounting Information Systems
Chapter 5: Advanced SQL Database System concepts,6th Ed.
SQL 101.
CPSC-310 Database Systems
Database Application Development
Introduction to Database
Introduction to Database
Database Processing: David M. Kroenke’s Chapter Seven:
DB Programming: SQL Programming Techniques
HAVING,INDEX,COMMIT & ROLLBACK
Lecture 17: Systems Aspects of SQL
Chapter 7 Using SQL in Applications
Dynamic SQL The dynamic SQL component of SQL allows programs to construct and submit SQL queries at run time. In contrast, embedded SQL statements must.
Updating Databases With Open SQL
Lecture 05: SQL Systems Aspects
Updating Databases With Open SQL
Presentation transcript:

An Introduction to SQL Prof. Yin-Fu Huang CSIE, NYUST Chapter 4

Advanced Database SystemYin-Fu Huang 4.1Introduction SQL:1999 Products typically support what might be called “a superset of a subset” of the standard. e.g. IBM DB2

Advanced Database SystemYin-Fu Huang 4.2Overview Data definition operations (See Fig. 4.1)

Advanced Database SystemYin-Fu Huang Insert Into Temp(P#, Weight) Select P#, Weight From P Where Color=Color(‘Red’); Delete From Sp Where P#=P#(’P2’); Update S Set Status=Status*2, City=‘Rome’ Where City=‘Paris’; Data manipulation operations (See Fig. 4.2) 4.2Overview (Cont.)

Advanced Database SystemYin-Fu Huang Information Schema SQL catalog vs. SQL schema 4.3The Catalog

Advanced Database SystemYin-Fu Huang 4.4Views Example: Create View Good_Supplier As Select S#, Status, City From S Where Status > 15; Select S#, Status From Good_Supplier Where City=’London’;  Select S#, Status From S Where Status > 15 And City=’London’;

Advanced Database SystemYin-Fu Huang 4.5Transactions Statements: Start Transaction, Commit Work, Rollback Work 4.6Embedded SQL The dual-mode principle is that any SQL statement that can be used interactively can also be embedded in an application program; Its converse is not. Example (See Fig. 4.3)

Advanced Database SystemYin-Fu Huang EXEC SQL executable and declarative SQL statements host variables Into clauses declare sections host variable Sqlstate host variables ⇒ appropriate data type host variables and SQL columns ⇒ the same name EXEC SQL Whenever ; ⇒ a directive to the SQL compiler loose coupling

Advanced Database SystemYin-Fu Huang 4.6Embedded SQL (Cont.) It is necessary to provide some kind of bridge between the set- level retrieval capacities of SQL and the row-level retrieval capacities of the host. Such is the purpose of cursors. Operations Not Involving Cursors Exam: Singleton Select EXEC SQL Select Status, City Into :Rank, :Town From S Where S#=S#(:Givens#); Exam: Insert EXEC SQL Insert Into P(P#, Pname, Weight) Values (:P#, :Pname, :Pwt); Exam: Delete EXEC SQL Delete From Sp Where :City= (Select City From S Where S.S#=Sp.S#); Exam: Update EXEC SQL Update S Set Status=Status+:Raise Where City=‘London’;

Advanced Database SystemYin-Fu Huang 4.6Embedded SQL (Cont.) Operations Involving Cursors  Declare cursor statement EXEC SQL Declare Cursor For [ ];  Open Statement EXEC SQL Open ;  Active set  Fetch Statement EXEC SQL Fetch Into ;  Close Statement EXEC SQL Close ;  Changing the values of host variables ⇒ no effect

Advanced Database SystemYin-Fu Huang Current forms of Delete and Update e.g. EXEC SQL Update S Set Status = Status +:Raise Where Current Of X; Example (Fig. 4.4)

Advanced Database SystemYin-Fu Huang 4.7Dynamic SQL and SQL/CLI The steps of an online application:  1. Accept a command from the terminal  2. Analyze that command  3. Execute appropriate SQL statements on the database  4. Return a message and/or results to the terminal Dynamic SQL  Dynamic SQL consists of a set of “dynamic statements”---which themselves are compiled ahead of time---whose purpose is precisely to support the compilation and execution of regular SQL statements that are constructed at run time.  Prepare and Execute statements e.g. DCL Sqlsource Char Varying (65000); Sqlsource = ‘Delete From Sp Where Qty < Qty(300)’; EXEC SQL Prepare Sqlprepped From :Sqlsource; EXEC SQL Execute Sqlprepped;

Advanced Database SystemYin-Fu Huang 4.7Dynamic SQL and SQL/CLI (Cont.) Call-Level Interfaces  SQL/CLI permits an application written in one of the usual host languages to issue database requests, not via embedded SQL, but rather by invoking certain vendor-provided routines.  Those routines use dynamic SQL to perform the requested database operations on the application’s behalf.  Reasons: 1.SQL/CLI standardizes the details of certain routine invocations. 2.Those applications can be DBMS-independent. e.g.char sqlsource [65000]; strcpy(sqlsource, “Delete From Sp Where Qty < Qty(300)”); rc = SQLExecDirect(hstmt, (SQLCHAR *)sqlsource, SQL_NTS);

Advanced Database SystemYin-Fu Huang SQL Is Not Perfect There is no product on the market today that supports the relational model in its entirety.

Advanced Database SystemYin-Fu Huang The End.