Chapter 10 SQL DDL.

Slides:



Advertisements
Similar presentations
Data Definition and Integrity Constraints
Advertisements

Fundamentals of Database Systems Fourth Edition El Masri & Navathe
Relational Database. Relational database: a set of relations Relation: made up of 2 parts: − Schema : specifies the name of relations, plus name and type.
OUTLINE OF THE LECTURE PART I GOAL: Understand the Data Definition Statements in Fig 4.1 Step1: Columns of the Tables and Data types. Step2: Single column.
Fall 2005 ICS184/EECS116 – Notes 08 1 ICS 184/EECS116: Introduction to Data Management Lecture Note 8 SQL: Structured Query Language -- DDL.
Overview Begin 6:00 Quiz15 mins6:15 Review Table Terms25 mins6:40 Short Break10 mins6:50 SQL: Creating Tables60 mins7:50 Break10 mins8:00 Lab – Creating.
Database Design -- Basic SQL
Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe Slide 8- 1.
Structure Query Language (SQL) COMSATS INSTITUTE OF INFORMATION TECHNOLOGY, VEHARI.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 4 SQL: Data Definition, Constraints, and Basic Queries and Updates.
Fundamentals, Design, and Implementation, 9/e COS 346 Day 11.
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.
Structured Query Language
SQL SQL stands for Structured Query Language SQL allows you to access a database SQL is an ANSI standard computer language SQL can execute queries against.
Chapter 6 SQL: Data Manipulation. 2 Objectives of SQL u Database language should allow user to: –create database and relation structures –perform insertion,
Structured Query Language. Brief History Developed in early 1970 for relational data model: –Structured English Query Language (SEQUEL) –Implemented with.
SQL Overview Defining a Schema CPSC 315 – Programming Studio Spring 2008 Project 1, Lecture 3 Slides adapted from those used by Jeffrey Ullman, via Jennifer.
CSC271 Database Systems Lecture # 10.
CSE314 Database Systems Lecture 4 Basic SQL Doç. Dr. Mehmet Göktürk src: Elmasri & Navanthe 6E Pearson Ed Slide Set.
Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe Chapter 8 SQL-99: Schema Definition, Constraints, and Queries and Views.
Database Design lecture 3_1 1 Database Design Lecture 3_1 Data definition in SQL.
Structured Query Language The main reference of this presentation is the textbook and PPT from : Elmasri & Navathe, Fundamental of Database Systems, 4.
Structured Query Language. Brief History Developed in early 1970 for relational data model: –Structured English Query Language (SEQUEL) –Implemented with.
Chapter 8 Part 1 SQL-99 Schema Definition, Constraints, Queries, and Views.
Ms. Hatoon Al-Sagri CCIS – IS Department SQL-99 :Schema Definition, Constraints, Queries, and Views 1.
Onsdag The concepts in a relation data model SQL DDL DML.
Chapter 5: Part 1: DDL STRUCTURED QUERY LANGUAGE (SQL)
1 Pertemuan > > Matakuliah: >/ > Tahun: > Versi: >
SQL: Data Manipulation I Chapter 5 CIS 458 Sungchul Hong.
Database Processing: Fundamentals, Design, and Implementation, 9/e by David M. KroenkeChapter 6/1 Copyright © 2004 Please……. No Food Or Drink in the class.
Chapter 8: SQL. Data Definition Modification of the Database Basic Query Structure Aggregate Functions.
SQL Fundamentals  SQL: Structured Query Language is a simple and powerful language used to create, access, and manipulate data and structure in the database.
SQL Basics. What is SQL? SQL stands for Structured Query Language. SQL lets you access and manipulate databases.
Chapter 8 Part 2 SQL-99 Schema Definition, Constraints, Queries, and Views.
CS 338The Relational Model2-1 The Relational Model Lecture Topics Overview of SQL Underlying relational model Relational database structure SQL DDL and.
DATA AND SCHEMA MODIFICATIONS CHAPTERS 4,5 (6/E) CHAPTER 8 (5/E) 1.
Week 8-9 SQL-1. SQL Components: DDL, DCL, & DML SQL is a very large and powerful language, but every type of SQL statement falls within one of three main.
ITS232 Introduction To Database Management Systems Siti Nurbaya Ismail Faculty of Computer Science & Mathematics, Universiti Teknologi MARA (UiTM), Kedah.
CS34311 The Relational Model. cs34312 Why Relational Model? Currently the most widely used Vendors: Oracle, Microsoft, IBM Older models still used IBM’s.
Physical Model Lecture 11. Physical Data Model The last step is the physical design phase, In this phase data is – Store – Organized and – Access.
SQL- Updates, Assertions and Views. Data Definition, Constraints, and Schema Changes Used to CREATE, DROP, and ALTER the descriptions of the tables (relations)
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 4 Basic SQL تنبيه : شرائح العرض (Slides) هي وسيلة لتوضيح الدرس واداة.
Structured Query Language (SQL) DDL
Fundamental of Database Systems
The SQL Database Grammar
REV 00 Chapter 4 SQL and QBE DDC 2483 – Database Systems.
SQL: SchemaDefinition, Constraints, and Queries and Views
SQL: Schema Definition and Constraints Chapter 6 week 6
Chapter 4 Basic SQL.
SQL Creating and Managing Tables
CS580 Advanced Database Topics
11/9/2018.
DATABASE MANAGEMENT SYSTEM
SQL Creating and Managing Tables
STRUCTURED QUERY LANGUAGE
SQL Creating and Managing Tables
CS4222 Principles of Database System
SQL OVERVIEW DEFINING A SCHEMA
SQL-1 Week 8-9.
Session - 6 Sequence - 1 SQL: The Structured Query Language:
Structured Query Language (3)
Chapter Name SQL: Data Manipulation
SQL-99: Schema Definition, Constraints, and Queries and Views
ISC321 Database Systems I Chapter 4: SQL: Data definition, Constraints, and Basic Queries and Updates Fall 2015 Dr. Abdullah Almutairi.
Session - 6 Sequence - 1 SQL: The Structured Query Language:
Chapter Name SQL: Data Manipulation
SQL (Structured Query Language)
Presentation transcript:

Chapter 10 SQL DDL

Objectives of SQL Ideally, database language should allow user to: create the database and relation structures; perform insertion, modification, deletion of data from relations; perform simple and complex queries. Must perform these tasks with minimal user effort and command structure/syntax must be easy to learn. It must be portable. Ritu CHaturvedi Some figures are adapted from Fundamentals of Database Systems By Elmasri and Navathe

Objectives of SQL SQL is a transform-oriented language with 2 major components: A DDL for defining database structure. A DML for retrieving and updating data. Until SQL3, SQL did not contain flow of control commands. These had to be implemented using a programming or job-control language, or interactively by the decisions of user. Ritu CHaturvedi Some figures are adapted from Fundamentals of Database Systems By Elmasri and Navathe

Objectives of SQL SQL is relatively easy to learn: it is non-procedural - you specify what information you require, rather than how to get it; it is essentially free-format. Ritu CHaturvedi Some figures are adapted from Fundamentals of Database Systems By Elmasri and Navathe

Objectives of SQL Consists of standard English words: 1) CREATE TABLE Staff(staffNo VARCHAR(5), lName VARCHAR(15), salary DECIMAL(7,2)); 2) INSERT INTO Staff VALUES (‘SG16’, ‘Brown’, 8300); 3) SELECT staffNo, lName, salary FROM Staff WHERE salary > 10000; Ritu CHaturvedi Some figures are adapted from Fundamentals of Database Systems By Elmasri and Navathe

Objectives of SQL Can be used by range of users including DBAs, management, application developers, and other types of end users. An ISO standard now exists for SQL, making it both the formal and de facto standard language for relational databases. Ritu CHaturvedi Some figures are adapted from Fundamentals of Database Systems By Elmasri and Navathe

History of SQL In 1974, D. Chamberlin (IBM San Jose Laboratory) defined language called ‘Structured English Query Language’ (SEQUEL). A revised version, SEQUEL/2, was defined in 1976 but name was subsequently changed to SQL for legal reasons. Ritu CHaturvedi Some figures are adapted from Fundamentals of Database Systems By Elmasri and Navathe

History of SQL Still pronounced ‘see-quel’, though official pronunciation is ‘S-Q-L’. IBM subsequently produced a prototype DBMS called System R, based on SEQUEL/2. Roots of SQL, however, are in SQUARE (Specifying Queries as Relational Expressions), which predates System R project. Ritu CHaturvedi Some figures are adapted from Fundamentals of Database Systems By Elmasri and Navathe

History of SQL In late 70s, ORACLE appeared and was probably first commercial RDBMS based on SQL. In 1987, ANSI and ISO published an initial standard for SQL. In 1989, ISO published an addendum that defined an ‘Integrity Enhancement Feature’. In 1992, first major revision to ISO standard occurred, referred to as SQL2 or SQL/92. In 1999, SQL3 was released with support for object-oriented data management. Ritu CHaturvedi Some figures are adapted from Fundamentals of Database Systems By Elmasri and Navathe

Importance of SQL SQL has become part of application architectures such as IBM’s Systems Application Architecture. It is strategic choice of many large and influential organizations (e.g. X/OPEN). SQL is Federal Information Processing Standard (FIPS) to which conformance is required for all sales of databases to American Government. Ritu CHaturvedi Some figures are adapted from Fundamentals of Database Systems By Elmasri and Navathe

Importance of SQL SQL is used in other standards and even influences development of other standards as a definitional tool. Examples include: ISO’s Information Resource Directory System (IRDS) Standard Remote Data Access (RDA) Standard. Ritu CHaturvedi Some figures are adapted from Fundamentals of Database Systems By Elmasri and Navathe

Writing SQL Commands SQL statement consists of reserved words and user-defined words. Reserved words are a fixed part of SQL and must be spelt exactly as required and cannot be split across lines. User-defined words are made up by user and represent names of various database objects such as relations, columns, views. Ritu CHaturvedi Some figures are adapted from Fundamentals of Database Systems By Elmasri and Navathe

Writing SQL Commands Most components of an SQL statement are case insensitive, except for literal character data. More readable with indentation and lineation: Each clause should begin on a new line. Start of a clause should line up with start of other clauses. If clause has several parts, should each appear on a separate line and be indented under start of clause. Ritu CHaturvedi Some figures are adapted from Fundamentals of Database Systems By Elmasri and Navathe

Writing SQL Commands Use extended form of BNF notation: - Upper-case letters represent reserved words. - Lower-case letters represent user-defined words. - | indicates a choice among alternatives. - Curly braces indicate a required element. - Square brackets indicate an optional element. - … indicates optional repetition (0 or more). Ritu CHaturvedi Some figures are adapted from Fundamentals of Database Systems By Elmasri and Navathe

Literals Literals are constants used in SQL statements. All non-numeric literals must be enclosed in single quotes (e.g. ‘London’). All numeric literals must not be enclosed in quotes (e.g. 650.00). Ritu CHaturvedi Some figures are adapted from Fundamentals of Database Systems By Elmasri and Navathe

CREATE TABLE Specifies a new base relation by giving it a name, and specifying each of its attributes and their data types (INTEGER, FLOAT, DECIMAL(i,j), CHAR(n), VARCHAR(n)) A constraint NOT NULL may be specified on an attribute CREATE TABLE DEPARTMENT ( DNAME VARCHAR(10) NOT NULL, DNUMBER INTEGER NOT NULL, MGRSSN CHAR(9), MGRSTARTDATE CHAR(9) ); Ritu CHaturvedi Some figures are adapted from Fundamentals of Database Systems By Elmasri and Navathe

Data Definition and Constraints Used to CREATE, DROP, and ALTER the descriptions of the tables (relations) of a database Ritu CHaturvedi Some figures are adapted from Fundamentals of Database Systems By Elmasri and Navathe

CREATE TABLE You can use the CREATE TABLE command for specifying the primary key attributes, secondary keys, and referential integrity constraints (foreign keys). Key attributes can be specified via the PRIMARY KEY and UNIQUE phrases CREATE TABLE DEPT ( DNAME VARCHAR(10) NOT NULL, DNUMBER INTEGER NOT NULL, MGRSSN CHAR(9), MGRSTARTDATE CHAR(9), PRIMARY KEY (DNUMBER), UNIQUE (DNAME), FOREIGN KEY (MGRSSN) REFERENCES EMP ); Ritu CHaturvedi Some figures are adapted from Fundamentals of Database Systems By Elmasri and Navathe

DROP TABLE Used to remove a relation (base table) and its definition The relation can no longer be used in queries, updates, or any other commands since its description no longer exists Example: DROP TABLE DEPENDENT; Ritu CHaturvedi Some figures are adapted from Fundamentals of Database Systems By Elmasri and Navathe

ALTER TABLE Used to add an attribute to one of the base relations The new attribute will have NULLs in all the tuples of the relation right after the command is executed; hence, the NOT NULL constraint is not allowed for such an attribute Example: ALTER TABLE EMPLOYEE ADD JOB VARCHAR(12); The database users must still enter a value for the new attribute JOB for each EMPLOYEE tuple. This can be done using the UPDATE command. Ritu CHaturvedi Some figures are adapted from Fundamentals of Database Systems By Elmasri and Navathe

Features Added in SQL2 and SQL-99 REFERENTIAL INTEGRITY OPTIONS Ritu CHaturvedi Some figures are adapted from Fundamentals of Database Systems By Elmasri and Navathe

REFERENTIAL INTEGRITY OPTIONS We can specify RESTRICT, CASCADE, SET NULL or SET DEFAULT on referential integrity constraints (foreign keys) CREATE TABLE DEPT ( DNAME VARCHAR(10) NOT NULL, DNUMBER INTEGER NOT NULL, MGRSSN CHAR(9), MGRSTARTDATE CHAR(9), PRIMARY KEY (DNUMBER), UNIQUE (DNAME), FOREIGN KEY (MGRSSN) REFERENCES EMP ON DELETE SET NULL); Ritu CHaturvedi Some figures are adapted from Fundamentals of Database Systems By Elmasri and Navathe

REFERENTIAL INTEGRITY OPTIONS (continued) CREATE TABLE EMP ( ENAME VARCHAR(30) NOT NULL, ESSN CHAR(9), BDATE DATE, DNO INTEGER DEFAULT 1, SUPERSSN CHAR(9), PRIMARY KEY (ESSN), FOREIGN KEY (DNO) REFERENCES DEPT ON DELETE SET NULL , FOREIGN KEY (SUPERSSN) REFERENCES EMP ON DELETE SET NULL); Ritu CHaturvedi Some figures are adapted from Fundamentals of Database Systems By Elmasri and Navathe

Retrieval Queries in SQL SQL has one basic statement for retrieving information from a database; the SELECT statement This is not the same as the SELECT operation of the relational algebra Important distinction between SQL and the formal relational model; SQL allows a table (relation) to have two or more tuples that are identical in all their attribute values Hence, an SQL relation (table) is a multi-set (sometimes called a bag) of tuples; it is not a set of tuples SQL relations can be constrained to be sets by specifying PRIMARY KEY or UNIQUE attributes, or by using the DISTINCT option in a query Ritu CHaturvedi Some figures are adapted from Fundamentals of Database Systems By Elmasri and Navathe

Retrieval Queries in SQL (cont.) Basic form of the SQL SELECT statement is called a mapping or a SELECT-FROM-WHERE block SELECT <attribute list> FROM <table list> WHERE <condition> <attribute list> is a list of attribute names whose values are to be retrieved by the query <table list> is a list of the relation names required to process the query <condition> is a conditional (Boolean) expression that identifies the tuples to be retrieved by the query Ritu CHaturvedi Some figures are adapted from Fundamentals of Database Systems By Elmasri and Navathe

Relational Database Schema Ritu CHaturvedi Some figures are adapted from Fundamentals of Database Systems By Elmasri and Navathe