SlideShare uma empresa Scribd logo
1 de 25
Including Constraints
Objectives ,[object Object],[object Object],[object Object]
What Are Constraints? ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Constraint Guidelines ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Defining Constraints CREATE TABLE [ schema .] table   ( column   datatype  [DEFAULT  expr ] [ column_constraint ], ... [ table_constraint ][,...]); CREATE TABLE emp(   empno  NUMBER(4),   ename  VARCHAR2(10),   ...   deptno  NUMBER(7,2) NOT NULL,   CONSTRAINT emp_empno_pk    PRIMARY KEY (EMPNO));
Defining Constraints ,[object Object],[object Object],column  [CONSTRAINT  constraint_name ]  constraint_type , column,... [CONSTRAINT  constraint_name ]  constraint_type ( column , ...),
The NOT NULL Constraint ,[object Object],EMP EMPNO  ENAME  JOB  ...  COMM  DEPTNO  7839 KING PRESIDENT   10 7698 BLAKE MANAGER   30 7782 CLARK MANAGER   10 7566 JONES MANAGER   20 ... NOT NULL constraint (no row can contain a null value for this column) Absence of NOT NULL constraint (any row can contain null for this column) NOT NULL constraint
The NOT NULL Constraint ,[object Object],SQL> CREATE TABLE emp( 2  empno  NUMBER(4), 3 ename VARCHAR2(10) NOT NULL, 4 job VARCHAR2(9), 5 mgr NUMBER(4), 6 hiredate DATE, 7 sal NUMBER(7,2), 8  comm NUMBER(7,2), 9 deptno NUMBER(7,2) NOT NULL);
The UNIQUE Key Constraint DEPT  DEPTNO DNAME  LOC  ------ ---------- -------- 10 ACCOUNTING NEW YORK 20 RESEARCH DALLAS 30 SALES CHICAGO 40 OPERATIONS BOSTON UNIQUE key constraint 50 SALES DETROIT 60 BOSTON Insert into Not allowed  (DNAME  SALES  already exists) Allowed
The UNIQUE Key Constraint ,[object Object],SQL> CREATE TABLE  dept( 2  deptno    NUMBER(2), 3 dname   VARCHAR2(14), 4 loc   VARCHAR2(13), 5 CONSTRAINT dept_dname_uk UNIQUE(dname));
The PRIMARY KEY Constraint DEPT  DEPTNO DNAME  LOC  ------ ---------- -------- 10 ACCOUNTING NEW YORK 20 RESEARCH DALLAS 30 SALES CHICAGO 40 OPERATIONS BOSTON PRIMARY KEY Insert into 20 MARKETING DALLAS FINANCE NEW YORK Not allowed (DEPTNO  20 already exists) Not allowed (DEPTNO is null)
The PRIMARY KEY Constraint ,[object Object],SQL> CREATE TABLE  dept( 2  deptno    NUMBER(2), 3 dname   VARCHAR2(14), 4 loc   VARCHAR2(13), 5 CONSTRAINT dept_dname_uk UNIQUE (dname), 6 CONSTRAINT dept_deptno_pk PRIMARY KEY(deptno));
The FOREIGN KEY Constraint DEPT  DEPTNO DNAME  LOC  ------ ---------- -------- 10 ACCOUNTING NEW YORK 20 RESEARCH DALLAS ... PRIMARY KEY EMP EMPNO  ENAME  JOB  ...  COMM  DEPTNO  7839 KING PRESIDENT   10 7698 BLAKE MANAGER   30 ... FOREIGN KEY 7571 FORD MANAGER  ...  200   9 7571 FORD MANAGER  ...  200  20 Insert into Not allowed (DEPTNO  9  does not exist in the DEPT table) Allowed
The FOREIGN KEY Constraint ,[object Object],SQL> CREATE TABLE emp( 2  empno  NUMBER(4), 3 ename VARCHAR2(10) NOT NULL, 4 job VARCHAR2(9), 5 mgr NUMBER(4), 6 hiredate DATE, 7 sal NUMBER(7,2), 8  comm NUMBER(7,2), 9 deptno NUMBER(7,2) NOT NULL, 10 CONSTRAINT emp_deptno_fk FOREIGN KEY (deptno) 11 REFERENCES dept (deptno));
FOREIGN KEY Constraint  Keywords ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
The CHECK Constraint ,[object Object],[object Object],[object Object],[object Object],[object Object],..., deptno NUMBER(2), CONSTRAINT emp_deptno_ck  CHECK (DEPTNO BETWEEN 10 AND 99),...
Adding a Constraint ,[object Object],[object Object],[object Object],ALTER TABLE   table ADD [CONSTRAINT  constraint ]  type  ( column );
Adding a Constraint ,[object Object],SQL> ALTER TABLE  emp 2  ADD CONSTRAINT  emp_mgr_fk  3  FOREIGN KEY(mgr) REFERENCES emp(empno); Table altered.
Dropping a Constraint ,[object Object],SQL> ALTER TABLE   emp 2  DROP CONSTRAINT  emp_mgr_fk; Table altered. ,[object Object],SQL> ALTER TABLE dept 2  DROP PRIMARY KEY CASCADE; Table altered.
Disabling Constraints ,[object Object],[object Object],SQL> ALTER TABLE emp 2  DISABLE CONSTRAINT emp_empno_pk CASCADE; Table altered.
Enabling Constraints ,[object Object],[object Object],SQL> ALTER TABLE emp 2  ENABLE CONSTRAINT emp_empno_pk; Table altered.
Viewing Constraints ,[object Object],CONSTRAINT_NAME  C SEARCH_CONDITION ------------------------ - -------------------------  SYS_C00674  C EMPNO IS NOT NULL  SYS_C00675  C DEPTNO IS NOT NULL EMP_EMPNO_PK   P ... SQL>  SELECT constraint_name, constraint_type, 2 search_condition 3  FROM user_constraints 4  WHERE table_name = 'EMP';
Viewing the Columns Associated with Constraints ,[object Object],CONSTRAINT_NAME  COLUMN_NAME ------------------------- ---------------------- EMP_DEPTNO_FK  DEPTNO EMP_EMPNO_PK  EMPNO EMP_MGR_FK  MGR SYS_C00674  EMPNO SYS_C00675  DEPTNO SQL> SELECT constraint_name, column_name 2  FROM user_cons_columns 3  WHERE table_name = 'EMP';
Summary ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Practice Overview ,[object Object],[object Object],[object Object]

Mais conteúdo relacionado

Mais procurados

MySQL partitions tutorial
MySQL partitions tutorialMySQL partitions tutorial
MySQL partitions tutorialGiuseppe Maxia
 
SQL WORKSHOP::Lecture 12
SQL WORKSHOP::Lecture 12SQL WORKSHOP::Lecture 12
SQL WORKSHOP::Lecture 12Umair Amjad
 
SQL WORKSHOP::Lecture 11
SQL WORKSHOP::Lecture 11SQL WORKSHOP::Lecture 11
SQL WORKSHOP::Lecture 11Umair Amjad
 
Database Management System
Database Management SystemDatabase Management System
Database Management SystemHitesh Mohapatra
 
Oracle naveen Sql
Oracle naveen   SqlOracle naveen   Sql
Oracle naveen Sqlnaveen
 

Mais procurados (20)

Les02
Les02Les02
Les02
 
Les02
Les02Les02
Les02
 
Les00 Intoduction
Les00 IntoductionLes00 Intoduction
Les00 Intoduction
 
Les01 Writing Basic Sql Statements
Les01 Writing Basic Sql StatementsLes01 Writing Basic Sql Statements
Les01 Writing Basic Sql Statements
 
Les11 Including Constraints
Les11 Including ConstraintsLes11 Including Constraints
Les11 Including Constraints
 
Les04 Displaying Data From Multiple Table
Les04 Displaying Data From Multiple TableLes04 Displaying Data From Multiple Table
Les04 Displaying Data From Multiple Table
 
Les12 creating views
Les12 creating viewsLes12 creating views
Les12 creating views
 
Les03 Single Row Function
Les03 Single Row FunctionLes03 Single Row Function
Les03 Single Row Function
 
Oracle: PLSQL Commands
Oracle: PLSQL CommandsOracle: PLSQL Commands
Oracle: PLSQL Commands
 
Les02 Restricting And Sorting Data
Les02 Restricting And Sorting DataLes02 Restricting And Sorting Data
Les02 Restricting And Sorting Data
 
Les05 Aggregating Data Using Group Function
Les05 Aggregating Data Using Group FunctionLes05 Aggregating Data Using Group Function
Les05 Aggregating Data Using Group Function
 
Les06 Subqueries
Les06 SubqueriesLes06 Subqueries
Les06 Subqueries
 
Les01
Les01Les01
Les01
 
MySQL partitions tutorial
MySQL partitions tutorialMySQL partitions tutorial
MySQL partitions tutorial
 
SQL WORKSHOP::Lecture 12
SQL WORKSHOP::Lecture 12SQL WORKSHOP::Lecture 12
SQL WORKSHOP::Lecture 12
 
Best sql plsql material
Best sql plsql materialBest sql plsql material
Best sql plsql material
 
SQL WORKSHOP::Lecture 11
SQL WORKSHOP::Lecture 11SQL WORKSHOP::Lecture 11
SQL WORKSHOP::Lecture 11
 
Database Management System
Database Management SystemDatabase Management System
Database Management System
 
Oracle naveen Sql
Oracle naveen   SqlOracle naveen   Sql
Oracle naveen Sql
 
ORACLE NOTES
ORACLE NOTESORACLE NOTES
ORACLE NOTES
 

Destaque (20)

Unit 07 dbms
Unit 07 dbmsUnit 07 dbms
Unit 07 dbms
 
Unit 08 dbms
Unit 08 dbmsUnit 08 dbms
Unit 08 dbms
 
Les06
Les06Les06
Les06
 
Unit 1 watertech1 merged
Unit 1 watertech1 mergedUnit 1 watertech1 merged
Unit 1 watertech1 merged
 
Unit 03 dbms
Unit 03 dbmsUnit 03 dbms
Unit 03 dbms
 
Unit 01 dbms
Unit 01 dbmsUnit 01 dbms
Unit 01 dbms
 
Unit 04 dbms
Unit 04 dbmsUnit 04 dbms
Unit 04 dbms
 
Unit 05 dbms
Unit 05 dbmsUnit 05 dbms
Unit 05 dbms
 
Unit 02 dbms
Unit 02 dbmsUnit 02 dbms
Unit 02 dbms
 
Unit 2 Java
Unit 2 JavaUnit 2 Java
Unit 2 Java
 
Unit 3 Java
Unit 3 JavaUnit 3 Java
Unit 3 Java
 
Unit 8
Unit 8Unit 8
Unit 8
 
C ppt
C pptC ppt
C ppt
 
INTRODUCTION TO C PROGRAMMING
INTRODUCTION TO C PROGRAMMINGINTRODUCTION TO C PROGRAMMING
INTRODUCTION TO C PROGRAMMING
 
Les14
Les14Les14
Les14
 
Unit 06 dbms
Unit 06 dbmsUnit 06 dbms
Unit 06 dbms
 
Les04
Les04Les04
Les04
 
Les07
Les07Les07
Les07
 
Les05
Les05Les05
Les05
 
Software testing ppt
Software testing pptSoftware testing ppt
Software testing ppt
 

Semelhante a Les11

Semelhante a Les11 (20)

Les10
Les10Les10
Les10
 
e computer notes - Including constraints
e computer notes - Including constraintse computer notes - Including constraints
e computer notes - Including constraints
 
SQL-8 Table Creation.pdf
SQL-8 Table Creation.pdfSQL-8 Table Creation.pdf
SQL-8 Table Creation.pdf
 
Les11[1]Including Constraints
Les11[1]Including ConstraintsLes11[1]Including Constraints
Les11[1]Including Constraints
 
Sql integrity constraints
Sql integrity constraintsSql integrity constraints
Sql integrity constraints
 
SQL WORKSHOP::Lecture 9
SQL WORKSHOP::Lecture 9SQL WORKSHOP::Lecture 9
SQL WORKSHOP::Lecture 9
 
Including Constraints -Oracle Data base
Including Constraints -Oracle Data base Including Constraints -Oracle Data base
Including Constraints -Oracle Data base
 
Entigrity constraint
Entigrity constraintEntigrity constraint
Entigrity constraint
 
Select To Order By
Select  To  Order BySelect  To  Order By
Select To Order By
 
Sql dml & tcl 2
Sql   dml & tcl 2Sql   dml & tcl 2
Sql dml & tcl 2
 
Oracle SQL AND PL/SQL
Oracle SQL AND PL/SQLOracle SQL AND PL/SQL
Oracle SQL AND PL/SQL
 
Connor McDonald 11g for developers
Connor McDonald 11g for developersConnor McDonald 11g for developers
Connor McDonald 11g for developers
 
Dbmsmanual
DbmsmanualDbmsmanual
Dbmsmanual
 
SQL Overview
SQL OverviewSQL Overview
SQL Overview
 
SQLQueries
SQLQueriesSQLQueries
SQLQueries
 
Oraclesql
OraclesqlOraclesql
Oraclesql
 
Les09[1]Manipulating Data
Les09[1]Manipulating DataLes09[1]Manipulating Data
Les09[1]Manipulating Data
 
zekeLabs sql-slides
zekeLabs sql-slideszekeLabs sql-slides
zekeLabs sql-slides
 
4sem dbms(1)
4sem dbms(1)4sem dbms(1)
4sem dbms(1)
 
MySql slides (ppt)
MySql slides (ppt)MySql slides (ppt)
MySql slides (ppt)
 

Mais de arnold 7490 (16)

Unit 8 Java
Unit 8 JavaUnit 8 Java
Unit 8 Java
 
Unit 6 Java
Unit 6 JavaUnit 6 Java
Unit 6 Java
 
Unit 5 Java
Unit 5 JavaUnit 5 Java
Unit 5 Java
 
Unit 4 Java
Unit 4 JavaUnit 4 Java
Unit 4 Java
 
Unit 1 Java
Unit 1 JavaUnit 1 Java
Unit 1 Java
 
Unit 7 Java
Unit 7 JavaUnit 7 Java
Unit 7 Java
 
Unit6 C
Unit6 C Unit6 C
Unit6 C
 
Unit5 C
Unit5 C Unit5 C
Unit5 C
 
Unit4 C
Unit4 C Unit4 C
Unit4 C
 
Unit3 C
Unit3 C Unit3 C
Unit3 C
 
Unit2 C
Unit2 C Unit2 C
Unit2 C
 
Unit1 C
Unit1 CUnit1 C
Unit1 C
 
Unit7 C
Unit7 CUnit7 C
Unit7 C
 
Unit2 C
Unit2 CUnit2 C
Unit2 C
 
Unit1 C
Unit1 CUnit1 C
Unit1 C
 
Unit8 C
Unit8 CUnit8 C
Unit8 C
 

Último

Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfAddepto
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenHervé Boutemy
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clashcharlottematthew16
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyAlfredo García Lavilla
 
Search Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfSearch Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfRankYa
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 3652toLead Limited
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsMiki Katsuragi
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024Stephanie Beckett
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024Lorenzo Miniero
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek SchlawackFwdays
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Patryk Bandurski
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr LapshynFwdays
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfAlex Barbosa Coqueiro
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Mark Simos
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxNavinnSomaal
 
My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024The Digital Insurer
 

Último (20)

Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdf
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache Maven
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clash
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easy
 
Search Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfSearch Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdf
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering Tips
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdf
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptx
 
My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024
 

Les11

  • 2.
  • 3.
  • 4.
  • 5. Defining Constraints CREATE TABLE [ schema .] table ( column datatype [DEFAULT expr ] [ column_constraint ], ... [ table_constraint ][,...]); CREATE TABLE emp( empno NUMBER(4), ename VARCHAR2(10), ... deptno NUMBER(7,2) NOT NULL, CONSTRAINT emp_empno_pk PRIMARY KEY (EMPNO));
  • 6.
  • 7.
  • 8.
  • 9. The UNIQUE Key Constraint DEPT DEPTNO DNAME LOC ------ ---------- -------- 10 ACCOUNTING NEW YORK 20 RESEARCH DALLAS 30 SALES CHICAGO 40 OPERATIONS BOSTON UNIQUE key constraint 50 SALES DETROIT 60 BOSTON Insert into Not allowed (DNAME  SALES already exists) Allowed
  • 10.
  • 11. The PRIMARY KEY Constraint DEPT DEPTNO DNAME LOC ------ ---------- -------- 10 ACCOUNTING NEW YORK 20 RESEARCH DALLAS 30 SALES CHICAGO 40 OPERATIONS BOSTON PRIMARY KEY Insert into 20 MARKETING DALLAS FINANCE NEW YORK Not allowed (DEPTNO  20 already exists) Not allowed (DEPTNO is null)
  • 12.
  • 13. The FOREIGN KEY Constraint DEPT DEPTNO DNAME LOC ------ ---------- -------- 10 ACCOUNTING NEW YORK 20 RESEARCH DALLAS ... PRIMARY KEY EMP EMPNO ENAME JOB ... COMM DEPTNO 7839 KING PRESIDENT 10 7698 BLAKE MANAGER 30 ... FOREIGN KEY 7571 FORD MANAGER ... 200 9 7571 FORD MANAGER ... 200 20 Insert into Not allowed (DEPTNO  9 does not exist in the DEPT table) Allowed
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
  • 25.

Notas do Editor

  1. Schedule: Timing Topic 45 minutes Lecture 25 minutes Practice 70 minutes Total
  2. Lesson Aim In this lesson, you will learn how to implement business rules by including integrity constraints.
  3. Schedule: Timing Topic 45 minutes Lecture 25 minutes Practice 70 minutes Total
  4. Constraint Guidelines All constraints are stored in the data dictionary. Constraints are easy to reference if you give them a meaningful name. Constraint names must follow the standard object-naming rules. If you do not name your constraint, Oracle generates a name with the format SYS_C n , where n is an integer to create a unique constraint name. Constraints can be defined at the time of table creation or after the table has been created. You can view the constraints defined for a specific table by looking at the USER_CONSTRAINTS data dictionary table.
  5. Schedule: Timing Topic 45 minutes Lecture 25 minutes Practice 70 minutes Total
  6. Schedule: Timing Topic 45 minutes Lecture 25 minutes Practice 70 minutes Total
  7. Schedule: Timing Topic 45 minutes Lecture 25 minutes Practice 70 minutes Total
  8. Schedule: Timing Topic 45 minutes Lecture 25 minutes Practice 70 minutes Total
  9. Schedule: Timing Topic 45 minutes Lecture 25 minutes Practice 70 minutes Total
  10. Schedule: Timing Topic 45 minutes Lecture 25 minutes Practice 70 minutes Total
  11. Schedule: Timing Topic 45 minutes Lecture 25 minutes Practice 70 minutes Total
  12. Schedule: Timing Topic 45 minutes Lecture 25 minutes Practice 70 minutes Total
  13. Schedule: Timing Topic 45 minutes Lecture 25 minutes Practice 70 minutes Total
  14. Schedule: Timing Topic 45 minutes Lecture 25 minutes Practice 70 minutes Total
  15. The FOREIGN KEY Constraint (continued) The foreign key is defined in the child table, and the table containing the referenced column is the parent table. The foreign key is defined using a combination of the following keywords: FOREIGN KEY is used to define the column in the child table at the table constraint level. REFERENCES identifies the table and column in the parent table. ON DELETE CASCADE indicates that when the row in the parent table is deleted, the dependent rows in the child table will also be deleted. Without the ON DELETE CASCADE option, the row in the parent table cannot be deleted if it is referenced in the child table.
  16. Schedule: Timing Topic 45 minutes Lecture 25 minutes Practice 70 minutes Total
  17. Schedule: Timing Topic 45 minutes Lecture 25 minutes Practice 70 minutes Total
  18. Schedule: Timing Topic 45 minutes Lecture 25 minutes Practice 70 minutes Total
  19. Schedule: Timing Topic 45 minutes Lecture 25 minutes Practice 70 minutes Total
  20. Schedule: Timing Topic 45 minutes Lecture 25 minutes Practice 70 minutes Total
  21. Schedule: Timing Topic 45 minutes Lecture 25 minutes Practice 70 minutes Total
  22. Schedule: Timing Topic 45 minutes Lecture 25 minutes Practice 70 minutes Total
  23. Schedule: Timing Topic 45 minutes Lecture 25 minutes Practice 70 minutes Total
  24. Summary The Oracle Server uses constraints to prevent invalid data entry into tables. The following constraint types are valid: NOT NULL UNIQUE PRIMARY KEY FOREIGN KEY CHECK You can query the USER_CONSTRAINTS table to view all constraint definitions and names.
  25. Practice Overview In this practice, you will add constraints and more columns to a table using the statements covered in this lesson. Class Management Note Advise the students to name their constraints.