Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 4 Basic SQL تنبيه : شرائح العرض (Slides) هي وسيلة لتوضيح الدرس واداة.

Slides:



Advertisements
Similar presentations
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 5 More SQL: Complex Queries, Triggers, Views, and Schema Modification.
Advertisements

Chapter 23 Database Security and Authorization Copyright © 2004 Pearson Education, Inc.
Relational Database. Relational database: a set of relations Relation: made up of 2 parts: − Schema : specifies the name of relations, plus name and type.
The Relational Model. Introduction Introduced by Ted Codd at IBM Research in 1970 The relational model represents data in the form of table. Main concept.
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.
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.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 5 More SQL: Complex Queries, Triggers, Views, and Schema Modification.
Copyright © 2004 Pearson Education, Inc.. Chapter 5 The Relational Data Model and Relational Database Constraints.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 3 The Basic (Flat) Relational Model.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 4 SQL: Data Definition, Constraints, and Basic Queries and Updates.
Copyright © 2004 Pearson Education, Inc.. Chapter 8 SQL-99: Schema Definition, Basic Constraints, and Queries.
Database Systems More SQL Database Design -- More SQL1.
SQL DDL constraints Restrictions on the columns and tables 1SQL DDL Constraints.
Elmasri and Navathe, Fundamentals of Database Systems, Fourth Edition Copyright © 2004 Pearson Education, Inc. Slide 2-1 Data Models Example: A relation.
Database Constraints. Database constraints are restrictions on the contents of the database or on database operations Database constraints provide a way.
1 CSE 480: Database Systems Lecture 9: SQL-DDL Reference: Read Chapter of the textbook.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 4 Basic SQL.
CSE314 Database Systems Lecture 4 Basic SQL Doç. Dr. Mehmet Göktürk src: Elmasri & Navanthe 6E Pearson Ed Slide Set.
BASIC SQL CHAPTER 4 (6/E) CHAPTER 8 (5/E) 1. LECTURE OUTLINE  SQL Data Definition and Data Types  Specifying Constraints in SQL  Basic Retrieval Queries.
Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe Chapter 8 SQL-99: Schema Definition, Constraints, and Queries and Views.
CSE314 Database Systems More SQL: Complex Queries, Triggers, Views, and Schema Modification Doç. Dr. Mehmet Göktürk src: Elmasri & Navanthe 6E Pearson.
SQL Data Definition (CB Chapter 6) CPSC 356 Database Ellen Walker Hiram College (Includes figures from Database Systems by Connolly & Begg, © Addison Wesley.
Chapter 10 – Database Creation1 IT238: Data Modeling and Database Design Unit 6: Database Creation Instructor: Qing Yan, M.D., Ph.D.
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.
SQL: DDL. SQL Statements DDL - data definition language –Defining and modifying data structures (metadata): database, tables, views, etc. DML - data manipulation.
© 2009 Pearson Education, Inc. Publishing as Prentice Hall 1 Chapter 7 (Part a): Introduction to SQL Modern Database Management 9 th Edition Jeffrey A.
Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe Chapter 6 Data Integrity and Security.
Database Systems Design, Implementation, and Management Coronel | Morris 11e ©2015 Cengage Learning. All Rights Reserved. May not be scanned, copied or.
SQL Basics. What is SQL? SQL stands for Structured Query Language. SQL lets you access and manipulate databases.
IS 230Lecture 6Slide 1 Lecture 7 Advanced SQL Introduction to Database Systems IS 230 This is the instructor’s notes and student has to read the textbook.
Chapter 8 Part 2 SQL-99 Schema Definition, Constraints, Queries, and Views.
Dec 8, 2003Murali Mani Constraints B term 2004: lecture 15.
1 SQL - II Data Constraints –Applying data constraints Types of data constraints –I/O constraints The PRIMARY KEY constraints The FOREIGN KEY constraints.
Chapter 9 Constraints. Chapter Objectives  Explain the purpose of constraints in a table  Distinguish among PRIMARY KEY, FOREIGN KEY, UNIQUE, CHECK,
Oracle 11g: SQL Chapter 4 Constraints.
Prince Sultan University Dept. of Computer & Information Sciences CS 340 Introduction to Database Systems.
7 1 Constraints & Triggers Chapter Constraints and triggers? Constraints: Certain properties that the DBMS is required to enforce –E.g. primary.
Chapter 4 Constraints Oracle 10g: SQL. Oracle 10g: SQL 2 Objectives Explain the purpose of constraints in a table Distinguish among PRIMARY KEY, FOREIGN.
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.
CS34311 The Relational Model. cs34312 Why Relational Model? Currently the most widely used Vendors: Oracle, Microsoft, IBM Older models still used IBM’s.
Copyright © 2016 Ramez Elmasri and Shamkant B. Navathe CHAPTER 6 Basic SQL Slide 6- 1.
Constraints and Views Chap. 3-5 continued (7 th ed. 5-7)
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 9 Relational Database Design by ER- and EER- to-Relational Mapping.
Slide Chapter 8 Views تنبيه : شرائح العرض (Slides) هي وسيلة لتوضيح الدرس واداة من الادوات في ذلك. حيث المرجع الاساسي للمادة هي الكتاب المعتمد في.
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) هي وسيلة لتوضيح الدرس واداة.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 6 The Relational Algebra and Relational Calculus تنبيه : شرائح العرض.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 7 Data Modeling Using the Entity- Relationship (ER) Model تنبيه :
Chapter 3 The Relational Data Model and Relational Database Constraints Copyright © 2004 Pearson Education, Inc.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 3 The Relational Data Model and Relational Database Constraints تنبيه.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 7 Data Modeling Using the Entity- Relationship (ER) Model تنبيه :
Data Modeling Using the Entity- Relationship (ER) Model
More SQL: Complex Queries, Triggers, Views, and Schema Modification
The Relational Algebra and Relational Calculus
Chapter 10 SQL DDL.
Relational Database Design by ER- and EER- to-Relational Mapping
Fundamental of Database Systems
More SQL: Complex Queries,
SQL: Schema Definition and Constraints Chapter 6 week 6
Chapter 4 Basic SQL.
More SQL: Complex Queries, Triggers, Views, and Schema Modification
SQL-1 Week 8-9.
Session - 6 Sequence - 1 SQL: The Structured Query Language:
Structured Query Language (3)
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:
Presentation transcript:

Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 4 Basic SQL تنبيه : شرائح العرض (Slides) هي وسيلة لتوضيح الدرس واداة من الادوات في ذلك. حيث المرجع الاساسي للمادة هي الكتاب المعتمد في وصف المقرر

Copyright © 2011 Ramez Elmasri and Shamkant B. Navathe Basic SQL SQL Considered one of the major reasons for the commercial success of relational databases Statements for data definition (DDL) and data manipulation (DML)

Copyright © 2011 Ramez Elmasri and Shamkant B. Navathe Slide 8- 3 SQL DDL CREATE statement Main SQL command for DDL

Copyright © 2011 Ramez Elmasri and Shamkant B. Navathe Schema Concepts in SQL SQL Schema Identified by a schema name and authorization identifier to indicate who own the schema Schema elements include Tables, constraints, views, and domains Each statement in SQL ends with a semicolon Example CREATE SCHEMA statement CREATE SCHEMA COMPANY AUTHORIZATION ‘Jsmith’;

Copyright © 2011 Ramez Elmasri and Shamkant B. Navathe The CREATE TABLE Command Specify a new relation Provide name Specify attributes and initial constraints Can optionally specify schema: CREATE TABLE COMPANY.EMPLOYEE... or CREATE TABLE EMPLOYEE...

Copyright © 2011 Ramez Elmasri and Shamkant B. Navathe The CREATE TABLE Command (cont’d.) Base tables (base relations) Relation and its tuples are actually created and stored as a file by the DBMS Virtual relations Created through the CREATE VIEW statement

Copyright © 2011 Ramez Elmasri and Shamkant B. Navathe Slide 8- 7 CREATE TABLE

Copyright © 2011 Ramez Elmasri and Shamkant B. Navathe Slide 8- 8

Copyright © 2011 Ramez Elmasri and Shamkant B. Navathe Specifying Constraints in SQL Basic constraints: Key and referential integrity constraints Restrictions on attribute domains and NULLs Constraints on individual tuples within a relation Slide 8- 9

Copyright © 2011 Ramez Elmasri and Shamkant B. Navathe Specifying Attribute Constraints and Attribute Defaults NOT NULL NULL is not permitted for a particular attribute Default value DEFAULT CHECK clause Dnumber INT NOT NULL CHECK (Dnumber > 0 AND Dnumber < 21); Keyword CONSTRAINT Name a constraint Useful for later altering Slide 8- 10

Copyright © 2011 Ramez Elmasri and Shamkant B. Navathe Slide 8- 11

Copyright © 2011 Ramez Elmasri and Shamkant B. Navathe Specifying Key and Referential Integrity Constraints PRIMARY KEY clause Specifies one or more attributes that make up the primary key of a relation Dnumber INT PRIMARY KEY; UNIQUE clause Specifies alternate (secondary) keys Dname VARCHAR(15) UNIQUE; Slide 8- 12

Copyright © 2011 Ramez Elmasri and Shamkant B. Navathe Specifying Key and Referential Integrity Constraints (cont’d.) FOREIGN KEY clause Default operation: reject update on violation Attach referential triggered action clause Options include SET NULL, CASCADE, and SET DEFAULT Slide 8- 13

Copyright © 2011 Ramez Elmasri and Shamkant B. Navathe Specifying Constraints on Tuples Using CHECK CHECK clauses at the end of a CREATE TABLE statement Apply to each tuple individually Example: Suppose that the table department contains additional attribute for holding the date of creation of the department, so we can add this check at the end of create statement CHECK ( Dept_create_date <= Mgr_start_date );

Copyright © 2011 Ramez Elmasri and Shamkant B. Navathe The DROP Command DROP command Used to drop named schema elements, such as tables or constraint Drop behavior options: CASCADE and RESTRICT

Copyright © 2011 Ramez Elmasri and Shamkant B. Navathe DROP SCHEMA Example: To remove the company database schema and all its tables, domains, and other elements the cascade option is used DROP SCHEMA COMPANY CASCADE; If the RESTRICT option is used, the schema is dropped only if it has no elements in it; otherwise, the DROP command will not be executed

Copyright © 2011 Ramez Elmasri and Shamkant B. Navathe Slide DROP TABLE Used to remove a relation 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 CASCADE ; WITH CASCADE OPTION ALL CONSTAINTS AND VIEWS THAT REFERENCE THE TABLE ARE DROPED AUTOMATICALLY FROM THE SCHEMA WITH RESTRICT OPTION The table will dropped only if it is not referenced in any constraints

Copyright © 2011 Ramez Elmasri and Shamkant B. Navathe The ALTER Command Alter table actions include: Adding or dropping a column (attribute) Changing a column definition Adding or dropping table constraints

Copyright © 2011 Ramez Elmasri and Shamkant B. Navathe The ALTER Command Example: ALTER TABLE COMPANY.EMPLOYEE ADD COLUMN Job VARCHAR(12); The value of the new attribute is set using The DEFAULT value Or the UPDATE command If no default clause is specified, the new attribute will have a NULL in all the tuples of the relation immediately after the command is executed Hence the NOT NULL constraint is not allowed in this case

Copyright © 2011 Ramez Elmasri and Shamkant B. Navathe The ALTER Command (cont’d.) Remove the attribute ALTER TABLE compny.employee DROP COLUMN Address CASCADE; Remove the default value ALTER TABLE compny.department ALTER COLUMN Mgr_ssn DROP DEFAULT; Change the default value ALTER TABLE compny.department ALTER COLUMN Mgr_ssn SET DEFAULT “ ”; Remove the constraint ALTER TABLE compny.employee DROP CONSTRAINT empsuperfk CASCADE;