Chapter 7 SQL: Data Definition Pearson Education © 2009.

Slides:



Advertisements
Similar presentations
Data Definition and Integrity Constraints
Advertisements

SQL DDL & DML. 2 Objectives of SQL u SQL is a transform-oriented language with 2 major components: –A DDL for defining database structure. –A DML for.
Chapter 3 The Relational Model Transparencies © Pearson Education Limited 1995, 2005.
Maintaining Referential Integrity Pertemuan 2 Matakuliah: T0413/Current Popular IT II Tahun: 2007.
Database Systems: A Practical Approach to Design, Implementation and Management International Computer Science S. Carolyn Begg, Thomas Connolly Lecture.
Chapter 7 SQL: Data Definition Pearson Education © 2009.
Using SQL to create tables Ways of using Databases.
1 Pertemuan 11 SQL Data Definition Matakuliah: >/ > Tahun: > Versi: >
© Pearson Education Limited, Chapter 3 SQL and QBE Transparencies.
SQL DDL constraints Restrictions on the columns and tables 1SQL DDL Constraints.
LOGICAL DATABASE DESIGN
CSC 240 (Blum)1 Data Definition Language Based on Chapter 6 of Database Systems (Connolly and Begg)
Module 9: Managing Schema Objects. Overview Naming guidelines for identifiers in schema object definitions Storage and structure of schema objects Implementing.
Chapter 4 The Relational Model Pearson Education © 2014.
© Pearson Education Limited, Chapter 2 The Relational Model Transparencies.
Relational Model Session 6 Course Name: Database System Year : 2012.
Chapter 7 SQL: Data Definition Pearson Education © 2009.
Learningcomputer.com SQL Server 2008 – Entity Relationships in a Database.
INTEGRITY. Integrity constraint Integrity constraints are specified on a database schema and are expected to hold on every valid database state of the.
SQL Data Definition (CB Chapter 6) CPSC 356 Database Ellen Walker Hiram College (Includes figures from Database Systems by Connolly & Begg, © Addison Wesley.
Chapter 6 SQL Data Definition Language Chapter 7 in Textbook.
1 Chapter 2 Database Environment Transparencies © Pearson Education Limited 1995, 2005.
Chapter 8 Part 1 SQL-99 Schema Definition, Constraints, Queries, and Views.
10/25/2012ISC239 Isabelle Bichindaritz1 SQL Commands.
Ms. Hatoon Al-Sagri CCIS – IS Department SQL-99 :Schema Definition, Constraints, Queries, and Views 1.
Chapter 9 Methodology - Logical Database Design Chapter 16 in Textbook.
SQL: DDL John Ortiz Cs.utsa.edu.
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.
SQL : Data Definition Session 9 – 10 Course Name: Database System Year : 2012.
Dec 8, 2003Murali Mani Constraints B term 2004: lecture 15.
Constraints cis 407 Types of Constraints & Naming Key Constraints Unique Constraints Check Constraints Default Constraints Misc Rules and Defaults Triggers.
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.
Chapter 6 SQL: Data Definition Transparencies. 2 Chapter 6 - Objectives u Data types supported by SQL standard. u Purpose of integrity enhancement feature.
Chapter 4 Constraints Oracle 10g: SQL. Oracle 10g: SQL 2 Objectives Explain the purpose of constraints in a table Distinguish among PRIMARY KEY, FOREIGN.
Chapter 6 SQL: Data Definition Transparencies Last Updated: 10 th March 2011 By M. Arief
Chapter Name SQL: Data Definition
Lecture5: SQL Overview, Oracle Data Type, DDL and Constraints Ref. Chapter6 Lecture4 1.
Chapter 6 SQL: Data Definition Transparencies © Pearson Education Limited 1995, 2005.
Data Definition Language
Chapter 6 SQL: Data Definition Transparencies © Pearson Education Limited 1995, 2005.
Chapter 3: Relational Databases
Lecture 03 Constraints. Example Schema CONSTRAINTS.
Chapter 7 SQL – Data Definition Pearson Education © 2014.
Chapter 3 The Relational Model. Objectives u Terminology of relational model. u How tables are used to represent data. u Connection between mathematical.
Constraints and Views Chap. 3-5 continued (7 th ed. 5-7)
Chapter 4 The Relational Model Pearson Education © 2009.
SQL DDL & DML. 2 Objectives of SQL u SQL is a transform-oriented language with 2 major components: –A DDL for defining database structure. –A DML for.
Fundamental of Database Systems
國立臺北科技大學 課程:資料庫系統 Chapter 7 SQL Data Definition.
SQL: Data Definition Transparencies
SQL: Schema Definition and Constraints Chapter 6 week 6
Chapter 7 SQL – Data Definition Pearson Education © 2014.
Minggu 5, Pertemuan 9 SQL: Data Definition
Introduction to SQL Chapter 3.
© Pearson Education Limited, 2004
لغة قواعد البيانات STRUCTURED QUERY LANGUAGE SQL))
Chapter 4 The Relational Model Pearson Education © 2009.
CS122 Using Relational Databases and SQL
Oracle Data Definition Language (DDL)
Chapter 7 SQL – Data Definition Pearson Education © 2014.
Chapter 4 The Relational Model Pearson Education © 2009.
CS122 Using Relational Databases and SQL
Chapter 4 The Relational Model Pearson Education © 2009.
CS1222 Using Relational Databases and SQL
CS122 Using Relational Databases and SQL
Integrity 5/5/2019 See scm-intranet.
CS122 Using Relational Databases and SQL
Presentation transcript:

Chapter 7 SQL: Data Definition Pearson Education © 2009

2 ISO SQL Data Types Pearson Education © 2009

3 Integrity Enhancement Feature u Consider five types of integrity constraints: –required data –domain constraints –entity integrity –referential integrity –general constraints. Pearson Education © 2009

4 IEF - Entity Integrity u Primary key of a table must contain a unique, non-null value for each row. u ISO standard supports FOREIGN KEY clause in CREATE and ALTER TABLE statements: PRIMARY KEY(staffNo) PRIMARY KEY(clientNo, propertyNo) u Can only have one PRIMARY KEY clause per table. Can still ensure uniqueness for alternate keys using UNIQUE: UNIQUE(telNo) Pearson Education © 2009

5 IEF - Referential Integrity u FK is column or set of columns that links each row in child table containing foreign FK to row of parent table containing matching PK. u Referential integrity means that, if FK contains a value, that value must refer to existing row in parent table. u ISO standard supports definition of FKs with FOREIGN KEY clause in CREATE and ALTER TABLE: FOREIGN KEY(branchNo) REFERENCES Branch Pearson Education © 2009

6 IEF - Referential Integrity u Any INSERT/UPDATE attempting to create FK value in child table without matching CK value in parent is rejected. u Action taken attempting to update/delete a CK value in parent table with matching rows in child is dependent on referential action specified using ON UPDATE and ON DELETE subclauses: –CASCADE- SET NULL –SET DEFAULT- NO ACTION Pearson Education © 2009

7 IEF - Referential Integrity CASCADE: Delete row from parent and delete matching rows in child, and so on in cascading manner. SET NULL: Delete row from parent and set FK column(s) in child to NULL. Only valid if FK columns are NOT NULL. SET DEFAULT: Delete row from parent and set each component of FK in child to specified default. Only valid if DEFAULT specified for FK columns. NO ACTION: Reject delete from parent. Default. Pearson Education © 2009

8 IEF - Referential Integrity FOREIGN KEY (staffNo) REFERENCES Staff ON DELETE SET NULL FOREIGN KEY (ownerNo) REFERENCES Owner ON UPDATE CASCADE Pearson Education © 2009

9 Data Definition u SQL DDL allows database objects such as schemas, domains, tables, views, and indexes to be created and destroyed. u Main SQL DDL statements are: CREATE SCHEMADROP SCHEMA CREATE/ALTER DOMAINDROP DOMAIN CREATE/ALTER TABLEDROP TABLE CREATE VIEWDROP VIEW u Many DBMSs also provide: CREATE INDEXDROP INDEX Pearson Education © 2009

10 CREATE TABLE CREATE TABLE TableName {(colName dataType [NOT NULL] [UNIQUE] [DEFAULT defaultOption] [CHECK searchCondition] [,...]} [PRIMARY KEY (listOfColumns),] {[UNIQUE (listOfColumns),] […,]} {[FOREIGN KEY (listOfFKColumns) REFERENCES ParentTableName [(listOfCKColumns)], [ON UPDATE referentialAction] [ON DELETE referentialAction ]] [,…]} {[CHECK (searchCondition)] [,…] }) Pearson Education © 2009