SlideShare a Scribd company logo
SQL
Constraint
Made By:
      Israa Al- Jarrah
                         CIS Dept-- IT
                         Faculty
SQL Constraint Meaning




                    Write Constraint




 Constraint Type
 Constraints can be specified when a table is created
   (with the CREATE TABLE statement) or after the
  table is created (with the ALTER TABLE statement)


     Constraints are used to limit the type of data
                that can go into a table.
Constraint   [Constraint name]   Constraint Type
You can define constraints syntactically in two ways:

    1.   As part of the definition of an individual column or
             attribute. This is called inline specification.

    2. As part of the table definition. This is called
             out-of-line specification.
Types of constraints:
     1.Integrity constraints
      2.Value constraints
Table constraint
     Restricts data value with
   respect to all other values in
                table
1. Not Null
2. Unique Key
3. Primary Key
4. Foreign Key
5. Check Key
6. Default Key
Not Null

 constraint enforces a column to NOT accept
 NULL values. constraint enforces a column to
           NOT accept NULL values.
 This means that you cannot insert a new
    record, or update a record without
        adding a value to this field.
 Expression of Not Null we use short cut NN
1. Not Null Example :-


Create Table Language
(
      Language_Name varchar2(30),
      Language_Id number(15)
Constraint
Constraint_Language_language_name
_NN
      Not Null
);
All other constraints
can be declared either
  inline or out of line.
2. Unique Key


  The UNIQUE constraint uniquely identifies
      each record in a database table.
2. Unique Key Example

Create Table Person
(
      Person_Id number(15)
      Constraint
Person_person_id_UN Unique
      Person_name varchar2(40),
     Person_BD Date
);
2. Unique Key Example

Create Table Person
(
       Person_Id number(15),
        Person_name varchar2(40),
         Person_BD Date
                 Constraint
   Person_person_id_UN Unique
             (Person_Id)
3. Primary Key


 Primary keys must contain unique values

   A primary key column cannot contain NULL
                     values.
     Each table should have a primary key, and each
           table can have only ONE primary key
3. Primary Key Example

CREATE TABLE locations_demo

    location_id NUMBER(4) Constraint
Constraint_loc_id_pk PRIMARY KEY ,
   street_address VARCHAR2(40) ,
    postal_code VARCHAR2(12)
);
3. Primary Key Example

CREATE TABLE locations_demo

    location_id NUMBER(4) ,
     street_address VARCHAR2(40) ,
     postal_code VARCHAR2(12) ,
    Constraint Constraint_loc_id_pk
PRIMARY KEY (Location_id)
);
Unique Key
Unique Key


               Primary Key
Unique Key
 Unique Key

 accept only one null value

    unique key use many time in
               table.
Primary Key
 Unique Key

Primary key does not accept null
             value
   primary key use only one time
               in table.
4. Foreign Key
      Unique Key
 A FOREIGN KEY in one table points to a PRIMARY KEY in
                     another table

       The FOREIGN KEY constraint is used to prevent actions
              that would destroy links between tables.
4. Foreign Key Example

     Unique Key
The "Persons" table:

P-Id     LastName     FirstName    Address      CIty

 1        Hansen         Ola      Timoteivn    Sandnes
                                     10
 2       Svendson       Tove      Borgvn23     Sandnes

 3        Pettersen     Kari      Storagt 20   Sandnes
4. Foreign Key Example

 Unique Key
The “Order" table:


      O_Id       OrderNo     P_id

       1             77895    3
       2             44678    3
       3             22456    2
       4             24562    1
4. Foreign Key Example

             "P_Id" column in the "Orders" table
              points to the "P_Id" column in the
                        "Persons" table.

        The "P_Id" column in the "Persons" table is
        the PRIMARY KEY in the "Persons" table.

        The "P_Id" column in the "Orders" table is
         a FOREIGN KEY in the "Orders" table.
4. Foreign Key Example
     First step must create “Person” Table
Create Table Person
(
   P_Id number Constraint
constraint_person_person_Id_PK primary key,
    LastName varcahr2(45),
    FirstName varchar2(45),
   Address varchar2(45),
   City varchar2(45)
);
4. Foreign Key Example


Create Table Order
(
Order_id number(15) CONSTRAINT
con_Order_id_pk Primary Key,
OredrNO number(30) ,
P_id number(15) CONSTRINT
con_person_order_id_FK refernace Person (p_id)
);
5. Check Key

 The CHECK constraint is used to limit the value range
            that can be placed in a column.

  If you define a CHECK constraint on a single column it
          allows only certain values for this column
5. Check Key Example

CREATE TABLE divisions
 (
div_no NUMBER CONSTRAINT check_divno
CHECK
(div_no BETWEEN 10 AND 99),

div_name VARCHAR2(9) CONSTRAINT
check_divname_cc CHECK
(div_name = UPPER(div_name))

);
5. Check Key
   6. Default Key

 The DEFAULT constraint is used to insert a default
                value into a column

  The default value will be added to all new records
 if no other value is specified
5. Check Key Example
   6. Default Key
CREATE TABLE Persons
(
    P_Id Number(15),
    LastName varchar(255),
    FirstName varchar(255),
    Address varchar(255),
    City varchar(255) DEFAULT 'Sandnes'
);
CONSTRAINT constraint_name
PRIMARY KEY (columnname1,
columnname2 
)
Create table person
(
           Person_ID Number(15),
         Person_phone number(15),
         Constraint con_person_un
     Unique(Person_ID,Person_Phone)
);
Reference
http://www.w3schools.com/sql/sql_constraints.asp

http://www.docs.oracle.com/cd/B19306_01/server.102/b142
00/clauses002.htm#i1015609
Thank you for listen
     Israa jarrah

More Related Content

What's hot

Java Linked List Tutorial | Edureka
Java Linked List Tutorial |  EdurekaJava Linked List Tutorial |  Edureka
Java Linked List Tutorial | Edureka
Edureka!
 
Normal forms
Normal formsNormal forms
Normal forms
Samuel Igbanogu
 
Group By, Order By, and Aliases in SQL
Group By, Order By, and Aliases in SQLGroup By, Order By, and Aliases in SQL
Group By, Order By, and Aliases in SQL
MSB Academy
 
Sql commands
Sql commandsSql commands
Sql commands
Pooja Dixit
 
Packages in PL/SQL
Packages in PL/SQLPackages in PL/SQL
Packages in PL/SQL
Pooja Dixit
 
Constraints In Sql
Constraints In SqlConstraints In Sql
Constraints In Sql
Anurag
 
SQL JOINS
SQL JOINSSQL JOINS
SQL JOINS
Swapnali Pawar
 
Linked list
Linked listLinked list
Linked list
KalaivaniKS1
 
Integrity Constraints
Integrity ConstraintsIntegrity Constraints
Integrity Constraints
madhav bansal
 
Oracle Database Trigger
Oracle Database TriggerOracle Database Trigger
Oracle Database Trigger
Eryk Budi Pratama
 
Data structure lecture 1
Data structure lecture 1Data structure lecture 1
Data structure lecture 1
Kumar
 
Unit 4 plsql
Unit 4  plsqlUnit 4  plsql
Unit 4 plsql
DrkhanchanaR
 
Trigger
TriggerTrigger
Trigger
VForce Infotech
 
View & index in SQL
View & index in SQLView & index in SQL
View & index in SQL
Swapnali Pawar
 
Key and its different types
Key and its different typesKey and its different types
Key and its different types
Umair Shakir
 
Referential integrity
Referential integrityReferential integrity
Referential integrity
Jubin Raju
 
Chapter 12 ds
Chapter 12 dsChapter 12 ds
Chapter 12 ds
Hanif Durad
 
Introduction to oracle functions
Introduction to oracle functionsIntroduction to oracle functions
Introduction to oracle functions
Nitesh Singh
 
trigger dbms
trigger dbmstrigger dbms
trigger dbms
kuldeep100
 
Using single row functions to customize output
Using single row functions to customize outputUsing single row functions to customize output
Using single row functions to customize output
Syed Zaid Irshad
 

What's hot (20)

Java Linked List Tutorial | Edureka
Java Linked List Tutorial |  EdurekaJava Linked List Tutorial |  Edureka
Java Linked List Tutorial | Edureka
 
Normal forms
Normal formsNormal forms
Normal forms
 
Group By, Order By, and Aliases in SQL
Group By, Order By, and Aliases in SQLGroup By, Order By, and Aliases in SQL
Group By, Order By, and Aliases in SQL
 
Sql commands
Sql commandsSql commands
Sql commands
 
Packages in PL/SQL
Packages in PL/SQLPackages in PL/SQL
Packages in PL/SQL
 
Constraints In Sql
Constraints In SqlConstraints In Sql
Constraints In Sql
 
SQL JOINS
SQL JOINSSQL JOINS
SQL JOINS
 
Linked list
Linked listLinked list
Linked list
 
Integrity Constraints
Integrity ConstraintsIntegrity Constraints
Integrity Constraints
 
Oracle Database Trigger
Oracle Database TriggerOracle Database Trigger
Oracle Database Trigger
 
Data structure lecture 1
Data structure lecture 1Data structure lecture 1
Data structure lecture 1
 
Unit 4 plsql
Unit 4  plsqlUnit 4  plsql
Unit 4 plsql
 
Trigger
TriggerTrigger
Trigger
 
View & index in SQL
View & index in SQLView & index in SQL
View & index in SQL
 
Key and its different types
Key and its different typesKey and its different types
Key and its different types
 
Referential integrity
Referential integrityReferential integrity
Referential integrity
 
Chapter 12 ds
Chapter 12 dsChapter 12 ds
Chapter 12 ds
 
Introduction to oracle functions
Introduction to oracle functionsIntroduction to oracle functions
Introduction to oracle functions
 
trigger dbms
trigger dbmstrigger dbms
trigger dbms
 
Using single row functions to customize output
Using single row functions to customize outputUsing single row functions to customize output
Using single row functions to customize output
 

Viewers also liked

L2 acquisition
L2 acquisitionL2 acquisition
L2 acquisition
CameliaN
 
Including Constraints -Oracle Data base
Including Constraints -Oracle Data base Including Constraints -Oracle Data base
Including Constraints -Oracle Data base
Salman Memon
 
Relational databe
Relational databeRelational databe
Relational databe
Samwel Charles
 
Sql xp 05
Sql xp 05Sql xp 05
Sql xp 05
Niit Care
 
SQL: Unique IDs, Primary Keys and Archiving Inactive Rows Without Violating C...
SQL: Unique IDs, Primary Keys and Archiving Inactive Rows Without Violating C...SQL: Unique IDs, Primary Keys and Archiving Inactive Rows Without Violating C...
SQL: Unique IDs, Primary Keys and Archiving Inactive Rows Without Violating C...
Marco M. Kiesewetter, MBA
 
8. sql
8. sql8. sql
8. sql
khoahuy82
 
SQL Server - Constraints
SQL Server - ConstraintsSQL Server - Constraints
SQL Server - Constraints
Aaron Buma
 
Parameter setting
Parameter settingParameter setting
Parameter setting
Rick McKinnon
 
SQL Tutorial - Table Constraints
SQL Tutorial - Table ConstraintsSQL Tutorial - Table Constraints
SQL Tutorial - Table Constraints
1keydata
 
Universal grammar
Universal grammarUniversal grammar
Universal grammar
Muhammad Al Fateh
 
Second Language Acquisition
Second Language AcquisitionSecond Language Acquisition
Second Language Acquisition
victorgaogao
 
Elt different methods & approaches
Elt different methods & approachesElt different methods & approaches
Elt different methods & approaches
Muhammad Fauzan
 
Sql database object
Sql database objectSql database object
Sql database object
Young Alista
 
Universal grammar
Universal grammarUniversal grammar
Universal grammar
Guillermo Cid
 
Theory of constraints
Theory of constraintsTheory of constraints
Theory of constraints
MOHD ARISH
 
Data integrity
Data integrityData integrity
Data integrity
Rahul Gupta
 
Error localization
Error localizationError localization
Error localization
Mohammed Bekkouche
 

Viewers also liked (17)

L2 acquisition
L2 acquisitionL2 acquisition
L2 acquisition
 
Including Constraints -Oracle Data base
Including Constraints -Oracle Data base Including Constraints -Oracle Data base
Including Constraints -Oracle Data base
 
Relational databe
Relational databeRelational databe
Relational databe
 
Sql xp 05
Sql xp 05Sql xp 05
Sql xp 05
 
SQL: Unique IDs, Primary Keys and Archiving Inactive Rows Without Violating C...
SQL: Unique IDs, Primary Keys and Archiving Inactive Rows Without Violating C...SQL: Unique IDs, Primary Keys and Archiving Inactive Rows Without Violating C...
SQL: Unique IDs, Primary Keys and Archiving Inactive Rows Without Violating C...
 
8. sql
8. sql8. sql
8. sql
 
SQL Server - Constraints
SQL Server - ConstraintsSQL Server - Constraints
SQL Server - Constraints
 
Parameter setting
Parameter settingParameter setting
Parameter setting
 
SQL Tutorial - Table Constraints
SQL Tutorial - Table ConstraintsSQL Tutorial - Table Constraints
SQL Tutorial - Table Constraints
 
Universal grammar
Universal grammarUniversal grammar
Universal grammar
 
Second Language Acquisition
Second Language AcquisitionSecond Language Acquisition
Second Language Acquisition
 
Elt different methods & approaches
Elt different methods & approachesElt different methods & approaches
Elt different methods & approaches
 
Sql database object
Sql database objectSql database object
Sql database object
 
Universal grammar
Universal grammarUniversal grammar
Universal grammar
 
Theory of constraints
Theory of constraintsTheory of constraints
Theory of constraints
 
Data integrity
Data integrityData integrity
Data integrity
 
Error localization
Error localizationError localization
Error localization
 

Similar to oracle Sql constraint

Entigrity constraint
Entigrity constraintEntigrity constraint
Entigrity constraint
suman kumar
 
Lecture 4 sql {basics keys and constraints}
Lecture 4 sql {basics  keys and constraints}Lecture 4 sql {basics  keys and constraints}
Lecture 4 sql {basics keys and constraints}
Shubham Shukla
 
SQL & PLSQL
SQL & PLSQLSQL & PLSQL
SQL & PLSQL
Prakash Poudel
 
MQSL JOINING OF TABLES.pptx
MQSL JOINING OF TABLES.pptxMQSL JOINING OF TABLES.pptx
MQSL JOINING OF TABLES.pptx
lemonchoos
 
Sql integrity constraints
Sql integrity constraintsSql integrity constraints
Sql integrity constraints
Vivek Singh
 
Create table
Create tableCreate table
Create table
Nitesh Singh
 
Sql server ___________session_15(data integrity)
Sql server  ___________session_15(data integrity)Sql server  ___________session_15(data integrity)
Sql server ___________session_15(data integrity)
Ehtisham Ali
 
Sql ch 12 - creating database
Sql ch 12 - creating databaseSql ch 12 - creating database
Sql ch 12 - creating database
Mukesh Tekwani
 
CONSTRAINTS PPT.pptx
CONSTRAINTS PPT.pptxCONSTRAINTS PPT.pptx
CONSTRAINTS PPT.pptx
ThangaduraiA4
 
MY SQL
MY SQLMY SQL
MY SQL
sundar
 
Integrity Constraints in Database Management System.pptx
Integrity Constraints in Database Management System.pptxIntegrity Constraints in Database Management System.pptx
Integrity Constraints in Database Management System.pptx
PallaviPatil905338
 
RDBMS Lab03 applying constraints (UIU)
RDBMS Lab03 applying constraints (UIU)RDBMS Lab03 applying constraints (UIU)
RDBMS Lab03 applying constraints (UIU)
Muhammad T Q Nafis
 
Sql
SqlSql
Mysql 120831075600-phpapp01
Mysql 120831075600-phpapp01Mysql 120831075600-phpapp01
Mysql 120831075600-phpapp01
sagaroceanic11
 
03Constraints - last.pdf
03Constraints - last.pdf03Constraints - last.pdf
03Constraints - last.pdf
ssuserfd620b
 
Integrity and security
Integrity and securityIntegrity and security
Integrity and security
Surendra Karki Chettri
 
Constraints
ConstraintsConstraints
Constraints
punu_82
 
introdution concept on _ _ sql_basic.ppt
introdution concept on _ _ sql_basic.pptintrodution concept on _ _ sql_basic.ppt
introdution concept on _ _ sql_basic.ppt
riscomputersir
 
Sql basics
Sql basicsSql basics
Sql basics
Aman Lalpuria
 
Introduction to sql
Introduction to sqlIntroduction to sql
Introduction to sql
VARSHAKUMARI49
 

Similar to oracle Sql constraint (20)

Entigrity constraint
Entigrity constraintEntigrity constraint
Entigrity constraint
 
Lecture 4 sql {basics keys and constraints}
Lecture 4 sql {basics  keys and constraints}Lecture 4 sql {basics  keys and constraints}
Lecture 4 sql {basics keys and constraints}
 
SQL & PLSQL
SQL & PLSQLSQL & PLSQL
SQL & PLSQL
 
MQSL JOINING OF TABLES.pptx
MQSL JOINING OF TABLES.pptxMQSL JOINING OF TABLES.pptx
MQSL JOINING OF TABLES.pptx
 
Sql integrity constraints
Sql integrity constraintsSql integrity constraints
Sql integrity constraints
 
Create table
Create tableCreate table
Create table
 
Sql server ___________session_15(data integrity)
Sql server  ___________session_15(data integrity)Sql server  ___________session_15(data integrity)
Sql server ___________session_15(data integrity)
 
Sql ch 12 - creating database
Sql ch 12 - creating databaseSql ch 12 - creating database
Sql ch 12 - creating database
 
CONSTRAINTS PPT.pptx
CONSTRAINTS PPT.pptxCONSTRAINTS PPT.pptx
CONSTRAINTS PPT.pptx
 
MY SQL
MY SQLMY SQL
MY SQL
 
Integrity Constraints in Database Management System.pptx
Integrity Constraints in Database Management System.pptxIntegrity Constraints in Database Management System.pptx
Integrity Constraints in Database Management System.pptx
 
RDBMS Lab03 applying constraints (UIU)
RDBMS Lab03 applying constraints (UIU)RDBMS Lab03 applying constraints (UIU)
RDBMS Lab03 applying constraints (UIU)
 
Sql
SqlSql
Sql
 
Mysql 120831075600-phpapp01
Mysql 120831075600-phpapp01Mysql 120831075600-phpapp01
Mysql 120831075600-phpapp01
 
03Constraints - last.pdf
03Constraints - last.pdf03Constraints - last.pdf
03Constraints - last.pdf
 
Integrity and security
Integrity and securityIntegrity and security
Integrity and security
 
Constraints
ConstraintsConstraints
Constraints
 
introdution concept on _ _ sql_basic.ppt
introdution concept on _ _ sql_basic.pptintrodution concept on _ _ sql_basic.ppt
introdution concept on _ _ sql_basic.ppt
 
Sql basics
Sql basicsSql basics
Sql basics
 
Introduction to sql
Introduction to sqlIntroduction to sql
Introduction to sql
 

More from home

Mobile security
Mobile securityMobile security
Mobile security
home
 
Html5
Html5Html5
Html5
home
 
svg Scalable Vector Graphics (SVG)
 svg Scalable Vector Graphics  (SVG) svg Scalable Vector Graphics  (SVG)
svg Scalable Vector Graphics (SVG)
home
 
SVG
SVG SVG
SVG
home
 
Working principle of the microwave1
Working principle of the microwave1Working principle of the microwave1
Working principle of the microwave1
home
 
How to work cable network
How to work cable networkHow to work cable network
How to work cable network
home
 

More from home (6)

Mobile security
Mobile securityMobile security
Mobile security
 
Html5
Html5Html5
Html5
 
svg Scalable Vector Graphics (SVG)
 svg Scalable Vector Graphics  (SVG) svg Scalable Vector Graphics  (SVG)
svg Scalable Vector Graphics (SVG)
 
SVG
SVG SVG
SVG
 
Working principle of the microwave1
Working principle of the microwave1Working principle of the microwave1
Working principle of the microwave1
 
How to work cable network
How to work cable networkHow to work cable network
How to work cable network
 

Recently uploaded

Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdfUnlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Malak Abu Hammad
 
Operating System Used by Users in day-to-day life.pptx
Operating System Used by Users in day-to-day life.pptxOperating System Used by Users in day-to-day life.pptx
Operating System Used by Users in day-to-day life.pptx
Pravash Chandra Das
 
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAUHCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
panagenda
 
Energy Efficient Video Encoding for Cloud and Edge Computing Instances
Energy Efficient Video Encoding for Cloud and Edge Computing InstancesEnergy Efficient Video Encoding for Cloud and Edge Computing Instances
Energy Efficient Video Encoding for Cloud and Edge Computing Instances
Alpen-Adria-UniversitÀt
 
Skybuffer SAM4U tool for SAP license adoption
Skybuffer SAM4U tool for SAP license adoptionSkybuffer SAM4U tool for SAP license adoption
Skybuffer SAM4U tool for SAP license adoption
Tatiana Kojar
 
GraphRAG for Life Science to increase LLM accuracy
GraphRAG for Life Science to increase LLM accuracyGraphRAG for Life Science to increase LLM accuracy
GraphRAG for Life Science to increase LLM accuracy
Tomaz Bratanic
 
Ocean lotus Threat actors project by John Sitima 2024 (1).pptx
Ocean lotus Threat actors project by John Sitima 2024 (1).pptxOcean lotus Threat actors project by John Sitima 2024 (1).pptx
Ocean lotus Threat actors project by John Sitima 2024 (1).pptx
SitimaJohn
 
Building Production Ready Search Pipelines with Spark and Milvus
Building Production Ready Search Pipelines with Spark and MilvusBuilding Production Ready Search Pipelines with Spark and Milvus
Building Production Ready Search Pipelines with Spark and Milvus
Zilliz
 
Skybuffer AI: Advanced Conversational and Generative AI Solution on SAP Busin...
Skybuffer AI: Advanced Conversational and Generative AI Solution on SAP Busin...Skybuffer AI: Advanced Conversational and Generative AI Solution on SAP Busin...
Skybuffer AI: Advanced Conversational and Generative AI Solution on SAP Busin...
Tatiana Kojar
 
System Design Case Study: Building a Scalable E-Commerce Platform - Hiike
System Design Case Study: Building a Scalable E-Commerce Platform - HiikeSystem Design Case Study: Building a Scalable E-Commerce Platform - Hiike
System Design Case Study: Building a Scalable E-Commerce Platform - Hiike
Hiike
 
Monitoring and Managing Anomaly Detection on OpenShift.pdf
Monitoring and Managing Anomaly Detection on OpenShift.pdfMonitoring and Managing Anomaly Detection on OpenShift.pdf
Monitoring and Managing Anomaly Detection on OpenShift.pdf
Tosin Akinosho
 
Fueling AI with Great Data with Airbyte Webinar
Fueling AI with Great Data with Airbyte WebinarFueling AI with Great Data with Airbyte Webinar
Fueling AI with Great Data with Airbyte Webinar
Zilliz
 
Introduction of Cybersecurity with OSS at Code Europe 2024
Introduction of Cybersecurity with OSS  at Code Europe 2024Introduction of Cybersecurity with OSS  at Code Europe 2024
Introduction of Cybersecurity with OSS at Code Europe 2024
Hiroshi SHIBATA
 
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with SlackLet's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
shyamraj55
 
Driving Business Innovation: Latest Generative AI Advancements & Success Story
Driving Business Innovation: Latest Generative AI Advancements & Success StoryDriving Business Innovation: Latest Generative AI Advancements & Success Story
Driving Business Innovation: Latest Generative AI Advancements & Success Story
Safe Software
 
Programming Foundation Models with DSPy - Meetup Slides
Programming Foundation Models with DSPy - Meetup SlidesProgramming Foundation Models with DSPy - Meetup Slides
Programming Foundation Models with DSPy - Meetup Slides
Zilliz
 
Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...
Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...
Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...
saastr
 
5th LF Energy Power Grid Model Meet-up Slides
5th LF Energy Power Grid Model Meet-up Slides5th LF Energy Power Grid Model Meet-up Slides
5th LF Energy Power Grid Model Meet-up Slides
DanBrown980551
 
June Patch Tuesday
June Patch TuesdayJune Patch Tuesday
June Patch Tuesday
Ivanti
 
Artificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopmentArtificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopment
Octavian Nadolu
 

Recently uploaded (20)

Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdfUnlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
 
Operating System Used by Users in day-to-day life.pptx
Operating System Used by Users in day-to-day life.pptxOperating System Used by Users in day-to-day life.pptx
Operating System Used by Users in day-to-day life.pptx
 
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAUHCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
 
Energy Efficient Video Encoding for Cloud and Edge Computing Instances
Energy Efficient Video Encoding for Cloud and Edge Computing InstancesEnergy Efficient Video Encoding for Cloud and Edge Computing Instances
Energy Efficient Video Encoding for Cloud and Edge Computing Instances
 
Skybuffer SAM4U tool for SAP license adoption
Skybuffer SAM4U tool for SAP license adoptionSkybuffer SAM4U tool for SAP license adoption
Skybuffer SAM4U tool for SAP license adoption
 
GraphRAG for Life Science to increase LLM accuracy
GraphRAG for Life Science to increase LLM accuracyGraphRAG for Life Science to increase LLM accuracy
GraphRAG for Life Science to increase LLM accuracy
 
Ocean lotus Threat actors project by John Sitima 2024 (1).pptx
Ocean lotus Threat actors project by John Sitima 2024 (1).pptxOcean lotus Threat actors project by John Sitima 2024 (1).pptx
Ocean lotus Threat actors project by John Sitima 2024 (1).pptx
 
Building Production Ready Search Pipelines with Spark and Milvus
Building Production Ready Search Pipelines with Spark and MilvusBuilding Production Ready Search Pipelines with Spark and Milvus
Building Production Ready Search Pipelines with Spark and Milvus
 
Skybuffer AI: Advanced Conversational and Generative AI Solution on SAP Busin...
Skybuffer AI: Advanced Conversational and Generative AI Solution on SAP Busin...Skybuffer AI: Advanced Conversational and Generative AI Solution on SAP Busin...
Skybuffer AI: Advanced Conversational and Generative AI Solution on SAP Busin...
 
System Design Case Study: Building a Scalable E-Commerce Platform - Hiike
System Design Case Study: Building a Scalable E-Commerce Platform - HiikeSystem Design Case Study: Building a Scalable E-Commerce Platform - Hiike
System Design Case Study: Building a Scalable E-Commerce Platform - Hiike
 
Monitoring and Managing Anomaly Detection on OpenShift.pdf
Monitoring and Managing Anomaly Detection on OpenShift.pdfMonitoring and Managing Anomaly Detection on OpenShift.pdf
Monitoring and Managing Anomaly Detection on OpenShift.pdf
 
Fueling AI with Great Data with Airbyte Webinar
Fueling AI with Great Data with Airbyte WebinarFueling AI with Great Data with Airbyte Webinar
Fueling AI with Great Data with Airbyte Webinar
 
Introduction of Cybersecurity with OSS at Code Europe 2024
Introduction of Cybersecurity with OSS  at Code Europe 2024Introduction of Cybersecurity with OSS  at Code Europe 2024
Introduction of Cybersecurity with OSS at Code Europe 2024
 
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with SlackLet's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
 
Driving Business Innovation: Latest Generative AI Advancements & Success Story
Driving Business Innovation: Latest Generative AI Advancements & Success StoryDriving Business Innovation: Latest Generative AI Advancements & Success Story
Driving Business Innovation: Latest Generative AI Advancements & Success Story
 
Programming Foundation Models with DSPy - Meetup Slides
Programming Foundation Models with DSPy - Meetup SlidesProgramming Foundation Models with DSPy - Meetup Slides
Programming Foundation Models with DSPy - Meetup Slides
 
Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...
Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...
Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...
 
5th LF Energy Power Grid Model Meet-up Slides
5th LF Energy Power Grid Model Meet-up Slides5th LF Energy Power Grid Model Meet-up Slides
5th LF Energy Power Grid Model Meet-up Slides
 
June Patch Tuesday
June Patch TuesdayJune Patch Tuesday
June Patch Tuesday
 
Artificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopmentArtificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopment
 

oracle Sql constraint

  • 1. SQL Constraint Made By: Israa Al- Jarrah CIS Dept-- IT Faculty
  • 2. SQL Constraint Meaning Write Constraint Constraint Type
  • 3.  Constraints can be specified when a table is created (with the CREATE TABLE statement) or after the table is created (with the ALTER TABLE statement) Constraints are used to limit the type of data that can go into a table.
  • 4. Constraint [Constraint name] Constraint Type
  • 5. You can define constraints syntactically in two ways: 1. As part of the definition of an individual column or attribute. This is called inline specification. 2. As part of the table definition. This is called out-of-line specification.
  • 6. Types of constraints: 1.Integrity constraints 2.Value constraints Table constraint Restricts data value with respect to all other values in table
  • 7. 1. Not Null 2. Unique Key 3. Primary Key 4. Foreign Key 5. Check Key 6. Default Key
  • 8. Not Null  constraint enforces a column to NOT accept NULL values. constraint enforces a column to NOT accept NULL values.  This means that you cannot insert a new record, or update a record without adding a value to this field.  Expression of Not Null we use short cut NN
  • 9. 1. Not Null Example :- Create Table Language ( Language_Name varchar2(30), Language_Id number(15) Constraint Constraint_Language_language_name _NN Not Null );
  • 10.
  • 11. All other constraints can be declared either inline or out of line.
  • 12. 2. Unique Key The UNIQUE constraint uniquely identifies each record in a database table.
  • 13. 2. Unique Key Example Create Table Person ( Person_Id number(15) Constraint Person_person_id_UN Unique Person_name varchar2(40), Person_BD Date );
  • 14. 2. Unique Key Example Create Table Person ( Person_Id number(15), Person_name varchar2(40), Person_BD Date Constraint Person_person_id_UN Unique (Person_Id)
  • 15. 3. Primary Key  Primary keys must contain unique values  A primary key column cannot contain NULL values.  Each table should have a primary key, and each table can have only ONE primary key
  • 16. 3. Primary Key Example CREATE TABLE locations_demo location_id NUMBER(4) Constraint Constraint_loc_id_pk PRIMARY KEY , street_address VARCHAR2(40) , postal_code VARCHAR2(12) );
  • 17. 3. Primary Key Example CREATE TABLE locations_demo location_id NUMBER(4) , street_address VARCHAR2(40) , postal_code VARCHAR2(12) , Constraint Constraint_loc_id_pk PRIMARY KEY (Location_id) );
  • 18. Unique Key Unique Key Primary Key
  • 19. Unique Key Unique Key  accept only one null value  unique key use many time in table.
  • 20. Primary Key Unique Key Primary key does not accept null value  primary key use only one time in table.
  • 21. 4. Foreign Key Unique Key  A FOREIGN KEY in one table points to a PRIMARY KEY in another table  The FOREIGN KEY constraint is used to prevent actions that would destroy links between tables.
  • 22. 4. Foreign Key Example Unique Key The "Persons" table: P-Id LastName FirstName Address CIty 1 Hansen Ola Timoteivn Sandnes 10 2 Svendson Tove Borgvn23 Sandnes 3 Pettersen Kari Storagt 20 Sandnes
  • 23. 4. Foreign Key Example Unique Key The “Order" table: O_Id OrderNo P_id 1 77895 3 2 44678 3 3 22456 2 4 24562 1
  • 24. 4. Foreign Key Example "P_Id" column in the "Orders" table points to the "P_Id" column in the "Persons" table. The "P_Id" column in the "Persons" table is the PRIMARY KEY in the "Persons" table. The "P_Id" column in the "Orders" table is a FOREIGN KEY in the "Orders" table.
  • 25. 4. Foreign Key Example First step must create “Person” Table Create Table Person ( P_Id number Constraint constraint_person_person_Id_PK primary key, LastName varcahr2(45), FirstName varchar2(45), Address varchar2(45), City varchar2(45) );
  • 26. 4. Foreign Key Example Create Table Order ( Order_id number(15) CONSTRAINT con_Order_id_pk Primary Key, OredrNO number(30) , P_id number(15) CONSTRINT con_person_order_id_FK refernace Person (p_id) );
  • 27. 5. Check Key  The CHECK constraint is used to limit the value range that can be placed in a column.  If you define a CHECK constraint on a single column it allows only certain values for this column
  • 28. 5. Check Key Example CREATE TABLE divisions ( div_no NUMBER CONSTRAINT check_divno CHECK (div_no BETWEEN 10 AND 99), div_name VARCHAR2(9) CONSTRAINT check_divname_cc CHECK (div_name = UPPER(div_name)) );
  • 29. 5. Check Key 6. Default Key  The DEFAULT constraint is used to insert a default value into a column  The default value will be added to all new records if no other value is specified
  • 30. 5. Check Key Example 6. Default Key CREATE TABLE Persons ( P_Id Number(15), LastName varchar(255), FirstName varchar(255), Address varchar(255), City varchar(255) DEFAULT 'Sandnes' );
  • 31. CONSTRAINT constraint_name PRIMARY KEY (columnname1, columnname2 
)
  • 32. Create table person ( Person_ID Number(15), Person_phone number(15), Constraint con_person_un Unique(Person_ID,Person_Phone) );
  • 34. Thank you for listen Israa jarrah