Session - 6 Sequence - 1 SQL: The Structured Query Language:

Slides:



Advertisements
Similar presentations
Fundamentals of Database Systems Fourth Edition El Masri & Navathe
Advertisements

MySQL. To start go to Login details: login: labuser password:macimd15 – There.
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.
SQL Lecture 10 Inst: Haya Sammaneh. Example Instance of Students Relation  Cardinality = 3, degree = 5, all rows distinct.
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 © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 4 SQL: Data Definition, Constraints, and Basic Queries and Updates.
CS 104 Introduction to Computer Science and Graphics Problems Introduction to Database (2) Basic SQL 12/05/2008 Yang Song.
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. 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.
1 CSE 480: Database Systems Lecture 9: SQL-DDL Reference: Read Chapter of the textbook.
SQL Overview Defining a Schema CPSC 315 – Programming Studio Slides adapted from those used by Jeffrey Ullman, via Jennifer Welch Via Yoonsuck Choe.
CSE314 Database Systems Lecture 4 Basic SQL Doç. Dr. Mehmet Göktürk src: Elmasri & Navanthe 6E Pearson Ed Slide Set.
AL-MAAREFA COLLEGE FOR SCIENCE AND TECHNOLOGY INFO 232: DATABASE SYSTEMS CHAPTER 7 INTRODUCTION TO STRUCTURED QUERY LANGUAGE (SQL) Instructor Ms. Arwa.
Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe Chapter 8 SQL-99: Schema Definition, Constraints, and Queries and Views.
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.
Chapter 7 SQL HUANG XUEHUA. SQL SQL server2005 introduction Install components  management studio.
SQL: DDL. SQL Statements DDL - data definition language –Defining and modifying data structures (metadata): database, tables, views, etc. DML - data manipulation.
SQL Basics. What is SQL? SQL stands for Structured Query Language. SQL lets you access and manipulate databases.
DatabaseDatabase cs453 Lab5 1 Ins.Ebtesam AL-Etowi.
Chapter 8 Part 2 SQL-99 Schema Definition, Constraints, Queries, and Views.
Prince Sultan University Dept. of Computer & Information Sciences CS 340 Introduction to Database Systems.
CMPT 258 Database Systems The Relationship Model (Chapter 3)
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.
©Silberschatz, Korth and Sudarshan1 Structured Query Language (SQL) Data Definition Language Domains Integrity Constraints.
1 CS 430 Database Theory Winter 2005 Lecture 10: Introduction to SQL.
CS34311 The Relational Model. cs34312 Why Relational Model? Currently the most widely used Vendors: Oracle, Microsoft, IBM Older models still used IBM’s.
الفصل السادس لغة Structured Query Language) SQL الفصل السادس لغة Structured Query Language) SQL.
Physical Model Lecture 11. Physical Data Model The last step is the physical design phase, In this phase data is – Store – Organized and – Access.
Copyright © 2004 Pearson Education, Inc. Schema Definition, Basic Constraints, and Queries.
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) هي وسيلة لتوضيح الدرس واداة.
CPSC-310 Database Systems
Structured Query Language
Chapter 10 SQL DDL.
Fundamental of Database Systems
SQL: SchemaDefinition, Constraints, and Queries and Views
SQL: Schema Definition and Constraints Chapter 6 week 6
Insert, Update and the rest…
CS 480: Database Systems Lecture 13 February 13,2013.
Chapter 4 Basic SQL.
Subject Name: DATA BASE MANAGEMENT SYSTEM Subject Code: 10cs54
11/9/2018.
ORACLE SQL Developer & SQLPLUS Statements
Normalization 2NF & 3NF Presented by: Dr. Samir Tartir
Instructor: Mohamed Eltabakh
لغة قواعد البيانات STRUCTURED QUERY LANGUAGE SQL))
CS4222 Principles of Database System
Session - 6 Sequence - 2 SQL: The Structured Query Language:
SQL OVERVIEW DEFINING A SCHEMA
Chapter 4 & 5 Basic SQL More SQL
Defining a Database Schema
SQL-1 Week 8-9.
Session - 6 Sequence - 1 SQL: The Structured Query Language:
Structured Query Language (3)
SQL-99: Schema Definition, Constraints, and Queries and Views
Chapter # 7 Introduction to Structured Query Language (SQL) Part I.
Session - 6 Sequence - 5 SQL Updating Database Contents
ISC321 Database Systems I Chapter 4: SQL: Data definition, Constraints, and Basic Queries and Updates Fall 2015 Dr. Abdullah Almutairi.
CS4433 Database Systems Relational Model.
SQL Updating Database Contents Presented by: Dr. Samir Tartir
SQL (Structured Query Language)
Presentation transcript:

Session - 6 Sequence - 1 SQL: The Structured Query Language: Introduction and Tables Presented by: Dr. Samir Tartir

Outline Introduction Relational Algebra Versions Scope Data Types Creating, Altering and Dropping Tables

Introduction SQL is the standard for relational databases. The official pronunciation is “es queue el” Some still use “sequel”. It is based on Relational Algebra and Relational Calculus. User-friendly syntax

Relational Algebra vs. SQL RA operations are too technical for most users. SQL is a high-level declarative language interface. The DBMS decides on the best execution of the query.

Versions SQL1 (or SQL-86): SQL2 (or SQL-92): A joint effort by ANSI (the American National Standards Institute) and ISO (the International Standards Organization). SQL2 (or SQL-92): Major revision: New data types, additional character sets, set operations, etc Other versions with minor revisions exist SQL3, SQL-2003, SQL-2006, SQL-2008

SQL Scope Schema: Data: Data Access Control creation and modification DDL Data: insert, query, update and delete DML Data Access Control DCL

Vocabulary SQL uses the terms “Table” for “Relation” “Row” for “Tuple” “Column” for “Attribute”

SQL Data Types Numeric Character Strings Integers Real numbers INTEGER, and SMALLINT Real numbers FLOAT, REAL, DOUBLE PRECISION Formatted numbers DECIMAL(i,j) or NUMERIC(i,j) Character Strings CHAR(n), VARCHAR(n)

SQL Data Types Date and Time: DATE: TIME: TIME(i): Made up of year-month-day in the format yyyy-mm-dd TIME: Made up of hour:minute:second in the format hh:mm:ss TIME(i): Made up of hour:minute:second plus i additional digits specifying fractions of a second format is hh:mm:ss:ii...i

SQL Data Types TIMESTAMP: INTERVAL: Has both DATE and TIME components Specifies a relative value rather than an absolute value Can be DAY/TIME intervals or YEAR/MONTH intervals Can be positive or negative when added to or subtracted from an absolute value, the result is an absolute value

Company ER Schema

Relational Schema Mapping

CREATE TABLE Specifies a new base relation by giving it a name, and specifying each of its attributes and their data types. A constraint NOT NULL may be specified on an attribute

Example CREATE TABLE DEPARTMENT ( DNAME VARCHAR(10) NOT NULL, Table Name CREATE TABLE DEPARTMENT ( DNAME VARCHAR(10) NOT NULL, DNUMBER INTEGER NOT NULL, MGRSSN CHAR(9), MGRSTARTDATE CHAR(9) ); Column Names Column Types Null?

CREATE TABLE Primary key Secondary keys Referential integrity constraints (foreign keys) Key attributes can be specified via the PRIMARY KEY and UNIQUE phrases

Example 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 );

REFERENTIAL INTEGRITY OPTIONS 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 DEFAULT ON UPDATE CASCADE );

REFERENTIAL INTEGRITY OPTIONS 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 DEFAULT ON UPDATE CASCADE, FOREIGN KEY (SUPERSSN) REFERENCES EMP ON DELETE SET NULL ON UPDATE CASCADE);

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 Adding a job description to each employee 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.

Example Modify the size of the last name field to 50. ALTER TABLE EMPLOYEE MODIFY LNAME VARCHAR(50);

Example Remove the birthdate column from the Employee table. ALTER TABLE EMPLOYEE DROP COLUMN BIRTHDATE;

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;

DROP TABLE If a table has other tables connect to (using foreign keys), it can’t be removed until the foreign keys are removed first. Or, using the following statement that removes the table and any foreign key constraints connected to it. Example: DROP TABLE EMPLOYEE CASCADE CONSTRAINTS;

SUMMARY Introduction to SQL Data Types Manipulating Tables

Resources & References Dr. Samir Tartir Email: startir@philadelphia.edu.jo Website: http://www.philadelphia.edu.jo/academics/startir Fundamentals of Database Systems by El Masri & Navathe. Publisher : Addison-Wesley, 5th edition, 2006.