SlideShare a Scribd company logo
Database Constraints
Database Constraints
• Database constraints are restrictions on the contents of the
database or on database operations
• Database constraints provide a way to guarantee that:
– rows in a table have valid primary or unique key values
– rows in a dependent table have valid foreign key values that reference
rows in a parent table
– individual column values are valid
Database Constraints
• SQL/400 constraints cover four specific integrity rules:
– primary key constraint (to enforce existence integrity)
– unique constraint (to enforce candidate key integrity)
– foreign key constraint (to enforce foreign key, or referential integrity)
– check constraint (to restrict a column's values; a partial enforcement of
domain integrity)
• You specify one or more of these constraints when you use the Create
Table statement to create a base table.
• You can also add or drop constraints with the Alter Table statement.
Database Constraints
• UDB/400 enforces all four types of constraints when rows in the table are
inserted or updated
• In the case of a foreign key constraint  when rows in the parent table are
updated or deleted
• Once a constraint for a table is defined
– The constraint is enforced for all database updates through any
interface
• including SQL DML, HLL built-in I/O operations, Interactive SQL (ISQL) ad
hoc updates, etc.
Create Table Sale
( OrderID Dec( 7, 0 ) Not Null
Constraint SaleOrderIdChk Check( OrderID > 0 ),
SaleDate Date Not Null,
ShipDate Date Default Null,
SaleTot Dec( 7, 2 ) Not Null,
CrdAutNbr Int Default Null,
CustID Dec( 7, 0 ) Not Null,
Primary Key( OrderID ),
Constraint SaleCrdAutNbrUK Unique ( CrdAutNbr ),
Constraint SaleCustomerFK Foreign Key ( CustID )
References Customer ( CustID )
On Delete Cascade
On Update Restrict,
Constraint SaleShipDateChk Check( ShipDate Is Null
Or ShipDate >= SaleDate ) )
Database Constraints
• If you don't specify a constraint name, UDB/400 generates a name when the
table is created.
– The constraint name can later be used in the Alter Table statement to drop the
constraint
Primary Key Constraints
• A primary key serves as the unique identifier for rows in the table.
• The syntax of the primary key constraint (following the Constraint keyword
and the constraint name, if they're specified) is
– Primary Key( column-name, ... )
– Each primary key column's definition must include Not Null.
– For a table with a primary key constraint, UDB/400 blocks any attempt to insert or
update a row that would cause two rows in the same table to have identical
value(s) for their primary key column(s).
– A table definition can have no more than one primary key constraint.
Unique Constraints
• A unique constraint is similar to a primary key constraint doesn't have to
be defined with Not Null.
• Recommend  always specify a constraint name for a unique constraint:
– Constraint constraint-name Unique ( column-name, ... )
• Note that a unique constraint does not use the Key keyword, as do primary
key and foreign key constraints.
• The SaleCrdAutNbrUK unique constraint specifies that any non-null value
for the CrdAutNbr column must be unique.
• Allowing the CrdAutNbr column to be null and specifying the
SaleCrdAutNbrUK constraint together enforce a business rule that some
orders (e.g., those paid by cash) may exist without a credit authorization
number, but any order that does have a credit authorization number must
have a unique value.
Foreign Key Constraints
• A foreign key constraint specifies how records in different tables are
related and how UDB/400 should handle row insert, delete, and update
operations that might violate the relationship.
• For example, sales rows are generally related to the customers who place
the orders. Although it might be valid for a customer row to exist without any
corresponding sale rows, it would normally be invalid for a sale row not to
have a reference to a valid customer.
• With a relational DBMS, the relationship between rows in two tables is
expressed by a foreign key in the dependent table. A foreign key is one or
more columns that contain a value identical to a primary key (or unique key)
value in some row in the parent table (i.e., the referenced table).
• With SQL/400, we might create the Customer and Sale tables so they have the
following partial constraint definitions:
– Customer table (parent)
• Primary key column: CustID
– Sale table (dependent)
• Primary key column: OrderID
• Foreign key column: CustID
• For each row in the Sale table, the CustID column should contain the same value
as the CustID column of some Customer row because this value tells which
customer placed the order.
• The purpose of specifying a foreign key constraint is to have UDB/400 ensure
that the Sale table never has a row with a (non-null) value in the CustID column
that has no matching Customer row.
Foreign Key Constraints cont.
The Sale table's foreign key constraint, which is
Constraint SaleCustomerFK Foreign Key ( CustID )
References Customer ( CustID )
On Delete Cascade
On Update Restrict
– Specifies that the CustID column in the Sale table is a foreign key that references the
CustID primary key column in the Customer table.
– UDB/400 does not allow an application to insert a new row in the Sale table unless
the row's CustID column contains the value of some existing CustID value in the
Customer table.
– Blocks any attempt to change the CustID column of a row in the Sale table to a value
that doesn't exist in any row in the Customer table. [a new or updated Sale row must
have a parent Customer row].
A foreign key constraint can specify the same table for the dependent and parent
tables. Suppose you have an Employee table with an EmpID primary key column
and a MgrEmpID column that holds the employee ID for the person's manager. :
Create Table Employee
( EmpID Dec ( 7, 0 ) Not Null,
MgrEmpID Dec ( 7, 0 ) Not Null,
other column definitions ... ,
Primary Key ( EmpID ),
Constraint EmpMgrFK Foreign Key ( MgrEmpID )
References Employee ( EmpID )
On Update Restrict
On Delete Restrict )
Check Constraints
• Used to enforce the validity of column values.
– Constraint SaleOrderIdChk Check( OrderID > 0 )
[guarantees that the OrderID primary key column is always greater than zero]
– Constraint SaleShipDateChk Check( ShipDate Is Null Or ShipDate >=
SaleDate )
[guarantees that either a row has no ship date (i.e., the ShipDate column is
null, meaning "unknown") or the ship date is on or after the sale date].
• A check constraint can compare a column to a constant (such as in the first
example), to another column in the same table (such as in the second example),
or to an expression (e.g., ColA + 3).
• UDB/400 checks to make sure a new or changed row doesn't violate any of its
table's check constraints before an insert or update operation is allowed.
check constraints cont.
You can combine check constraints for more than one column into a single
check constraint, as in the following example:
Constraint CustStatusNameChk
Check ( ( Status = 'A' Or Status = 'I' )
And ( Name <> ' ' ) )
Add/Remove Constraints
• After you create a table, you can use the Alter Table statement to
– add or remove a primary key, unique, foreign key, or check
constraint
• To drop a table's primary key constraint, just specify the Primary Key
keywords:
Alter Table Sale
Drop Primary Key
• To drop a unique, foreign key, or check constraint, you must specify the
constraint name:
Alter Table Sale
Drop Constraint SaleCustomerFK
• To add a new constraint, use the same constraint syntax as in a Create
Table statement:
Alter Table Sale
Add Constraint SaleSaleTotChk Check( SaleTot >= 0 )
Database Constraints
• Constraints can be added to a file in several ways
– the CL Add Physical File Constraint (ADDPFCST) command,
– the Create Table or Alter Table SQL statements,
– the Table Properties tab of AS/400 Operations Navigator.
• Because constraints are defined at the file level, adding one to an existing file
requires that all existing data comply with the constraint being added. You might
need to perform data cleanup prior to introducing a constraint to the file.
• If you try adding a constraint to a file already containing data that violates the
constraint, the constraint is added in a check pending status.
• A constraint having a status of check pending doesn't become enabled until after
the data in violation of the constraint is corrected and the constraint readded.
• To identify and correct the records in violation, two CL commands exist to assist
you-Work with Physical File Constraints (WRKPFCST) and Display Check
Pending Constraint (DSPCPCST).
Constraint States
• Constraints added to a file can have a state of either enabled or disabled.
• When set to disabled, the rules of the constraint are not enforced. If a
constraint is added in a check pending status, the state is automatically set
to disabled.
– An active constraint can be temporarily disabled using the State
parameter of the Change Physical File Constraint (CHGPFCST)
command.
Database Constraints
• Database constraints provide a way to guarantee that:
– rows in a table have valid primary or unique key values
– rows in a dependent table have valid foreign key values that reference
rows in a parent table
– individual column values are valid
Database Constraints
• Database constraints provide a way to guarantee that:
– rows in a table have valid primary or unique key values
– rows in a dependent table have valid foreign key values that reference
rows in a parent table
– individual column values are valid
Database constraints

More Related Content

What's hot

Nested queries in database
Nested queries in databaseNested queries in database
Nested queries in database
Satya P. Joshi
 
DATABASE CONSTRAINTS
DATABASE CONSTRAINTSDATABASE CONSTRAINTS
DATABASE CONSTRAINTS
sunanditaAnand
 
Database Relationships
Database RelationshipsDatabase Relationships
Database Relationships
wmassie
 
Sql fundamentals
Sql fundamentalsSql fundamentals
Sql fundamentals
Ravinder Kamboj
 
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
 
Triggers in plsql
Triggers in plsqlTriggers in plsql
Triggers in plsql
Arun Sial
 
Integrity Constraints
Integrity ConstraintsIntegrity Constraints
Integrity Constraints
madhav bansal
 
Key and its different types
Key and its different typesKey and its different types
Key and its different types
Umair Shakir
 
Normalization
NormalizationNormalization
Normalization
Salman Memon
 
Packages in PL/SQL
Packages in PL/SQLPackages in PL/SQL
Packages in PL/SQL
Pooja Dixit
 
SQL(DDL & DML)
SQL(DDL & DML)SQL(DDL & DML)
SQL(DDL & DML)
Sharad Dubey
 
Sql commands
Sql commandsSql commands
Sql commands
Pooja Dixit
 
Sql(structured query language)
Sql(structured query language)Sql(structured query language)
Sql(structured query language)
Ishucs
 
introdution to SQL and SQL functions
introdution to SQL and SQL functionsintrodution to SQL and SQL functions
introdution to SQL and SQL functions
farwa waqar
 
SQL Constraints
SQL ConstraintsSQL Constraints
Best sql plsql material
Best sql plsql materialBest sql plsql material
Best sql plsql material
pitchaiah yechuri
 
Relational algebra in dbms
Relational algebra in dbmsRelational algebra in dbms
Relational algebra in dbms
Vignesh Saravanan
 
DDL And DML
DDL And DMLDDL And DML
DDL And DML
pnp @in
 
Sql subquery
Sql  subquerySql  subquery
Sql subquery
Raveena Thakur
 
Introduction to structured query language (sql)
Introduction to structured query language (sql)Introduction to structured query language (sql)
Introduction to structured query language (sql)
Sabana Maharjan
 

What's hot (20)

Nested queries in database
Nested queries in databaseNested queries in database
Nested queries in database
 
DATABASE CONSTRAINTS
DATABASE CONSTRAINTSDATABASE CONSTRAINTS
DATABASE CONSTRAINTS
 
Database Relationships
Database RelationshipsDatabase Relationships
Database Relationships
 
Sql fundamentals
Sql fundamentalsSql fundamentals
Sql fundamentals
 
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
 
Triggers in plsql
Triggers in plsqlTriggers in plsql
Triggers in plsql
 
Integrity Constraints
Integrity ConstraintsIntegrity Constraints
Integrity Constraints
 
Key and its different types
Key and its different typesKey and its different types
Key and its different types
 
Normalization
NormalizationNormalization
Normalization
 
Packages in PL/SQL
Packages in PL/SQLPackages in PL/SQL
Packages in PL/SQL
 
SQL(DDL & DML)
SQL(DDL & DML)SQL(DDL & DML)
SQL(DDL & DML)
 
Sql commands
Sql commandsSql commands
Sql commands
 
Sql(structured query language)
Sql(structured query language)Sql(structured query language)
Sql(structured query language)
 
introdution to SQL and SQL functions
introdution to SQL and SQL functionsintrodution to SQL and SQL functions
introdution to SQL and SQL functions
 
SQL Constraints
SQL ConstraintsSQL Constraints
SQL Constraints
 
Best sql plsql material
Best sql plsql materialBest sql plsql material
Best sql plsql material
 
Relational algebra in dbms
Relational algebra in dbmsRelational algebra in dbms
Relational algebra in dbms
 
DDL And DML
DDL And DMLDDL And DML
DDL And DML
 
Sql subquery
Sql  subquerySql  subquery
Sql subquery
 
Introduction to structured query language (sql)
Introduction to structured query language (sql)Introduction to structured query language (sql)
Introduction to structured query language (sql)
 

Viewers also liked

Database Design E R 2009
Database Design E R 2009Database Design E R 2009
Database Design E R 2009
Cathie101
 
DataBase ch2
DataBase ch2DataBase ch2
DataBase ch2
ayman_alawin
 
Database design
Database designDatabase design
Database design
Bashir Rezaie
 
Fundamentals of database system - Data Modeling Using the Entity-Relationshi...
Fundamentals of database system  - Data Modeling Using the Entity-Relationshi...Fundamentals of database system  - Data Modeling Using the Entity-Relationshi...
Fundamentals of database system - Data Modeling Using the Entity-Relationshi...
Mustafa Kamel Mohammadi
 
Database management system chapter16
Database management system chapter16Database management system chapter16
Database management system chapter16
Md. Mahedi Mahfuj
 
Relational Algebra-Database Systems
Relational Algebra-Database SystemsRelational Algebra-Database Systems
Relational Algebra-Database Systems
jakodongo
 
Dbms mca-section a
Dbms mca-section aDbms mca-section a
Dbms mca-section a
Vaibhav Kathuria
 
Previous question papers of Database Management System (DBMS) By SHABEEB
Previous question papers of Database Management System (DBMS) By SHABEEBPrevious question papers of Database Management System (DBMS) By SHABEEB
Previous question papers of Database Management System (DBMS) By SHABEEB
Shabeeb Shabi
 
Dbms ii mca-ch5-ch6-relational algebra-2013
Dbms ii mca-ch5-ch6-relational algebra-2013Dbms ii mca-ch5-ch6-relational algebra-2013
Dbms ii mca-ch5-ch6-relational algebra-2013
Prosanta Ghosh
 
DBMS an Example
DBMS an ExampleDBMS an Example
DBMS an Example
Dr. C.V. Suresh Babu
 
Entity Relationship Model
Entity Relationship ModelEntity Relationship Model
Entity Relationship Model
Slideshare
 
Relational Model and Relational Algebra - Lecture 3 - Introduction to Databas...
Relational Model and Relational Algebra - Lecture 3 - Introduction to Databas...Relational Model and Relational Algebra - Lecture 3 - Introduction to Databas...
Relational Model and Relational Algebra - Lecture 3 - Introduction to Databas...
Beat Signer
 
Entity Relationship Diagram
Entity Relationship DiagramEntity Relationship Diagram
Entity Relationship Diagram
Shakila Mahjabin
 
Dbms models
Dbms modelsDbms models
Dbms models
devgocool
 
Database Design Slide 1
Database Design Slide 1Database Design Slide 1
Database Design Slide 1
ahfiki
 
Different data models
Different data modelsDifferent data models
Different data models
madhusha udayangani
 
Unit 06 dbms
Unit 06 dbmsUnit 06 dbms
Unit 06 dbms
anuragmbst
 

Viewers also liked (17)

Database Design E R 2009
Database Design E R 2009Database Design E R 2009
Database Design E R 2009
 
DataBase ch2
DataBase ch2DataBase ch2
DataBase ch2
 
Database design
Database designDatabase design
Database design
 
Fundamentals of database system - Data Modeling Using the Entity-Relationshi...
Fundamentals of database system  - Data Modeling Using the Entity-Relationshi...Fundamentals of database system  - Data Modeling Using the Entity-Relationshi...
Fundamentals of database system - Data Modeling Using the Entity-Relationshi...
 
Database management system chapter16
Database management system chapter16Database management system chapter16
Database management system chapter16
 
Relational Algebra-Database Systems
Relational Algebra-Database SystemsRelational Algebra-Database Systems
Relational Algebra-Database Systems
 
Dbms mca-section a
Dbms mca-section aDbms mca-section a
Dbms mca-section a
 
Previous question papers of Database Management System (DBMS) By SHABEEB
Previous question papers of Database Management System (DBMS) By SHABEEBPrevious question papers of Database Management System (DBMS) By SHABEEB
Previous question papers of Database Management System (DBMS) By SHABEEB
 
Dbms ii mca-ch5-ch6-relational algebra-2013
Dbms ii mca-ch5-ch6-relational algebra-2013Dbms ii mca-ch5-ch6-relational algebra-2013
Dbms ii mca-ch5-ch6-relational algebra-2013
 
DBMS an Example
DBMS an ExampleDBMS an Example
DBMS an Example
 
Entity Relationship Model
Entity Relationship ModelEntity Relationship Model
Entity Relationship Model
 
Relational Model and Relational Algebra - Lecture 3 - Introduction to Databas...
Relational Model and Relational Algebra - Lecture 3 - Introduction to Databas...Relational Model and Relational Algebra - Lecture 3 - Introduction to Databas...
Relational Model and Relational Algebra - Lecture 3 - Introduction to Databas...
 
Entity Relationship Diagram
Entity Relationship DiagramEntity Relationship Diagram
Entity Relationship Diagram
 
Dbms models
Dbms modelsDbms models
Dbms models
 
Database Design Slide 1
Database Design Slide 1Database Design Slide 1
Database Design Slide 1
 
Different data models
Different data modelsDifferent data models
Different data models
 
Unit 06 dbms
Unit 06 dbmsUnit 06 dbms
Unit 06 dbms
 

Similar to Database constraints

Bn1037 demo oracle sql
Bn1037 demo  oracle sqlBn1037 demo  oracle sql
Bn1037 demo oracle sql
conline training
 
Data integrity
Data integrityData integrity
Data integrity
Rahul Gupta
 
3. ddl create
3. ddl create3. ddl create
3. ddl create
Amrit Kaur
 
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
SHAKIR325211
 
Database constraints
Database constraintsDatabase constraints
Database constraints
Khadija Parween
 
Bn1017 a demo rdbms
Bn1017 a demo  rdbmsBn1017 a demo  rdbms
Bn1017 a demo rdbms
conline training
 
Aggregate functions in SQL.pptx
Aggregate functions in SQL.pptxAggregate functions in SQL.pptx
Aggregate functions in SQL.pptx
SherinRappai1
 
Constraints In Sql
Constraints In SqlConstraints In Sql
Constraints In Sql
Anurag
 
Aggregate functions in SQL.pptx
Aggregate functions in SQL.pptxAggregate functions in SQL.pptx
Aggregate functions in SQL.pptx
SherinRappai
 
Oracle SQL Fundamentals - Lecture 3
Oracle SQL Fundamentals - Lecture 3Oracle SQL Fundamentals - Lecture 3
Oracle SQL Fundamentals - Lecture 3
MuhammadWaheed44
 
Dms 22319 micro project
Dms 22319 micro projectDms 22319 micro project
Dms 22319 micro project
ARVIND SARDAR
 
Steps towards of sql server developer
Steps towards of sql server developerSteps towards of sql server developer
Steps towards of sql server developer
Ahsan Kabir
 
SQL Inteoduction to SQL manipulating of data
SQL Inteoduction to SQL manipulating of data   SQL Inteoduction to SQL manipulating of data
SQL Inteoduction to SQL manipulating of data
Vibrant Technologies & Computers
 
Sql integrity constraints
Sql integrity constraintsSql integrity constraints
Sql integrity constraints
Vivek Singh
 
Sql ch 12 - creating database
Sql ch 12 - creating databaseSql ch 12 - creating database
Sql ch 12 - creating database
Mukesh Tekwani
 
Sql ch 9 - data integrity
Sql ch 9 - data integritySql ch 9 - data integrity
Sql ch 9 - data integrity
Mukesh Tekwani
 
Intro to tsql unit 7
Intro to tsql   unit 7Intro to tsql   unit 7
Intro to tsql unit 7
Syed Asrarali
 
1.Implementing_Data_Integrity.pdf
1.Implementing_Data_Integrity.pdf1.Implementing_Data_Integrity.pdf
1.Implementing_Data_Integrity.pdf
diaa46
 
SQL -Beginner To Intermediate Level.pdf
SQL -Beginner To Intermediate Level.pdfSQL -Beginner To Intermediate Level.pdf
SQL -Beginner To Intermediate Level.pdf
DraguClaudiu
 
SQL
SQLSQL

Similar to Database constraints (20)

Bn1037 demo oracle sql
Bn1037 demo  oracle sqlBn1037 demo  oracle sql
Bn1037 demo oracle sql
 
Data integrity
Data integrityData integrity
Data integrity
 
3. ddl create
3. ddl create3. ddl create
3. ddl create
 
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
 
Database constraints
Database constraintsDatabase constraints
Database constraints
 
Bn1017 a demo rdbms
Bn1017 a demo  rdbmsBn1017 a demo  rdbms
Bn1017 a demo rdbms
 
Aggregate functions in SQL.pptx
Aggregate functions in SQL.pptxAggregate functions in SQL.pptx
Aggregate functions in SQL.pptx
 
Constraints In Sql
Constraints In SqlConstraints In Sql
Constraints In Sql
 
Aggregate functions in SQL.pptx
Aggregate functions in SQL.pptxAggregate functions in SQL.pptx
Aggregate functions in SQL.pptx
 
Oracle SQL Fundamentals - Lecture 3
Oracle SQL Fundamentals - Lecture 3Oracle SQL Fundamentals - Lecture 3
Oracle SQL Fundamentals - Lecture 3
 
Dms 22319 micro project
Dms 22319 micro projectDms 22319 micro project
Dms 22319 micro project
 
Steps towards of sql server developer
Steps towards of sql server developerSteps towards of sql server developer
Steps towards of sql server developer
 
SQL Inteoduction to SQL manipulating of data
SQL Inteoduction to SQL manipulating of data   SQL Inteoduction to SQL manipulating of data
SQL Inteoduction to SQL manipulating of data
 
Sql integrity constraints
Sql integrity constraintsSql integrity constraints
Sql integrity constraints
 
Sql ch 12 - creating database
Sql ch 12 - creating databaseSql ch 12 - creating database
Sql ch 12 - creating database
 
Sql ch 9 - data integrity
Sql ch 9 - data integritySql ch 9 - data integrity
Sql ch 9 - data integrity
 
Intro to tsql unit 7
Intro to tsql   unit 7Intro to tsql   unit 7
Intro to tsql unit 7
 
1.Implementing_Data_Integrity.pdf
1.Implementing_Data_Integrity.pdf1.Implementing_Data_Integrity.pdf
1.Implementing_Data_Integrity.pdf
 
SQL -Beginner To Intermediate Level.pdf
SQL -Beginner To Intermediate Level.pdfSQL -Beginner To Intermediate Level.pdf
SQL -Beginner To Intermediate Level.pdf
 
SQL
SQLSQL
SQL
 

More from Fraboni Ec

Hardware multithreading
Hardware multithreadingHardware multithreading
Hardware multithreading
Fraboni Ec
 
Lisp
LispLisp
What is simultaneous multithreading
What is simultaneous multithreadingWhat is simultaneous multithreading
What is simultaneous multithreading
Fraboni Ec
 
Directory based cache coherence
Directory based cache coherenceDirectory based cache coherence
Directory based cache coherence
Fraboni Ec
 
Business analytics and data mining
Business analytics and data miningBusiness analytics and data mining
Business analytics and data mining
Fraboni Ec
 
Big picture of data mining
Big picture of data miningBig picture of data mining
Big picture of data mining
Fraboni Ec
 
Data mining and knowledge discovery
Data mining and knowledge discoveryData mining and knowledge discovery
Data mining and knowledge discovery
Fraboni Ec
 
Cache recap
Cache recapCache recap
Cache recap
Fraboni Ec
 
How analysis services caching works
How analysis services caching worksHow analysis services caching works
How analysis services caching works
Fraboni Ec
 
Hardware managed cache
Hardware managed cacheHardware managed cache
Hardware managed cache
Fraboni Ec
 
Data structures and algorithms
Data structures and algorithmsData structures and algorithms
Data structures and algorithms
Fraboni Ec
 
Cobol, lisp, and python
Cobol, lisp, and pythonCobol, lisp, and python
Cobol, lisp, and python
Fraboni Ec
 
Abstract data types
Abstract data typesAbstract data types
Abstract data types
Fraboni Ec
 
Optimizing shared caches in chip multiprocessors
Optimizing shared caches in chip multiprocessorsOptimizing shared caches in chip multiprocessors
Optimizing shared caches in chip multiprocessors
Fraboni Ec
 
Abstraction file
Abstraction fileAbstraction file
Abstraction file
Fraboni Ec
 
Object model
Object modelObject model
Object model
Fraboni Ec
 
Object oriented analysis
Object oriented analysisObject oriented analysis
Object oriented analysis
Fraboni Ec
 
Abstract class
Abstract classAbstract class
Abstract class
Fraboni Ec
 
Concurrency with java
Concurrency with javaConcurrency with java
Concurrency with java
Fraboni Ec
 
Inheritance
InheritanceInheritance
Inheritance
Fraboni Ec
 

More from Fraboni Ec (20)

Hardware multithreading
Hardware multithreadingHardware multithreading
Hardware multithreading
 
Lisp
LispLisp
Lisp
 
What is simultaneous multithreading
What is simultaneous multithreadingWhat is simultaneous multithreading
What is simultaneous multithreading
 
Directory based cache coherence
Directory based cache coherenceDirectory based cache coherence
Directory based cache coherence
 
Business analytics and data mining
Business analytics and data miningBusiness analytics and data mining
Business analytics and data mining
 
Big picture of data mining
Big picture of data miningBig picture of data mining
Big picture of data mining
 
Data mining and knowledge discovery
Data mining and knowledge discoveryData mining and knowledge discovery
Data mining and knowledge discovery
 
Cache recap
Cache recapCache recap
Cache recap
 
How analysis services caching works
How analysis services caching worksHow analysis services caching works
How analysis services caching works
 
Hardware managed cache
Hardware managed cacheHardware managed cache
Hardware managed cache
 
Data structures and algorithms
Data structures and algorithmsData structures and algorithms
Data structures and algorithms
 
Cobol, lisp, and python
Cobol, lisp, and pythonCobol, lisp, and python
Cobol, lisp, and python
 
Abstract data types
Abstract data typesAbstract data types
Abstract data types
 
Optimizing shared caches in chip multiprocessors
Optimizing shared caches in chip multiprocessorsOptimizing shared caches in chip multiprocessors
Optimizing shared caches in chip multiprocessors
 
Abstraction file
Abstraction fileAbstraction file
Abstraction file
 
Object model
Object modelObject model
Object model
 
Object oriented analysis
Object oriented analysisObject oriented analysis
Object oriented analysis
 
Abstract class
Abstract classAbstract class
Abstract class
 
Concurrency with java
Concurrency with javaConcurrency with java
Concurrency with java
 
Inheritance
InheritanceInheritance
Inheritance
 

Recently uploaded

Serial Arm Control in Real Time Presentation
Serial Arm Control in Real Time PresentationSerial Arm Control in Real Time Presentation
Serial Arm Control in Real Time Presentation
tolgahangng
 
Removing Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software FuzzingRemoving Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software Fuzzing
Aftab Hussain
 
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
 
How to use Firebase Data Connect For Flutter
How to use Firebase Data Connect For FlutterHow to use Firebase Data Connect For Flutter
How to use Firebase Data Connect For Flutter
Daiki Mogmet Ito
 
UiPath Test Automation using UiPath Test Suite series, part 6
UiPath Test Automation using UiPath Test Suite series, part 6UiPath Test Automation using UiPath Test Suite series, part 6
UiPath Test Automation using UiPath Test Suite series, part 6
DianaGray10
 
OpenID AuthZEN Interop Read Out - Authorization
OpenID AuthZEN Interop Read Out - AuthorizationOpenID AuthZEN Interop Read Out - Authorization
OpenID AuthZEN Interop Read Out - Authorization
David Brossard
 
Uni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems Copilot event_05062024_C.Vlachos.pdfUni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems S.M.S.A.
 
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
 
Things to Consider When Choosing a Website Developer for your Website | FODUU
Things to Consider When Choosing a Website Developer for your Website | FODUUThings to Consider When Choosing a Website Developer for your Website | FODUU
Things to Consider When Choosing a Website Developer for your Website | FODUU
FODUU
 
How to Get CNIC Information System with Paksim Ga.pptx
How to Get CNIC Information System with Paksim Ga.pptxHow to Get CNIC Information System with Paksim Ga.pptx
How to Get CNIC Information System with Paksim Ga.pptx
danishmna97
 
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
名前 です男
 
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
 
Best 20 SEO Techniques To Improve Website Visibility In SERP
Best 20 SEO Techniques To Improve Website Visibility In SERPBest 20 SEO Techniques To Improve Website Visibility In SERP
Best 20 SEO Techniques To Improve Website Visibility In SERP
Pixlogix Infotech
 
Generating privacy-protected synthetic data using Secludy and Milvus
Generating privacy-protected synthetic data using Secludy and MilvusGenerating privacy-protected synthetic data using Secludy and Milvus
Generating privacy-protected synthetic data using Secludy and Milvus
Zilliz
 
GenAI Pilot Implementation in the organizations
GenAI Pilot Implementation in the organizationsGenAI Pilot Implementation in the organizations
GenAI Pilot Implementation in the organizations
kumardaparthi1024
 
20240605 QFM017 Machine Intelligence Reading List May 2024
20240605 QFM017 Machine Intelligence Reading List May 202420240605 QFM017 Machine Intelligence Reading List May 2024
20240605 QFM017 Machine Intelligence Reading List May 2024
Matthew Sinclair
 
“I’m still / I’m still / Chaining from the Block”
“I’m still / I’m still / Chaining from the Block”“I’m still / I’m still / Chaining from the Block”
“I’m still / I’m still / Chaining from the Block”
Claudio Di Ciccio
 
AI-Powered Food Delivery Transforming App Development in Saudi Arabia.pdf
AI-Powered Food Delivery Transforming App Development in Saudi Arabia.pdfAI-Powered Food Delivery Transforming App Development in Saudi Arabia.pdf
AI-Powered Food Delivery Transforming App Development in Saudi Arabia.pdf
Techgropse Pvt.Ltd.
 
Your One-Stop Shop for Python Success: Top 10 US Python Development Providers
Your One-Stop Shop for Python Success: Top 10 US Python Development ProvidersYour One-Stop Shop for Python Success: Top 10 US Python Development Providers
Your One-Stop Shop for Python Success: Top 10 US Python Development Providers
akankshawande
 
Mariano G Tinti - Decoding SpaceX
Mariano G Tinti - Decoding SpaceXMariano G Tinti - Decoding SpaceX
Mariano G Tinti - Decoding SpaceX
Mariano Tinti
 

Recently uploaded (20)

Serial Arm Control in Real Time Presentation
Serial Arm Control in Real Time PresentationSerial Arm Control in Real Time Presentation
Serial Arm Control in Real Time Presentation
 
Removing Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software FuzzingRemoving Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software Fuzzing
 
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
 
How to use Firebase Data Connect For Flutter
How to use Firebase Data Connect For FlutterHow to use Firebase Data Connect For Flutter
How to use Firebase Data Connect For Flutter
 
UiPath Test Automation using UiPath Test Suite series, part 6
UiPath Test Automation using UiPath Test Suite series, part 6UiPath Test Automation using UiPath Test Suite series, part 6
UiPath Test Automation using UiPath Test Suite series, part 6
 
OpenID AuthZEN Interop Read Out - Authorization
OpenID AuthZEN Interop Read Out - AuthorizationOpenID AuthZEN Interop Read Out - Authorization
OpenID AuthZEN Interop Read Out - Authorization
 
Uni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems Copilot event_05062024_C.Vlachos.pdfUni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems Copilot event_05062024_C.Vlachos.pdf
 
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
 
Things to Consider When Choosing a Website Developer for your Website | FODUU
Things to Consider When Choosing a Website Developer for your Website | FODUUThings to Consider When Choosing a Website Developer for your Website | FODUU
Things to Consider When Choosing a Website Developer for your Website | FODUU
 
How to Get CNIC Information System with Paksim Ga.pptx
How to Get CNIC Information System with Paksim Ga.pptxHow to Get CNIC Information System with Paksim Ga.pptx
How to Get CNIC Information System with Paksim Ga.pptx
 
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
 
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
 
Best 20 SEO Techniques To Improve Website Visibility In SERP
Best 20 SEO Techniques To Improve Website Visibility In SERPBest 20 SEO Techniques To Improve Website Visibility In SERP
Best 20 SEO Techniques To Improve Website Visibility In SERP
 
Generating privacy-protected synthetic data using Secludy and Milvus
Generating privacy-protected synthetic data using Secludy and MilvusGenerating privacy-protected synthetic data using Secludy and Milvus
Generating privacy-protected synthetic data using Secludy and Milvus
 
GenAI Pilot Implementation in the organizations
GenAI Pilot Implementation in the organizationsGenAI Pilot Implementation in the organizations
GenAI Pilot Implementation in the organizations
 
20240605 QFM017 Machine Intelligence Reading List May 2024
20240605 QFM017 Machine Intelligence Reading List May 202420240605 QFM017 Machine Intelligence Reading List May 2024
20240605 QFM017 Machine Intelligence Reading List May 2024
 
“I’m still / I’m still / Chaining from the Block”
“I’m still / I’m still / Chaining from the Block”“I’m still / I’m still / Chaining from the Block”
“I’m still / I’m still / Chaining from the Block”
 
AI-Powered Food Delivery Transforming App Development in Saudi Arabia.pdf
AI-Powered Food Delivery Transforming App Development in Saudi Arabia.pdfAI-Powered Food Delivery Transforming App Development in Saudi Arabia.pdf
AI-Powered Food Delivery Transforming App Development in Saudi Arabia.pdf
 
Your One-Stop Shop for Python Success: Top 10 US Python Development Providers
Your One-Stop Shop for Python Success: Top 10 US Python Development ProvidersYour One-Stop Shop for Python Success: Top 10 US Python Development Providers
Your One-Stop Shop for Python Success: Top 10 US Python Development Providers
 
Mariano G Tinti - Decoding SpaceX
Mariano G Tinti - Decoding SpaceXMariano G Tinti - Decoding SpaceX
Mariano G Tinti - Decoding SpaceX
 

Database constraints

  • 2. Database Constraints • Database constraints are restrictions on the contents of the database or on database operations • Database constraints provide a way to guarantee that: – rows in a table have valid primary or unique key values – rows in a dependent table have valid foreign key values that reference rows in a parent table – individual column values are valid
  • 3. Database Constraints • SQL/400 constraints cover four specific integrity rules: – primary key constraint (to enforce existence integrity) – unique constraint (to enforce candidate key integrity) – foreign key constraint (to enforce foreign key, or referential integrity) – check constraint (to restrict a column's values; a partial enforcement of domain integrity) • You specify one or more of these constraints when you use the Create Table statement to create a base table. • You can also add or drop constraints with the Alter Table statement.
  • 4. Database Constraints • UDB/400 enforces all four types of constraints when rows in the table are inserted or updated • In the case of a foreign key constraint  when rows in the parent table are updated or deleted • Once a constraint for a table is defined – The constraint is enforced for all database updates through any interface • including SQL DML, HLL built-in I/O operations, Interactive SQL (ISQL) ad hoc updates, etc.
  • 5. Create Table Sale ( OrderID Dec( 7, 0 ) Not Null Constraint SaleOrderIdChk Check( OrderID > 0 ), SaleDate Date Not Null, ShipDate Date Default Null, SaleTot Dec( 7, 2 ) Not Null, CrdAutNbr Int Default Null, CustID Dec( 7, 0 ) Not Null, Primary Key( OrderID ), Constraint SaleCrdAutNbrUK Unique ( CrdAutNbr ), Constraint SaleCustomerFK Foreign Key ( CustID ) References Customer ( CustID ) On Delete Cascade On Update Restrict, Constraint SaleShipDateChk Check( ShipDate Is Null Or ShipDate >= SaleDate ) )
  • 6. Database Constraints • If you don't specify a constraint name, UDB/400 generates a name when the table is created. – The constraint name can later be used in the Alter Table statement to drop the constraint
  • 7. Primary Key Constraints • A primary key serves as the unique identifier for rows in the table. • The syntax of the primary key constraint (following the Constraint keyword and the constraint name, if they're specified) is – Primary Key( column-name, ... ) – Each primary key column's definition must include Not Null. – For a table with a primary key constraint, UDB/400 blocks any attempt to insert or update a row that would cause two rows in the same table to have identical value(s) for their primary key column(s). – A table definition can have no more than one primary key constraint.
  • 8. Unique Constraints • A unique constraint is similar to a primary key constraint doesn't have to be defined with Not Null. • Recommend  always specify a constraint name for a unique constraint: – Constraint constraint-name Unique ( column-name, ... ) • Note that a unique constraint does not use the Key keyword, as do primary key and foreign key constraints. • The SaleCrdAutNbrUK unique constraint specifies that any non-null value for the CrdAutNbr column must be unique. • Allowing the CrdAutNbr column to be null and specifying the SaleCrdAutNbrUK constraint together enforce a business rule that some orders (e.g., those paid by cash) may exist without a credit authorization number, but any order that does have a credit authorization number must have a unique value.
  • 9. Foreign Key Constraints • A foreign key constraint specifies how records in different tables are related and how UDB/400 should handle row insert, delete, and update operations that might violate the relationship. • For example, sales rows are generally related to the customers who place the orders. Although it might be valid for a customer row to exist without any corresponding sale rows, it would normally be invalid for a sale row not to have a reference to a valid customer. • With a relational DBMS, the relationship between rows in two tables is expressed by a foreign key in the dependent table. A foreign key is one or more columns that contain a value identical to a primary key (or unique key) value in some row in the parent table (i.e., the referenced table).
  • 10. • With SQL/400, we might create the Customer and Sale tables so they have the following partial constraint definitions: – Customer table (parent) • Primary key column: CustID – Sale table (dependent) • Primary key column: OrderID • Foreign key column: CustID • For each row in the Sale table, the CustID column should contain the same value as the CustID column of some Customer row because this value tells which customer placed the order. • The purpose of specifying a foreign key constraint is to have UDB/400 ensure that the Sale table never has a row with a (non-null) value in the CustID column that has no matching Customer row.
  • 11. Foreign Key Constraints cont. The Sale table's foreign key constraint, which is Constraint SaleCustomerFK Foreign Key ( CustID ) References Customer ( CustID ) On Delete Cascade On Update Restrict – Specifies that the CustID column in the Sale table is a foreign key that references the CustID primary key column in the Customer table. – UDB/400 does not allow an application to insert a new row in the Sale table unless the row's CustID column contains the value of some existing CustID value in the Customer table. – Blocks any attempt to change the CustID column of a row in the Sale table to a value that doesn't exist in any row in the Customer table. [a new or updated Sale row must have a parent Customer row].
  • 12. A foreign key constraint can specify the same table for the dependent and parent tables. Suppose you have an Employee table with an EmpID primary key column and a MgrEmpID column that holds the employee ID for the person's manager. : Create Table Employee ( EmpID Dec ( 7, 0 ) Not Null, MgrEmpID Dec ( 7, 0 ) Not Null, other column definitions ... , Primary Key ( EmpID ), Constraint EmpMgrFK Foreign Key ( MgrEmpID ) References Employee ( EmpID ) On Update Restrict On Delete Restrict )
  • 13. Check Constraints • Used to enforce the validity of column values. – Constraint SaleOrderIdChk Check( OrderID > 0 ) [guarantees that the OrderID primary key column is always greater than zero] – Constraint SaleShipDateChk Check( ShipDate Is Null Or ShipDate >= SaleDate ) [guarantees that either a row has no ship date (i.e., the ShipDate column is null, meaning "unknown") or the ship date is on or after the sale date]. • A check constraint can compare a column to a constant (such as in the first example), to another column in the same table (such as in the second example), or to an expression (e.g., ColA + 3). • UDB/400 checks to make sure a new or changed row doesn't violate any of its table's check constraints before an insert or update operation is allowed.
  • 14. check constraints cont. You can combine check constraints for more than one column into a single check constraint, as in the following example: Constraint CustStatusNameChk Check ( ( Status = 'A' Or Status = 'I' ) And ( Name <> ' ' ) )
  • 15. Add/Remove Constraints • After you create a table, you can use the Alter Table statement to – add or remove a primary key, unique, foreign key, or check constraint • To drop a table's primary key constraint, just specify the Primary Key keywords: Alter Table Sale Drop Primary Key • To drop a unique, foreign key, or check constraint, you must specify the constraint name: Alter Table Sale Drop Constraint SaleCustomerFK • To add a new constraint, use the same constraint syntax as in a Create Table statement: Alter Table Sale Add Constraint SaleSaleTotChk Check( SaleTot >= 0 )
  • 16. Database Constraints • Constraints can be added to a file in several ways – the CL Add Physical File Constraint (ADDPFCST) command, – the Create Table or Alter Table SQL statements, – the Table Properties tab of AS/400 Operations Navigator. • Because constraints are defined at the file level, adding one to an existing file requires that all existing data comply with the constraint being added. You might need to perform data cleanup prior to introducing a constraint to the file. • If you try adding a constraint to a file already containing data that violates the constraint, the constraint is added in a check pending status. • A constraint having a status of check pending doesn't become enabled until after the data in violation of the constraint is corrected and the constraint readded. • To identify and correct the records in violation, two CL commands exist to assist you-Work with Physical File Constraints (WRKPFCST) and Display Check Pending Constraint (DSPCPCST).
  • 17. Constraint States • Constraints added to a file can have a state of either enabled or disabled. • When set to disabled, the rules of the constraint are not enforced. If a constraint is added in a check pending status, the state is automatically set to disabled. – An active constraint can be temporarily disabled using the State parameter of the Change Physical File Constraint (CHGPFCST) command.
  • 18. Database Constraints • Database constraints provide a way to guarantee that: – rows in a table have valid primary or unique key values – rows in a dependent table have valid foreign key values that reference rows in a parent table – individual column values are valid
  • 19. Database Constraints • Database constraints provide a way to guarantee that: – rows in a table have valid primary or unique key values – rows in a dependent table have valid foreign key values that reference rows in a parent table – individual column values are valid