SlideShare une entreprise Scribd logo
1  sur  25
1111
Including Constraints
11-2
Objectives
After completing this lesson, you shouldAfter completing this lesson, you should
be able to do the following:be able to do the following:
• Describe constraints
• Create and maintain constraints
11-3
What Are Constraints?
• Constraints enforce rules at the table level.
• Constraints prevent the deletion of a table
if there are dependencies.
• The following constraint types are valid in
Oracle:
– NOT NULL
– UNIQUE
– PRIMARY KEY
– FOREIGN KEY
– CHECK
11-4
Constraint Guidelines
• Name a constraint or the Oracle Server will
generate a name by using the SYS_Cn
format.
• Create a constraint:
– At the same time as the table is created
– After the table has been created
• Define a constraint at the column or table
level.
• View a constraint in the data dictionary.
11-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));
11-6
Defining Constraints
• Column constraint level
• Table constraint level
column [CONSTRAINT constraint_name] constraint_type,column [CONSTRAINT constraint_name] constraint_type,
column,...
[CONSTRAINT constraint_name] constraint_type
(column, ...),
column,...
[CONSTRAINT constraint_name] constraint_type
(column, ...),
11-7
The NOT NULL Constraint
Ensures that null values are not permittedEnsures that null values are not permitted
for the columnfor the column
EMPEMP
EMPNO ENAME JOB ... COMM DEPTNO
7839 KING PRESIDENT 10
7698 BLAKE MANAGER 30
7782 CLARK MANAGER 10
7566 JONES MANAGER 20
...
NOT NULL constraintNOT NULL constraint
(no row can contain(no row can contain
a null value fora null value for
this column)this column)
Absence of NOT NULLAbsence of NOT NULL
constraintconstraint
(any row can contain(any row can contain
null for this column)null for this column)
NOT NULL constraintNOT NULL constraint
11-8
The NOT NULL Constraint
Defined at the column levelDefined at the column level
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);
11-9
The UNIQUE Key Constraint
DEPTDEPT
DEPTNO DNAME LOC
------ ---------- --------
10 ACCOUNTING NEW YORK
20 RESEARCH DALLAS
30 SALES CHICAGO
40 OPERATIONS BOSTON
UNIQUE key constraintUNIQUE key constraint
50 SALES DETROIT
60 BOSTON
Insert intoInsert into Not allowedNot allowed
(DNAME(DNAME−SALES
already exists)already exists)
AllowedAllowed
11-10
The UNIQUE Key Constraint
Defined at either the table level or the columnDefined at either the table level or the column
levellevel
SQL> CREATE TABLE dept(
2 deptno NUMBER(2),
3 dname VARCHAR2(14),
4 loc VARCHAR2(13),
5 CONSTRAINT dept_dname_uk UNIQUE(dname));
11-11
The PRIMARY KEY Constraint
DEPTDEPT
DEPTNO DNAME LOC
------ ---------- --------
10 ACCOUNTING NEW YORK
20 RESEARCH DALLAS
30 SALES CHICAGO
40 OPERATIONS BOSTON
PRIMARY KEYPRIMARY KEY
Insert intoInsert into
20 MARKETING DALLAS
FINANCE NEW YORK
Not allowedNot allowed
(DEPTNO(DEPTNO−20 already20 already
exists)exists)
Not allowedNot allowed
(DEPTNO is null)(DEPTNO is null)
11-12
The PRIMARY KEY Constraint
Defined at either the table level or the columnDefined at either the table level or the column
levellevel
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));
11-13
The FOREIGN KEY Constraint
DEPTDEPT
DEPTNO DNAME LOC
------ ---------- --------
10 ACCOUNTING NEW YORK
20 RESEARCH DALLAS
...
PRIMARYPRIMARY
KEYKEY
EMPEMP
EMPNO ENAME JOB ... COMM DEPTNO
7839 KING PRESIDENT 10
7698 BLAKE MANAGER 30
...
FOREIGNFOREIGN
KEYKEY
7571 FORD MANAGER ... 200 9
7571 FORD MANAGER ... 200 20
Insert intoInsert into
Not allowedNot allowed
(DEPTNO(DEPTNO 99
does not existdoes not exist
in the DEPTin the DEPT
table)table)
AllowedAllowed
11-14
The FOREIGN KEY Constraint
Defined at either the table level or theDefined at either the table level or the
column levelcolumn level
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));
11-15
FOREIGN KEY Constraint
Keywords
• FOREIGN KEY
Defines the column in the child table at
the table constraint level
• REFERENCES
Identifies the table and column in the
parent table
• ON DELETE CASCADE
Allows deletion in the parent table and
deletion of the dependent rows in the
child table
11-16
The CHECK Constraint
• Defines a condition that each row must
satisfy
• Expressions that are not allowed:
– References to CURRVAL, NEXTVAL,
LEVEL, and ROWNUM pseudocolumns
– Calls to SYSDATE, UID, USER, and
USERENV functions
– Queries that refer to other values in other
rows
..., deptno NUMBER(2),
CONSTRAINT emp_deptno_ck
CHECK (DEPTNO BETWEEN 10 AND 99),...
11-17
Adding a Constraint
• Add or drop, but not modify, a
constraint
• Enable or disable constraints
• Add a NOT NULL constraint by using
the MODIFY clause
ALTER TABLE table
ADD [CONSTRAINT constraint] type (column);
ALTER TABLE table
ADD [CONSTRAINT constraint] type (column);
11-18
Adding a Constraint
Add a FOREIGN KEY constraint to theAdd a FOREIGN KEY constraint to the
EMP table indicating that a manager mustEMP table indicating that a manager must
already exist as a valid employee in thealready exist as a valid employee in the
EMP table.EMP table.
SQL> ALTER TABLE emp
2 ADD CONSTRAINT emp_mgr_fk
3 FOREIGN KEY(mgr) REFERENCES emp(empno);
Table altered.Table altered.
11-19
Dropping a Constraint
• Remove the manager constraint from
the EMP table.
SQL> ALTER TABLE emp
2 DROP CONSTRAINT emp_mgr_fk;
Table altered.Table altered.
SQL> ALTER TABLE emp
2 DROP CONSTRAINT emp_mgr_fk;
Table altered.Table altered.
• Remove the PRIMARY KEY constraint
on the DEPT table and drop the
associated FOREIGN KEY constraint on
the EMP.DEPTNO column.
SQL> ALTER TABLE dept
2 DROP PRIMARY KEY CASCADE;
Table altered.Table altered.
SQL> ALTER TABLE dept
2 DROP PRIMARY KEY CASCADE;
Table altered.Table altered.
11-20
Disabling Constraints
• Execute the DISABLE clause of the
ALTER TABLE statement to deactivate
an integrity constraint.
• Apply the CASCADE option to disable
dependent integrity constraints.
SQL> ALTER TABLE emp
2 DISABLE CONSTRAINT emp_empno_pk CASCADE;
Table altered.Table altered.
SQL> ALTER TABLE emp
2 DISABLE CONSTRAINT emp_empno_pk CASCADE;
Table altered.Table altered.
11-21
Enabling Constraints
• Activate an integrity constraint currently
disabled in the table definition by using
the ENABLE clause.
• A UNIQUE or PRIMARY KEY index is
automatically created if you enable a
UNIQUE key or PRIMARY KEY
constraint.
SQL> ALTER TABLE emp
2 ENABLE CONSTRAINT emp_empno_pk;
Table altered.Table altered.
SQL> ALTER TABLE emp
2 ENABLE CONSTRAINT emp_empno_pk;
Table altered.Table altered.
11-22
Viewing Constraints
Query the USER_CONSTRAINTS table toQuery the USER_CONSTRAINTS table to
view all constraint definitions and names.view all constraint definitions and names.
CONSTRAINT_NAME C SEARCH_CONDITION
------------------------ - -------------------------
SYS_C00674 C EMPNO IS NOT NULL
SYS_C00675 C DEPTNO IS NOT NULL
EMP_EMPNO_PK P
...
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';
11-23
Viewing the Columns
Associated with Constraints
CONSTRAINT_NAME COLUMN_NAME
------------------------- ----------------------
EMP_DEPTNO_FK DEPTNO
EMP_EMPNO_PK EMPNO
EMP_MGR_FK MGR
SYS_C00674 EMPNO
SYS_C00675 DEPTNO
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';
View the columns associated with theView the columns associated with the
constraint names in theconstraint names in the
USER_CONS_COLUMNS view.USER_CONS_COLUMNS view.
11-24
Summary
• Create the following types of constraints:
– NOT NULL
– UNIQUE
– PRIMARY KEY
– FOREIGN KEY
– CHECK
• Query the USER_CONSTRAINTS table to
view all constraint definitions and names.
11-25
Practice Overview
• Adding constraints to existing tables
• Adding more columns to a table
• Displaying information in data
dictionary views

Contenu connexe

Tendances (20)

IR SQLite Session #3
IR SQLite Session #3IR SQLite Session #3
IR SQLite Session #3
 
Quick reference for cql
Quick reference for cqlQuick reference for cql
Quick reference for cql
 
Oracle SQL AND PL/SQL
Oracle SQL AND PL/SQLOracle SQL AND PL/SQL
Oracle SQL AND PL/SQL
 
Best sql plsql material
Best sql plsql materialBest sql plsql material
Best sql plsql material
 
Oracle Sql & PLSQL Complete guide
Oracle Sql & PLSQL Complete guideOracle Sql & PLSQL Complete guide
Oracle Sql & PLSQL Complete guide
 
Database Systems - SQL - DDL Statements (Chapter 3/3)
Database Systems - SQL - DDL Statements (Chapter 3/3)Database Systems - SQL - DDL Statements (Chapter 3/3)
Database Systems - SQL - DDL Statements (Chapter 3/3)
 
Sql queries
Sql queriesSql queries
Sql queries
 
11 things about 11gr2
11 things about 11gr211 things about 11gr2
11 things about 11gr2
 
Les09 Manipulating Data
Les09 Manipulating DataLes09 Manipulating Data
Les09 Manipulating Data
 
DBMS lab manual
DBMS lab manualDBMS lab manual
DBMS lab manual
 
8. sql
8. sql8. sql
8. sql
 
Les12
Les12Les12
Les12
 
Les10
Les10Les10
Les10
 
Les01
Les01Les01
Les01
 
Oracle sql material
Oracle sql materialOracle sql material
Oracle sql material
 
Oracle: DDL
Oracle: DDLOracle: DDL
Oracle: DDL
 
Basic sql statements
Basic sql statementsBasic sql statements
Basic sql statements
 
Dbmsmanual
DbmsmanualDbmsmanual
Dbmsmanual
 
COIS 420 - Practice01
COIS 420 - Practice01COIS 420 - Practice01
COIS 420 - Practice01
 
Columnrename9i
Columnrename9iColumnrename9i
Columnrename9i
 

En vedette

SQL WORKSHOP::Lecture 10
SQL WORKSHOP::Lecture 10SQL WORKSHOP::Lecture 10
SQL WORKSHOP::Lecture 10Umair Amjad
 
SQL WORKSHOP::Lecture 4
SQL WORKSHOP::Lecture 4SQL WORKSHOP::Lecture 4
SQL WORKSHOP::Lecture 4Umair Amjad
 
SQL WORKSHOP::Lecture 6
SQL WORKSHOP::Lecture 6SQL WORKSHOP::Lecture 6
SQL WORKSHOP::Lecture 6Umair Amjad
 
SQL WORKSHOP::Lecture 12
SQL WORKSHOP::Lecture 12SQL WORKSHOP::Lecture 12
SQL WORKSHOP::Lecture 12Umair Amjad
 
SQL WORKSHOP::Lecture 9
SQL WORKSHOP::Lecture 9SQL WORKSHOP::Lecture 9
SQL WORKSHOP::Lecture 9Umair Amjad
 
SQL WORKSHOP::Lecture 2
SQL WORKSHOP::Lecture 2SQL WORKSHOP::Lecture 2
SQL WORKSHOP::Lecture 2Umair Amjad
 
SQL WORKSHOP::Lecture 7
SQL WORKSHOP::Lecture 7SQL WORKSHOP::Lecture 7
SQL WORKSHOP::Lecture 7Umair Amjad
 
SQL WORKSHOP::Lecture 13
SQL WORKSHOP::Lecture 13SQL WORKSHOP::Lecture 13
SQL WORKSHOP::Lecture 13Umair Amjad
 
SQL WORKSHOP::Lecture 5
SQL WORKSHOP::Lecture 5SQL WORKSHOP::Lecture 5
SQL WORKSHOP::Lecture 5Umair Amjad
 
Slides 2-basic sql
Slides 2-basic sqlSlides 2-basic sql
Slides 2-basic sqlAnuja Lad
 
SQL WORKSHOP::Lecture 3
SQL WORKSHOP::Lecture 3SQL WORKSHOP::Lecture 3
SQL WORKSHOP::Lecture 3Umair Amjad
 
SQL WORKSHOP::Lecture 1
SQL WORKSHOP::Lecture 1SQL WORKSHOP::Lecture 1
SQL WORKSHOP::Lecture 1Umair Amjad
 
SQL Fundamentals
SQL FundamentalsSQL Fundamentals
SQL FundamentalsBrian Foote
 
Writing Basic SQL SELECT Statements
Writing Basic SQL SELECT StatementsWriting Basic SQL SELECT Statements
Writing Basic SQL SELECT StatementsSalman Memon
 
Tutorial for using SQL in Microsoft Access
Tutorial for using SQL in Microsoft AccessTutorial for using SQL in Microsoft Access
Tutorial for using SQL in Microsoft Accessmcclellm
 

En vedette (20)

SQL WORKSHOP::Lecture 10
SQL WORKSHOP::Lecture 10SQL WORKSHOP::Lecture 10
SQL WORKSHOP::Lecture 10
 
SQL WORKSHOP::Lecture 4
SQL WORKSHOP::Lecture 4SQL WORKSHOP::Lecture 4
SQL WORKSHOP::Lecture 4
 
SQL WORKSHOP::Lecture 6
SQL WORKSHOP::Lecture 6SQL WORKSHOP::Lecture 6
SQL WORKSHOP::Lecture 6
 
SQL WORKSHOP::Lecture 12
SQL WORKSHOP::Lecture 12SQL WORKSHOP::Lecture 12
SQL WORKSHOP::Lecture 12
 
SQL WORKSHOP::Lecture 9
SQL WORKSHOP::Lecture 9SQL WORKSHOP::Lecture 9
SQL WORKSHOP::Lecture 9
 
SQL WORKSHOP::Lecture 2
SQL WORKSHOP::Lecture 2SQL WORKSHOP::Lecture 2
SQL WORKSHOP::Lecture 2
 
SQL WORKSHOP::Lecture 7
SQL WORKSHOP::Lecture 7SQL WORKSHOP::Lecture 7
SQL WORKSHOP::Lecture 7
 
SQL WORKSHOP::Lecture 13
SQL WORKSHOP::Lecture 13SQL WORKSHOP::Lecture 13
SQL WORKSHOP::Lecture 13
 
SQL WORKSHOP::Lecture 5
SQL WORKSHOP::Lecture 5SQL WORKSHOP::Lecture 5
SQL WORKSHOP::Lecture 5
 
Slides 2-basic sql
Slides 2-basic sqlSlides 2-basic sql
Slides 2-basic sql
 
Lecture 07 - Basic SQL
Lecture 07 - Basic SQLLecture 07 - Basic SQL
Lecture 07 - Basic SQL
 
Basic SQL Part 2
Basic SQL Part 2Basic SQL Part 2
Basic SQL Part 2
 
MySQL and its basic commands
MySQL and its basic commandsMySQL and its basic commands
MySQL and its basic commands
 
SQL WORKSHOP::Lecture 3
SQL WORKSHOP::Lecture 3SQL WORKSHOP::Lecture 3
SQL WORKSHOP::Lecture 3
 
SQL WORKSHOP::Lecture 1
SQL WORKSHOP::Lecture 1SQL WORKSHOP::Lecture 1
SQL WORKSHOP::Lecture 1
 
SQL Fundamentals
SQL FundamentalsSQL Fundamentals
SQL Fundamentals
 
Writing Basic SQL SELECT Statements
Writing Basic SQL SELECT StatementsWriting Basic SQL SELECT Statements
Writing Basic SQL SELECT Statements
 
Tutorial for using SQL in Microsoft Access
Tutorial for using SQL in Microsoft AccessTutorial for using SQL in Microsoft Access
Tutorial for using SQL in Microsoft Access
 
SQL Injection
SQL Injection SQL Injection
SQL Injection
 
SQL injection: Not only AND 1=1
SQL injection: Not only AND 1=1SQL injection: Not only AND 1=1
SQL injection: Not only AND 1=1
 

Similaire à SQL WORKSHOP::Lecture 11

Les11[1]Including Constraints
Les11[1]Including ConstraintsLes11[1]Including Constraints
Les11[1]Including Constraintssiavosh kaviani
 
Including Constraints -Oracle Data base
Including Constraints -Oracle Data base Including Constraints -Oracle Data base
Including Constraints -Oracle Data base Salman Memon
 
e computer notes - Including constraints
e computer notes - Including constraintse computer notes - Including constraints
e computer notes - Including constraintsecomputernotes
 
Clase 13 integridad modificada
Clase 13 integridad   modificadaClase 13 integridad   modificada
Clase 13 integridad modificadaTitiushko Jazz
 
Clase 13 integridad modificada
Clase 13 integridad   modificadaClase 13 integridad   modificada
Clase 13 integridad modificadaTitiushko Jazz
 
SQL-8 Table Creation.pdf
SQL-8 Table Creation.pdfSQL-8 Table Creation.pdf
SQL-8 Table Creation.pdfHannanKhalid4
 
Oracle SQL Fundamentals - Lecture 3
Oracle SQL Fundamentals - Lecture 3Oracle SQL Fundamentals - Lecture 3
Oracle SQL Fundamentals - Lecture 3MuhammadWaheed44
 
Constraints constraints of oracle data base management systems
Constraints  constraints of oracle data base management systemsConstraints  constraints of oracle data base management systems
Constraints constraints of oracle data base management systemsSHAKIR325211
 
Dms 22319 micro project
Dms 22319 micro projectDms 22319 micro project
Dms 22319 micro projectARVIND SARDAR
 
DDL(Data defination Language ) Using Oracle
DDL(Data defination Language ) Using OracleDDL(Data defination Language ) Using Oracle
DDL(Data defination Language ) Using OracleFarhan Aslam
 
database management system lessonchapter
database management system lessonchapterdatabase management system lessonchapter
database management system lessonchapterMohammedNouh7
 
Sql integrity constraints
Sql integrity constraintsSql integrity constraints
Sql integrity constraintsVivek Singh
 
constraints2100000000000000000000000000000
constraints2100000000000000000000000000000constraints2100000000000000000000000000000
constraints2100000000000000000000000000000227567
 
Les10[1]Creating and Managing Tables
Les10[1]Creating and Managing TablesLes10[1]Creating and Managing Tables
Les10[1]Creating and Managing Tablessiavosh kaviani
 
Managing Declarative Constraints
Managing Declarative ConstraintsManaging Declarative Constraints
Managing Declarative Constraintscarldudley
 

Similaire à SQL WORKSHOP::Lecture 11 (20)

Les11[1]Including Constraints
Les11[1]Including ConstraintsLes11[1]Including Constraints
Les11[1]Including Constraints
 
Including Constraints -Oracle Data base
Including Constraints -Oracle Data base Including Constraints -Oracle Data base
Including Constraints -Oracle Data base
 
Les10
Les10Les10
Les10
 
e computer notes - Including constraints
e computer notes - Including constraintse computer notes - Including constraints
e computer notes - Including constraints
 
Clase 13 integridad modificada
Clase 13 integridad   modificadaClase 13 integridad   modificada
Clase 13 integridad modificada
 
Clase 13 integridad modificada
Clase 13 integridad   modificadaClase 13 integridad   modificada
Clase 13 integridad modificada
 
SQL-8 Table Creation.pdf
SQL-8 Table Creation.pdfSQL-8 Table Creation.pdf
SQL-8 Table Creation.pdf
 
Oracle SQL Fundamentals - Lecture 3
Oracle SQL Fundamentals - Lecture 3Oracle SQL Fundamentals - Lecture 3
Oracle SQL Fundamentals - Lecture 3
 
Constraints constraints of oracle data base management systems
Constraints  constraints of oracle data base management systemsConstraints  constraints of oracle data base management systems
Constraints constraints of oracle data base management systems
 
Dms 22319 micro project
Dms 22319 micro projectDms 22319 micro project
Dms 22319 micro project
 
DDL(Data defination Language ) Using Oracle
DDL(Data defination Language ) Using OracleDDL(Data defination Language ) Using Oracle
DDL(Data defination Language ) Using Oracle
 
database management system lessonchapter
database management system lessonchapterdatabase management system lessonchapter
database management system lessonchapter
 
Sql commands
Sql commandsSql commands
Sql commands
 
Sql integrity constraints
Sql integrity constraintsSql integrity constraints
Sql integrity constraints
 
Data integrity
Data integrityData integrity
Data integrity
 
constraints2100000000000000000000000000000
constraints2100000000000000000000000000000constraints2100000000000000000000000000000
constraints2100000000000000000000000000000
 
SQL Sort Notes
SQL Sort NotesSQL Sort Notes
SQL Sort Notes
 
zekeLabs sql-slides
zekeLabs sql-slideszekeLabs sql-slides
zekeLabs sql-slides
 
Les10[1]Creating and Managing Tables
Les10[1]Creating and Managing TablesLes10[1]Creating and Managing Tables
Les10[1]Creating and Managing Tables
 
Managing Declarative Constraints
Managing Declarative ConstraintsManaging Declarative Constraints
Managing Declarative Constraints
 

Plus de Umair Amjad

Automated Process for Auditng in Agile - SCRUM
Automated Process for Auditng in Agile - SCRUMAutomated Process for Auditng in Agile - SCRUM
Automated Process for Auditng in Agile - SCRUMUmair Amjad
 
Data Deduplication: Venti and its improvements
Data Deduplication: Venti and its improvementsData Deduplication: Venti and its improvements
Data Deduplication: Venti and its improvementsUmair Amjad
 
Bead–Sort :: A Natural Sorting Algorithm
Bead–Sort :: A Natural Sorting AlgorithmBead–Sort :: A Natural Sorting Algorithm
Bead–Sort :: A Natural Sorting AlgorithmUmair Amjad
 
Apache logs monitoring
Apache logs monitoringApache logs monitoring
Apache logs monitoringUmair Amjad
 
Exact Cell Decomposition of Arrangements used for Path Planning in Robotics
Exact Cell Decomposition of Arrangements used for Path Planning in RoboticsExact Cell Decomposition of Arrangements used for Path Planning in Robotics
Exact Cell Decomposition of Arrangements used for Path Planning in RoboticsUmair Amjad
 
Ruby on Rails workshop for beginner
Ruby on Rails workshop for beginnerRuby on Rails workshop for beginner
Ruby on Rails workshop for beginnerUmair Amjad
 
DCT based Watermarking technique
DCT based Watermarking techniqueDCT based Watermarking technique
DCT based Watermarking techniqueUmair Amjad
 
Multi-core processor and Multi-channel memory architecture
Multi-core processor and Multi-channel memory architectureMulti-core processor and Multi-channel memory architecture
Multi-core processor and Multi-channel memory architectureUmair Amjad
 
Migration from Rails2 to Rails3
Migration from Rails2 to Rails3Migration from Rails2 to Rails3
Migration from Rails2 to Rails3Umair Amjad
 

Plus de Umair Amjad (9)

Automated Process for Auditng in Agile - SCRUM
Automated Process for Auditng in Agile - SCRUMAutomated Process for Auditng in Agile - SCRUM
Automated Process for Auditng in Agile - SCRUM
 
Data Deduplication: Venti and its improvements
Data Deduplication: Venti and its improvementsData Deduplication: Venti and its improvements
Data Deduplication: Venti and its improvements
 
Bead–Sort :: A Natural Sorting Algorithm
Bead–Sort :: A Natural Sorting AlgorithmBead–Sort :: A Natural Sorting Algorithm
Bead–Sort :: A Natural Sorting Algorithm
 
Apache logs monitoring
Apache logs monitoringApache logs monitoring
Apache logs monitoring
 
Exact Cell Decomposition of Arrangements used for Path Planning in Robotics
Exact Cell Decomposition of Arrangements used for Path Planning in RoboticsExact Cell Decomposition of Arrangements used for Path Planning in Robotics
Exact Cell Decomposition of Arrangements used for Path Planning in Robotics
 
Ruby on Rails workshop for beginner
Ruby on Rails workshop for beginnerRuby on Rails workshop for beginner
Ruby on Rails workshop for beginner
 
DCT based Watermarking technique
DCT based Watermarking techniqueDCT based Watermarking technique
DCT based Watermarking technique
 
Multi-core processor and Multi-channel memory architecture
Multi-core processor and Multi-channel memory architectureMulti-core processor and Multi-channel memory architecture
Multi-core processor and Multi-channel memory architecture
 
Migration from Rails2 to Rails3
Migration from Rails2 to Rails3Migration from Rails2 to Rails3
Migration from Rails2 to Rails3
 

Dernier

Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...apidays
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobeapidays
 
Tech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfTech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfhans926745
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdflior mazor
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CVKhem
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessPixlogix Infotech
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProduct Anonymous
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century educationjfdjdjcjdnsjd
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024The Digital Insurer
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Enterprise Knowledge
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 

Dernier (20)

Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
Tech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfTech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdf
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your Business
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 

SQL WORKSHOP::Lecture 11

  • 2. 11-2 Objectives After completing this lesson, you shouldAfter completing this lesson, you should be able to do the following:be able to do the following: • Describe constraints • Create and maintain constraints
  • 3. 11-3 What Are Constraints? • Constraints enforce rules at the table level. • Constraints prevent the deletion of a table if there are dependencies. • The following constraint types are valid in Oracle: – NOT NULL – UNIQUE – PRIMARY KEY – FOREIGN KEY – CHECK
  • 4. 11-4 Constraint Guidelines • Name a constraint or the Oracle Server will generate a name by using the SYS_Cn format. • Create a constraint: – At the same time as the table is created – After the table has been created • Define a constraint at the column or table level. • View a constraint in the data dictionary.
  • 5. 11-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. 11-6 Defining Constraints • Column constraint level • Table constraint level column [CONSTRAINT constraint_name] constraint_type,column [CONSTRAINT constraint_name] constraint_type, column,... [CONSTRAINT constraint_name] constraint_type (column, ...), column,... [CONSTRAINT constraint_name] constraint_type (column, ...),
  • 7. 11-7 The NOT NULL Constraint Ensures that null values are not permittedEnsures that null values are not permitted for the columnfor the column EMPEMP EMPNO ENAME JOB ... COMM DEPTNO 7839 KING PRESIDENT 10 7698 BLAKE MANAGER 30 7782 CLARK MANAGER 10 7566 JONES MANAGER 20 ... NOT NULL constraintNOT NULL constraint (no row can contain(no row can contain a null value fora null value for this column)this column) Absence of NOT NULLAbsence of NOT NULL constraintconstraint (any row can contain(any row can contain null for this column)null for this column) NOT NULL constraintNOT NULL constraint
  • 8. 11-8 The NOT NULL Constraint Defined at the column levelDefined at the column level 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);
  • 9. 11-9 The UNIQUE Key Constraint DEPTDEPT DEPTNO DNAME LOC ------ ---------- -------- 10 ACCOUNTING NEW YORK 20 RESEARCH DALLAS 30 SALES CHICAGO 40 OPERATIONS BOSTON UNIQUE key constraintUNIQUE key constraint 50 SALES DETROIT 60 BOSTON Insert intoInsert into Not allowedNot allowed (DNAME(DNAME−SALES already exists)already exists) AllowedAllowed
  • 10. 11-10 The UNIQUE Key Constraint Defined at either the table level or the columnDefined at either the table level or the column levellevel SQL> CREATE TABLE dept( 2 deptno NUMBER(2), 3 dname VARCHAR2(14), 4 loc VARCHAR2(13), 5 CONSTRAINT dept_dname_uk UNIQUE(dname));
  • 11. 11-11 The PRIMARY KEY Constraint DEPTDEPT DEPTNO DNAME LOC ------ ---------- -------- 10 ACCOUNTING NEW YORK 20 RESEARCH DALLAS 30 SALES CHICAGO 40 OPERATIONS BOSTON PRIMARY KEYPRIMARY KEY Insert intoInsert into 20 MARKETING DALLAS FINANCE NEW YORK Not allowedNot allowed (DEPTNO(DEPTNO−20 already20 already exists)exists) Not allowedNot allowed (DEPTNO is null)(DEPTNO is null)
  • 12. 11-12 The PRIMARY KEY Constraint Defined at either the table level or the columnDefined at either the table level or the column levellevel 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));
  • 13. 11-13 The FOREIGN KEY Constraint DEPTDEPT DEPTNO DNAME LOC ------ ---------- -------- 10 ACCOUNTING NEW YORK 20 RESEARCH DALLAS ... PRIMARYPRIMARY KEYKEY EMPEMP EMPNO ENAME JOB ... COMM DEPTNO 7839 KING PRESIDENT 10 7698 BLAKE MANAGER 30 ... FOREIGNFOREIGN KEYKEY 7571 FORD MANAGER ... 200 9 7571 FORD MANAGER ... 200 20 Insert intoInsert into Not allowedNot allowed (DEPTNO(DEPTNO 99 does not existdoes not exist in the DEPTin the DEPT table)table) AllowedAllowed
  • 14. 11-14 The FOREIGN KEY Constraint Defined at either the table level or theDefined at either the table level or the column levelcolumn level 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));
  • 15. 11-15 FOREIGN KEY Constraint Keywords • FOREIGN KEY Defines the column in the child table at the table constraint level • REFERENCES Identifies the table and column in the parent table • ON DELETE CASCADE Allows deletion in the parent table and deletion of the dependent rows in the child table
  • 16. 11-16 The CHECK Constraint • Defines a condition that each row must satisfy • Expressions that are not allowed: – References to CURRVAL, NEXTVAL, LEVEL, and ROWNUM pseudocolumns – Calls to SYSDATE, UID, USER, and USERENV functions – Queries that refer to other values in other rows ..., deptno NUMBER(2), CONSTRAINT emp_deptno_ck CHECK (DEPTNO BETWEEN 10 AND 99),...
  • 17. 11-17 Adding a Constraint • Add or drop, but not modify, a constraint • Enable or disable constraints • Add a NOT NULL constraint by using the MODIFY clause ALTER TABLE table ADD [CONSTRAINT constraint] type (column); ALTER TABLE table ADD [CONSTRAINT constraint] type (column);
  • 18. 11-18 Adding a Constraint Add a FOREIGN KEY constraint to theAdd a FOREIGN KEY constraint to the EMP table indicating that a manager mustEMP table indicating that a manager must already exist as a valid employee in thealready exist as a valid employee in the EMP table.EMP table. SQL> ALTER TABLE emp 2 ADD CONSTRAINT emp_mgr_fk 3 FOREIGN KEY(mgr) REFERENCES emp(empno); Table altered.Table altered.
  • 19. 11-19 Dropping a Constraint • Remove the manager constraint from the EMP table. SQL> ALTER TABLE emp 2 DROP CONSTRAINT emp_mgr_fk; Table altered.Table altered. SQL> ALTER TABLE emp 2 DROP CONSTRAINT emp_mgr_fk; Table altered.Table altered. • Remove the PRIMARY KEY constraint on the DEPT table and drop the associated FOREIGN KEY constraint on the EMP.DEPTNO column. SQL> ALTER TABLE dept 2 DROP PRIMARY KEY CASCADE; Table altered.Table altered. SQL> ALTER TABLE dept 2 DROP PRIMARY KEY CASCADE; Table altered.Table altered.
  • 20. 11-20 Disabling Constraints • Execute the DISABLE clause of the ALTER TABLE statement to deactivate an integrity constraint. • Apply the CASCADE option to disable dependent integrity constraints. SQL> ALTER TABLE emp 2 DISABLE CONSTRAINT emp_empno_pk CASCADE; Table altered.Table altered. SQL> ALTER TABLE emp 2 DISABLE CONSTRAINT emp_empno_pk CASCADE; Table altered.Table altered.
  • 21. 11-21 Enabling Constraints • Activate an integrity constraint currently disabled in the table definition by using the ENABLE clause. • A UNIQUE or PRIMARY KEY index is automatically created if you enable a UNIQUE key or PRIMARY KEY constraint. SQL> ALTER TABLE emp 2 ENABLE CONSTRAINT emp_empno_pk; Table altered.Table altered. SQL> ALTER TABLE emp 2 ENABLE CONSTRAINT emp_empno_pk; Table altered.Table altered.
  • 22. 11-22 Viewing Constraints Query the USER_CONSTRAINTS table toQuery the USER_CONSTRAINTS table to view all constraint definitions and names.view all constraint definitions and names. CONSTRAINT_NAME C SEARCH_CONDITION ------------------------ - ------------------------- SYS_C00674 C EMPNO IS NOT NULL SYS_C00675 C DEPTNO IS NOT NULL EMP_EMPNO_PK P ... 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';
  • 23. 11-23 Viewing the Columns Associated with Constraints CONSTRAINT_NAME COLUMN_NAME ------------------------- ---------------------- EMP_DEPTNO_FK DEPTNO EMP_EMPNO_PK EMPNO EMP_MGR_FK MGR SYS_C00674 EMPNO SYS_C00675 DEPTNO 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'; View the columns associated with theView the columns associated with the constraint names in theconstraint names in the USER_CONS_COLUMNS view.USER_CONS_COLUMNS view.
  • 24. 11-24 Summary • Create the following types of constraints: – NOT NULL – UNIQUE – PRIMARY KEY – FOREIGN KEY – CHECK • Query the USER_CONSTRAINTS table to view all constraint definitions and names.
  • 25. 11-25 Practice Overview • Adding constraints to existing tables • Adding more columns to a table • Displaying information in data dictionary views

Notes de l'éditeur

  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.