Objectives of SQL. Terminology for Relational Model. Introduction to SQL



Similar documents
14 Triggers / Embedded SQL

Introduction to Microsoft Jet SQL

Information Systems SQL. Nikolaj Popov

CSC 443 Data Base Management Systems. Basic SQL

Database Query 1: SQL Basics

Chapter 9, More SQL: Assertions, Views, and Programming Techniques

Structured Query Language (SQL)

Embedded SQL. Unit 5.1. Dr Gordon Russell, Napier University

SQL Introduction Chapter 7, sections 1 & 4. Introduction to SQL. Introduction to SQL. Introduction to SQL

Unit 10: Microsoft Access Queries

Oracle Database: SQL and PL/SQL Fundamentals

SQL Simple Queries. Chapter 3.1 V3.0. Napier University Dr Gordon Russell

Chapter 5 More SQL: Complex Queries, Triggers, Views, and Schema Modification

Elena Baralis, Silvia Chiusano Politecnico di Torino. Pag. 1. Active database systems. Triggers. Triggers. Active database systems.

Databasesystemer, forår 2005 IT Universitetet i København. Forelæsning 3: Business rules, constraints & triggers. 3. marts 2005

Programming Database lectures for mathema

There are five fields or columns, with names and types as shown above.

Oracle Database: SQL and PL/SQL Fundamentals NEW

Oracle Database 12c: Introduction to SQL Ed 1.1

Lab 2: PostgreSQL Tutorial II: Command Line

Oracle SQL. Course Summary. Duration. Objectives

Chapter 1: Introduction. Database Management System (DBMS) University Database Example

Using Multiple Operations. Implementing Table Operations Using Structured Query Language (SQL)

SQL Programming. CS145 Lecture Notes #10. Motivation. Oracle PL/SQL. Basics. Example schema:

SQL Server 2008 Core Skills. Gary Young 2011

Databases What the Specification Says


Oracle 10g PL/SQL Training

KB_SQL SQL Reference Guide Version 4

Embedded SQL programming

Oracle Database: SQL and PL/SQL Fundamentals

Database Design. Marta Jakubowska-Sobczak IT/ADC based on slides prepared by Paula Figueiredo, IT/DB

Oracle Database 10g: Introduction to SQL

Chapter 2 Database System Concepts and Architecture

Retrieving Data Using the SQL SELECT Statement. Copyright 2006, Oracle. All rights reserved.

Introduction to SQL and database objects

Chapter 1: Introduction. Database Management System (DBMS)

Instant SQL Programming

Database System Concepts

Oracle For Beginners Page : 1

Database Programming with PL/SQL: Learning Objectives

Database Migration from MySQL to RDM Server

Intro to Embedded SQL Programming for ILE RPG Developers

Data Tool Platform SQL Development Tools

Maintaining Stored Procedures in Database Application

Oracle Database 11g SQL

Part A: Data Definition Language (DDL) Schema and Catalog CREAT TABLE. Referential Triggered Actions. CSC 742 Database Management Systems

Relational Algebra. Query Languages Review. Operators. Select (σ), Project (π), Union ( ), Difference (-), Join: Natural (*) and Theta ( )

SQL NULL s, Constraints, Triggers

History of SQL. Relational Database Languages. Tuple relational calculus ALPHA (Codd, 1970s) QUEL (based on ALPHA) Datalog (rule-based, like PROLOG)

Advanced SQL. Jim Mason. Web solutions for iseries engineer, build, deploy, support, train

Demystified CONTENTS Acknowledgments xvii Introduction xix CHAPTER 1 Database Fundamentals CHAPTER 2 Exploring Relational Database Components

CS2Bh: Current Technologies. Introduction to XML and Relational Databases. The Relational Model. The relational model

Duration Vendor Audience 5 Days Oracle End Users, Developers, Technical Consultants and Support Staff

Introduction to Databases

The Structured Query Language. De facto standard used to interact with relational DB management systems Two major branches

Chapter 1: Introduction

Foreign and Primary Keys in RDM Embedded SQL: Efficiently Implemented Using the Network Model

IT2304: Database Systems 1 (DBS 1)

How To Create A Table In Sql (Ahem)

2. Basic Relational Data Model

Ch.5 Database Security. Ch.5 Database Security Review

ICAB4136B Use structured query language to create database structures and manipulate data

Using Temporary Tables to Improve Performance for SQL Data Services

Building Queries in Microsoft Access 2007

CSE 530A Database Management Systems. Introduction. Washington University Fall 2013

3.GETTING STARTED WITH ORACLE8i

5. CHANGING STRUCTURE AND DATA

Chapter 6: Physical Database Design and Performance. Database Development Process. Physical Design Process. Physical Database Design

A basic create statement for a simple student table would look like the following.

SQL. Short introduction

1 File Processing Systems

4. SQL. Contents. Example Database. CUSTOMERS(FName, LName, CAddress, Account) PRODUCTS(Prodname, Category) SUPPLIERS(SName, SAddress, Chain)

Using SQL in RPG Programs: An Introduction

BCA. Database Management System

IT2305 Database Systems I (Compulsory)

unisys ClearPath Enterprise Servers SQL Query Processor for ClearPath MCP Installation and Operations Guide ClearPath MCP 16.0

Introduction to database management systems

SQL interview questions and answers

1.1 A Collection of Related Data : Databases and Database Management Systems.

Mini User's Guide for SQL*Plus T. J. Teorey

Postgres Plus xdb Replication Server with Multi-Master User s Guide

TrendWorX32 SQL Query Engine V9.2 Beta III

Databases in Engineering / Lab-1 (MS-Access/SQL)

RDBMS Using Oracle. Lecture Week 7 Introduction to Oracle 9i SQL Last Lecture. kamran.munir@gmail.com. Joining Tables

Chapter 1: Introduction

MS Access: Advanced Tables and Queries. Lesson Notes Author: Pamela Schmidt

Chapter 5. SQL: Queries, Constraints, Triggers

SQL Server. 1. What is RDBMS?

Review Entity-Relationship Diagrams and the Relational Model. Data Models. Review. Why Study the Relational Model? Steps in Database Design

2874CD1EssentialSQL.qxd 6/25/01 3:06 PM Page 1 Essential SQL Copyright 2001 SYBEX, Inc., Alameda, CA

What is a database? COSC 304 Introduction to Database Systems. Database Introduction. Example Problem. Databases in the Real-World

Developing Microsoft SQL Server Databases MOC 20464

ECS 165A: Introduction to Database Systems

RNDr. Michal Kopecký, Ph.D. Department of Software Engineering, Faculty of Mathematics and Physics, Charles University in Prague

Object-Relational Query Processing

Overview of Database Management Systems

Chapter 9 Java and SQL. Wang Yang wyang@njnet.edu.cn

DATABASE MANAGEMENT SYSTEMS. Question Bank:

Schema Evolution in SQL-99 and Commercial (Object-)Relational DBMS

Transcription:

Karlstad University Department of Information Systems Adapted for a textbook by Date C. J. An Introduction to Database Systems Pearson Addison Wesley, 2004 Introduction to SQL Remigijus GUSTAS Phone: +46-54 700 17 65 E-mail: Remigijus.Gustas@kau.se http://www.cs.kau.se/~gustas/ Terminology for Relational Model SQL terms Internal level terms Relation,Relvar 4-2 Objectives of SQL Database language should allow user to: create the database and relation structures; perform insertion, modification, deletion of data from relations; perform queries. Two major components: Data Definition Language (DDL) Data Manipulation Language (DML) SQL is non-procedural - you specify what information you require, rather than how to get it 4-3 1

ISO SQL Data Types Any given type is either system-defined or user-defined CREATE TYPE <type name> AS <representation> FINAL ; CREATE TYPE NAME AS CHAR(15) FINAL ; <representation> is another (system or user-defined) type 4-4 CREATE TABLE specifies the name and structure of a base table CREATE TABLE ( CHAR(2), NAME, INTEGER, PRIMARY KEY ( ) ) ; 4-5 BNF notation Material in lowercase enclosed in angle brackets "<" and ">" represents a syntactic category that appears on the left side of another production rule, and hence must eventually be replaced by specific items chosen by the user. Vertical bars " " are used to separate alternatives. Square brackets "[" and "]" are used to indicate that the material enclosed in those brackets is optional. 4-6 2

Manipulative operations: INSERT INSERT INTO <table name> (<column name> [, < column name>] ) VALUES (<column value> [, < column name>] ) ; INSERT INTO (,, ) VALUES (,, ) ; 4-7 Manipulative operations: DELETE DELETE FROM <table name> WHERE (<condition>) ; DELETE FROM WHERE = ; 4-8 Manipulative operations: UPDATE UPDATE <table name> SET <column name> = <new value> WHERE <condition> ; UPDATE SET = 20000 WHERE = ; 20000 4-9 3

Relational operators in SQL Restrict is implemented by SELECT Subset of rows Uses WHERE clause to narrow result Uses SELECT * to copy entire table Project is also implemented by SELECT Subset of columns Join is also implemented by SELECT Result is a single table matched by values in the join columns of each source table Uses WHERE clause to specify source tables Uses dot operator to disambiguate column references 4-10 Restrict is implemented by SELECT SELECT,, FROM WHERE <> ; SELECT * FROM WHERE <> ; Result # 4-11 Project is implemented by SELECT SELECT, FROM ; Result 4-12 4

Join is implemented by SELECT EMP EMPNO ENAME SALARY 10.000K E1 Lopez 40K 12.000K E2 Cheng 42K 5.000K E3 Finzi 30K E4 Saito 35K SELECT,,, EMPNO, ENAME, SALARY FROM, EMP WHERE. = EMP. ; 10.000K 10.000K 12.000K 12.000K EMPNO E1 E2 E3 E4 ENAME Lopez Cheng Finzi Saito SALARY 40K 42K 30K 35K 4-13 INSERT, DELETE and UPDATE are operations on sets EMP EMPNO ENAME SALARY DELETE FROM EMP WHERE = ; E1 E2 E3 E4 Lopez Cheng Finzi Saito 40K 42K 30K 35K UPDATE SUPPLIER SET STATUS = 2 * STATUS, CITY = Rome WHERE CITY = Paris ; Doubles the status of the Parisian suppliers and moves them to Rome. 4-14 The Catalog in SQL Every database has a catalog A catalog has many schemas, one per user Each catalog includes one Information Schema The Information Schema is a collection of all other schemas as views Represents a hypothetical Definition Schema for all users 4-15 5

The Information Schema - Examples Tables (includes views) Views (does not include tables) Table constraints Referential constraints Column constraints Privileges Note: All these objects are tables, therefore they can be queried 4-16 Views View is a virtual relation that can be derived from base relations upon request CREATE VIEW <viewname> ; CREATE VIEW GOOD_SUPPLIER AS SELECT SNUMBER, STATUS, CITY FROM SUPPLIER WHERE STATUS > 15; You can operate on the view, for instance: SELECT SNUMBER, STATUS FROM GOOD_SUPPLIER WHERE CITY = London ; 4-17 Views Creating a view, and then selecting from the view is equivalent to a SELECT sub-query SELECT GOOD_SUPPLIER.SNUMBER, GOOD_SUPPLIER.STATUS FROM (SELECT SNUMBER, STATUS, CITY FROM SUPPLIER WHERE STATUS > 15 ) AS GOOD_SUPPLIER; WHERE GOOD_SUPPLIER.CITY = London ; This query is what is actually executed SELECT SNUMBER, STATUS FROM SUPPLIER WHERE STATUS > 15 AND CITY = London ; This query is what is actually executed 4-18 6

Embedded SQL SQL statements can be embedded in a host program SQL standard includes support for C, COBOL, PL/1, Java, and many others Initiated in host via EXEC SQL statement Any embedded SQL statement is valid after EXEC SQL SQL operations retrieve many rows (not just one) and host languages are generally not equipped to handle more than one row at a time 4-19 7