SlideShare a Scribd company logo
MySQL Constraints
Presented By Harish Gyanani
What is Constraint??

Constraints are used to specify rules for the data in a table.

If there is any violation between the constraint and the
data action, the action is aborted by the constraint.

Constraints can be specified when the table is created
(inside the CREATE TABLE statement) or after the table is
created (inside the ALTER TABLE statement).
Types of Constraints
NOT NULL
DEFAULT
UNIQUE

Check
Primary Key
Foreign Key
NOT NULL
The NOT NULL constraint enforces a column to NOT
accept NULL values.

It enforces a field to always contain a value.
This means that you cannot insert a new record, or
update a record without adding a value to this field.
NOT NULL
Set NOT NULL constraint
• While creating table
• After creating table
Verify NOT NULL in table structure

Try to skip the NOT NULL column in INSERT INTO query

Find what is stored, when we skip NOT NULL column values

Try another ways to insert null into not null column

DROP NOT NULL Constraint from Column
Set NOT NULL constraint
While creating
table

After creating
table
Set NOT NULL Constraint
(While Creating Table)

mysql> create table table1
-> (
-> rollno int,
-> name varchar(20) not null
-> );
Query OK, 0 rows affected (0.20 sec)
Set NOT NULL Constraint
(After Creating Table)

mysql> alter table table1
-> modify name varchar(20) not null;
Query OK, 0 rows affected (0.10 sec)
Records: 0 Duplicates: 0 Warnings: 0
1. Verify NOT NULL in Table Structure

NULL value not allowed in
name column
Try to enter Null value in name
column

Display Warningmysql> show warnings;
+---------+------+-------------------------------------------+
| Level

| Code | Message

|

+---------+------+-------------------------------------------+
| Warning | 1364 | Field 'name' doesn't have a default value |
+---------+------+-------------------------------------------+
1 row in set (0.00 sec)
What has been Stored by Table???.1
What has been Stored by
Table???.2
mysql> select * from table1;
+--------+------+
| rollno | name |
+--------+------+
|

1 |

|

+--------+------+
1 row in set (0.00 sec)

Still not clear what is stored by Table in Name column
What has been Stored by
Table???.3
mysql> select length(name)
-> from table1;
+--------------+
| length(name) |
+--------------+
|

0 |

+--------------+
1 row in set (0.02 sec)

Table stored empty
string
BECAUSE if it is NULL;
length function would
have returned NULL
Another way to check table has
stored empty String in not null
column.1
mysql> select * from table1
-> where name is null;
Empty set (0.01 sec)

BECAUSE table has stored empty string instead of null
null != empty String (null is not equal to empty string )
Another way to check table has
stored empty String in not null
column.1
mysql> select * from table1
-> where name ='';
+--------+------+
| rollno | name |
+--------+------+
|
1 |
|
+--------+------+
1 row in set (0.00 sec)

Hence Proved table has
Stored empty String
Conclusion: - MySQL has stored
empty string because it cannot
store NULL
MySQL Stores these values
when user doesn’t provide value
and
column cannot store NULL;
They are not equivalent to NULL
String

‘’(empty string)

Number

0

Date

0000-00-00

time

00:00:00
Another ways to Insert NULL
value.1

mysql> insert into table1(name)
-> values(NULL);
ERROR 1048 (23000): Column 'name'
cannot be null
Another ways to Insert NULL
value.2

mysql> insert into table1
-> values(23,NULL);
ERROR 1048 (23000): Column 'name'
cannot be null
Another ways to Insert NULL
value.3
mysql> insert into table1
-> values(23);
ERROR 1136 (21S01): Column count
doesn't match value count at row 1
Another ways to Insert NULL
value.4
mysql> insert into table1(rollno,name)
-> values(456);
ERROR 1136 (21S01): Column count doesn't
match value count at row 1
DEFAULT
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.
DEFAULT
Set DEFAULT constraint

• While creating table
• After creating table
Verify DEFAULT in table structure

Try to skip rollno column value in INSERT INTO

Find what is stored, when we skip NOT NULL column values

Try another ways to insert null into not null column
Set DEFAULT Constraint
While creating
table

After creating
table
Set DEFAULT Constraint
(While Creating Table)

mysql>
->
->
->
->

create table table1
(
rollno int default 500,
name varchar(20)
);

Query OK, 0 rows affected (0.08 sec)
Set DEFAULT Constraint
(After Creating Table)

mysql> alter table table1
-> alter rollno
-> set default 500;
Query OK, 0 rows affected (0.03 sec)
Records: 0 Duplicates: 0 Warnings: 0
Verify DEFAULT in Table Structure
mysql> DESC table1;
+--------+-------------+------+-----+---------+-------+
| Field | Type
| Null | Key | Default | Extra |
+--------+-------------+------+-----+---------+-------+
| rollno | int(11)
| YES |
| 500
|
|
| name
| varchar(20) | YES |
| NULL
|
|
+--------+-------------+------+-----+---------+-------+
2 rows in set (0.03 sec)

Instead of null value,
default value 500 is stored

DEFAULT value for rollno
column is 500
Try to skip rollno column value in
INSERT INTO

mysql> INSERT INTO table1(name)
-> VALUES('harish');
Query OK, 1 row affected (0.03 sec)
What has been Stored by Table???
Simple!!! The DEFAULT value
mysql> SELECT * FROM table1;
+--------+--------+
| rollno | name
|
+--------+--------+
|
500 | harish |
+--------+--------+
1 row in set (0.00 sec)

Default Value 500 is Stored when we did not specify any value
What happens when we
specify a value????
mysql> INSERT INTO table1
-> VALUES(1,'ramesh');
Query OK, 1 row affected (0.03 sec)
Simple !!! The Specified value is
Stored
mysql> SELECT * FROM table1;
+--------+--------+
| rollno | name
|
+--------+--------+
|
500 | harish |
|
1 | ramesh |
+--------+--------+
2 rows in set (0.00 sec)

The specified value in INSERT INTO statement is stored
What happens when we store
null in rollno column???

mysql> insert into table1
-> values(NULL,'suresh');
Query OK, 1 row affected (0.07 sec)
NULL is stored but why???
mysql> select * from table1;
+--------+--------+
| rollno | name
|
+--------+--------+
|
500 | harish |
|
1 | ramesh |
|
NULL | suresh |
+--------+--------+
3 rows in set (0.00 sec)
NULL can be stored with DEFAULT constraint column
Because…..
mysql> desc table1;
+--------+-------------+------+-----+---------+-------+
| Field | Type
| Null | Key | Default | Extra |
+--------+-------------+------+-----+---------+-------+
| rollno | int(11)
| YES |
| 500
|
|
| name
| varchar(20) | YES |
| NULL
|
|
+--------+-------------+------+-----+---------+-------+
2 rows in set (0.03 sec)

NULL is allowed
What happens when we Do not
specify any value????
mysql> insert into table1()
-> values();
Query OK, 1 row affected (0.03 sec)
Simple!!!
Default values are stored
mysql> select * from table1;
+--------+--------+
| rollno | name
|
+--------+--------+
|
500 | harish |
|
1 | ramesh |
|
NULL | suresh |
NULL is stored because it is|
500 | NULL
|
1. Default value for this column
+--------+--------+
2. NULL is allowed
4 rows in set (0.00 sec)
Rollno has default value 500,
that’s why it is stored
Can we specify DEFAULT
constraint in filled table???
Yes!!! We can
When we add DEFAULT Constraint in a Filled
Column,
No Old Values are altered
How to Drop DEFAULT??
mysql> alter table table1
-> alter rollno
-> drop default;
Query OK, 0 rows affected (0.08 sec)
Records: 0 Duplicates: 0 Warnings: 0
Verify, DEFAULT Dropped or
Not….
mysql> desc table1;
+--------+-------------+------+-----+---------+-------+
| Field | Type
| Null | Key | Default | Extra |
+--------+-------------+------+-----+---------+-------+
| rollno | int(11)
| YES |
| NULL
|
|
| name
| varchar(20) | YES |
| NULL
|
|
+--------+-------------+------+-----+---------+-------+
2 rows in set (0.00 sec)
Returned Back to NULL,
like other columns

NO Default value, Only
NULL
Foreign Key
What is Foreign key?
1.

2.
3.

4.
5.

6.
7.

A foreign key is a field (or collection of fields) in one table that uniquely
identifies a row of another table.
In other words, a foreign key is a column or a combination of columns
that is used to establish and enforce a link between two tables.
The table containing the foreign key is called the referencing or child
table, and the table containing the candidate key is called
the referenced or parent table.
A FOREIGN KEY in one table points to a PRIMARY KEY in another table.
The FOREIGN KEY constraint also prevents invalid data from being
inserted into the foreign key column, because it has to be one of the
values contained in the table it points to.
A table can contain more than one foreign key.
This is sometimes called a referencing key.
Example Scenario
For example, consider a database with two tables: a CUSTOMER table that
includes all customer data and an ORDER table that includes all customer
orders. Suppose the business requires that each order must refer to a single
customer. To reflect this in the database, a foreign key column is added to the
ORDER table (e.g., CUSTOMERID), which references the primary key of
CUSTOMER (e.g. ID). Because the primary key of a table must be unique, and
because CUSTOMERID only contains values from that primary key field, we
may assume that, when it has a value, CUSTOMERID will identify the
particular customer which placed the order.
Example 2
Persons table
P_Id

LastName

FirstName

Address

City

1

Hansen

Ola

Timoteivn
10

Sandnes

2

Svendson

Tove

Borgvn 23

Sandnes

3

Pettersen

Kari

Storgt 20

Stavanger

Orders table
O_Id

OrderNo

P_Id

1

77895

3

2

44678

3

3

22456

2

4

24562

1

P_id column is common in these tables. P_id is primary key in persons table. The other
way to check is, p_id values are not unique in orders table. It means persons table
which contains p_id as primary key is parent table and orders table is child table.
Student Table

Example 3

Course Table

Course table is parent
because courseid is primary
key in course table.
Example 4

City table is parent because
cityid is primary key in course
table.
Example 5

Address table is parent
because address_id is
primary key in address table.
Telephone table is child.

You must have a contact before an address or
telephone number.

Contact table is parent
because contact_id is primary
key in contact table. Address
and telephone tables are
children.
Example 6
Example 7
Example 8
Exercise 1
Exercise 2
Exercise 3
Exercise 4
Exercise 5
Exercise 6
Exercise 7
Student table
+------+--------+-----------+
| sid | sname | branch_no |
+------+--------+-----------+
| s001 | Ram
| br001
|
| s002 | Shyam | br001
|
| s003 | Sita
| br002
|
| s004 | Geeta | br003
|
| s005 | Naresh | br002
|
+------+--------+-----------+
Branch table
+-----------+-------------+
| branch_no | branch_name |
+-----------+-------------+
| br001
| IT
|
| br002
| CSE
|
| br003
| ECE
|
+-----------+-------------+
How to add foreign key in
MySQL/Oracle
While creating table
SyntaxCONSTRAINT <constraint_name>
FOREIGN KEY(<column name of this/child table>)
REFERENCES <Parent Table Name> (<column name of parent table>)
ExampleCREATE TABLE Orders
(
O_Id int NOT NULL,
OrderNo int NOT NULL,
P_Id int,
PRIMARY KEY (O_Id),
CONSTRAINT fk_PerOrders
FOREIGN KEY (P_Id)
REFERENCES Persons(P_Id)
)
How to add foreign key in
MySQL/Oracle
After creating table
SyntaxALTER TABLE <child table name>
ADD CONSTRAINT <constraint_name>
FOREIGN KEY(<column name of this/child table>)
REFERENCES <Parent Table Name> (<column name of parent table>);
ExampleALTER TABLE Orders
ADD CONSTRAINT fk_PerOrders
FOREIGN KEY (P_Id)
REFERENCES Persons(P_Id);
How to check foreign keys in a table
mysql> DESC orders;
+---------+---------+------+-----+---------+-------+
| Field
| Type
| Null | Key | Default | Extra |
+---------+---------+------+-----+---------+-------+
| O_Id
| int(11) | NO
| PRI | NULL
|
|
| OrderNo | int(11) | NO
|
| NULL
|
|
| P_Id
| int(11) | YES | MUL | NULL
|
|
+---------+---------+------+-----+---------+-------+
This shows a foreign key constraint is set to
p_id column in orders table.
But Where are the Details???
Its parent table?
Linked column in parent table?
Check full details of foreign keys
mysql> SHOW CREATE TABLE orders;

| Table | Create Table
--------------------------------------------------------+
| orders | CREATE TABLE `orders` (
`O_Id` int(11) NOT NULL,
`OrderNo` int(11) NOT NULL,
`P_Id` int(11) DEFAULT NULL,
PRIMARY KEY (`O_Id`),
KEY `fk_PerOrders` (`P_Id`),
CONSTRAINT `fk_PerOrders` FOREIGN KEY (`P_Id`) REFERENCES `persons`
(`p_id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 |
+--------+---------------------------------------------------------------------Column in
parent table

Foreign key
constraint name

Column of this
table

Parent table name
Drop Foreign key in MySQL/Oracle
MySQL

Oracle

SyntaxALTER TABLE <child table name>
DROP FOREIGN KEY <constraint name>;

SyntaxALTER TABLE <child table name>
DROP CONSTRAINT <constraint name>;

ExampleALTER TABLE Orders
DROP FOREIGN KEY fk_PerOrders;

ExampleALTER TABLE Orders
DROP CONSTRAINT fk_PerOrders
References
• http://rdbms.opengrass.net/2_Database%20Design/2.1_TermsOfRe
ference/2.1.2_Keys.html
• http://www.teachict.com/as_as_computing/ocr/H447/F453/3_3_9/dbkey/miniweb/p
g3.htm
• http://databaserefactoring.com/AddForeignKey.html
• http://www.ssw.com.au/ssw/SQLAuditor/UserguideWizards.aspx
• http://www.cs.usfca.edu/~parrt/course/601/lectures/db.html
• http://www.teachict.com/as_a2_ict_new/ocr/AS_G061/315_database_concepts/ter
minology/miniweb/pg13.htm
• http://www.sparxsystems.com/enterprise_architect_user_guide/9.
0/database_engineering/create_a_foreign_key.html

More Related Content

What's hot

Database Connectivity in PHP
Database Connectivity in PHPDatabase Connectivity in PHP
Database Connectivity in PHP
Taha Malampatti
 
Java collections notes
Java collections notesJava collections notes
Java collections notes
Surendar Meesala
 
Spring ppt
Spring pptSpring ppt
Spring ppt
Mumbai Academisc
 
This keyword in java
This keyword in javaThis keyword in java
This keyword in java
Hitesh Kumar
 
SQL
SQLSQL
Java Collections Framework
Java Collections FrameworkJava Collections Framework
Java Collections Framework
Sony India Software Center
 
Constructor in java
Constructor in javaConstructor in java
Constructor in java
Hitesh Kumar
 
Sql tutorial
Sql tutorialSql tutorial
Sql tutorial
Rumman Ansari
 
XML Document Object Model (DOM)
XML Document Object Model (DOM)XML Document Object Model (DOM)
XML Document Object Model (DOM)
BOSS Webtech
 
Exception handling in plsql
Exception handling in plsqlException handling in plsql
Exception handling in plsql
Arun Sial
 
Java Collections
Java  Collections Java  Collections
C# program structure
C# program structureC# program structure
Aggregate functions
Aggregate functionsAggregate functions
Aggregate functions
sinhacp
 
Php array
Php arrayPhp array
Php array
Nikul Shah
 
Triggers in plsql
Triggers in plsqlTriggers in plsql
Triggers in plsql
Arun Sial
 
MySql:Basics
MySql:BasicsMySql:Basics
MySql:Basics
DataminingTools Inc
 
Php string function
Php string function Php string function
Php string function
Ravi Bhadauria
 
Exception Handling in JAVA
Exception Handling in JAVAException Handling in JAVA
Exception Handling in JAVA
SURIT DATTA
 
Threads concept in java
Threads concept in javaThreads concept in java
Threads concept in java
Muthukumaran Subramanian
 
MySQL for beginners
MySQL for beginnersMySQL for beginners
MySQL for beginners
Saeid Zebardast
 

What's hot (20)

Database Connectivity in PHP
Database Connectivity in PHPDatabase Connectivity in PHP
Database Connectivity in PHP
 
Java collections notes
Java collections notesJava collections notes
Java collections notes
 
Spring ppt
Spring pptSpring ppt
Spring ppt
 
This keyword in java
This keyword in javaThis keyword in java
This keyword in java
 
SQL
SQLSQL
SQL
 
Java Collections Framework
Java Collections FrameworkJava Collections Framework
Java Collections Framework
 
Constructor in java
Constructor in javaConstructor in java
Constructor in java
 
Sql tutorial
Sql tutorialSql tutorial
Sql tutorial
 
XML Document Object Model (DOM)
XML Document Object Model (DOM)XML Document Object Model (DOM)
XML Document Object Model (DOM)
 
Exception handling in plsql
Exception handling in plsqlException handling in plsql
Exception handling in plsql
 
Java Collections
Java  Collections Java  Collections
Java Collections
 
C# program structure
C# program structureC# program structure
C# program structure
 
Aggregate functions
Aggregate functionsAggregate functions
Aggregate functions
 
Php array
Php arrayPhp array
Php array
 
Triggers in plsql
Triggers in plsqlTriggers in plsql
Triggers in plsql
 
MySql:Basics
MySql:BasicsMySql:Basics
MySql:Basics
 
Php string function
Php string function Php string function
Php string function
 
Exception Handling in JAVA
Exception Handling in JAVAException Handling in JAVA
Exception Handling in JAVA
 
Threads concept in java
Threads concept in javaThreads concept in java
Threads concept in java
 
MySQL for beginners
MySQL for beginnersMySQL for beginners
MySQL for beginners
 

Viewers also liked

Introduction to DB design
Introduction to DB designIntroduction to DB design
Introduction to DB design
Vijay Kalangi
 
Using SQL Standards? Database SQL comparition
Using SQL Standards? Database SQL comparitionUsing SQL Standards? Database SQL comparition
Using SQL Standards? Database SQL comparition
Denish Patel
 
Naming Standards, Clean Code
Naming Standards, Clean CodeNaming Standards, Clean Code
Naming Standards, Clean Code
CleanestCode
 
Building a CRM Application
Building a CRM ApplicationBuilding a CRM Application
Building a CRM Application
Iron Speed
 
RDBMS ERD
RDBMS ERDRDBMS ERD
RDBMS ERD
Sarmad Ali
 
外部キー制約に伴うロックの小話
外部キー制約に伴うロックの小話外部キー制約に伴うロックの小話
外部キー制約に伴うロックの小話
ichirin2501
 
MySQL Best Practices - OTN
MySQL Best Practices - OTNMySQL Best Practices - OTN
MySQL Best Practices - OTN
Ronald Bradford
 

Viewers also liked (7)

Introduction to DB design
Introduction to DB designIntroduction to DB design
Introduction to DB design
 
Using SQL Standards? Database SQL comparition
Using SQL Standards? Database SQL comparitionUsing SQL Standards? Database SQL comparition
Using SQL Standards? Database SQL comparition
 
Naming Standards, Clean Code
Naming Standards, Clean CodeNaming Standards, Clean Code
Naming Standards, Clean Code
 
Building a CRM Application
Building a CRM ApplicationBuilding a CRM Application
Building a CRM Application
 
RDBMS ERD
RDBMS ERDRDBMS ERD
RDBMS ERD
 
外部キー制約に伴うロックの小話
外部キー制約に伴うロックの小話外部キー制約に伴うロックの小話
外部キー制約に伴うロックの小話
 
MySQL Best Practices - OTN
MySQL Best Practices - OTNMySQL Best Practices - OTN
MySQL Best Practices - OTN
 

Similar to MySQL constraints

Mysql basics1
Mysql basics1Mysql basics1
Mysql basics1
Steffy Robert
 
SQL Tutorial for BCA-2
SQL Tutorial for BCA-2SQL Tutorial for BCA-2
SQL Tutorial for BCA-2
Raj vardhan
 
My SQL
My SQLMy SQL
database-querry-student-note
database-querry-student-notedatabase-querry-student-note
database-querry-student-note
Leerpiny Makouach
 
Mysql alter-command
Mysql alter-commandMysql alter-command
Mysql alter-command
beben benzy
 
MySQL Database System Hiep Dinh
MySQL Database System Hiep DinhMySQL Database System Hiep Dinh
MySQL Database System Hiep Dinh
webhostingguy
 
mysqlHiep.ppt
mysqlHiep.pptmysqlHiep.ppt
mysqlHiep.ppt
webhostingguy
 
3. ddl create
3. ddl create3. ddl create
3. ddl create
Amrit Kaur
 
DATA BASE || INTRODUCTION OF DATABASE \\ SQL 2018
DATA BASE || INTRODUCTION OF DATABASE \\ SQL 2018DATA BASE || INTRODUCTION OF DATABASE \\ SQL 2018
DATA BASE || INTRODUCTION OF DATABASE \\ SQL 2018
teachersduniya.com
 
MySql slides (ppt)
MySql slides (ppt)MySql slides (ppt)
MySql slides (ppt)
webhostingguy
 
My sql1
My sql1My sql1
Sql basics
Sql basicsSql basics
Sql basics
Aman Lalpuria
 
Applied Partitioning And Scaling Your Database System Presentation
Applied Partitioning And Scaling Your Database System PresentationApplied Partitioning And Scaling Your Database System Presentation
Applied Partitioning And Scaling Your Database System Presentation
Richard Crowley
 
DBMS 4 | MySQL - DDL & DML Commands
DBMS 4 | MySQL - DDL & DML CommandsDBMS 4 | MySQL - DDL & DML Commands
DBMS 4 | MySQL - DDL & DML Commands
Mohammad Imam Hossain
 
Optimizing queries MySQL
Optimizing queries MySQLOptimizing queries MySQL
Optimizing queries MySQL
Georgi Sotirov
 
[Www.pkbulk.blogspot.com]dbms10
[Www.pkbulk.blogspot.com]dbms10[Www.pkbulk.blogspot.com]dbms10
[Www.pkbulk.blogspot.com]dbms10
AnusAhmad
 
MySQL Essential Training
MySQL Essential TrainingMySQL Essential Training
MySQL Essential Training
HudaRaghibKadhim
 
Table partitioning in PostgreSQL + Rails
Table partitioning in PostgreSQL + RailsTable partitioning in PostgreSQL + Rails
Table partitioning in PostgreSQL + Rails
Agnieszka Figiel
 
Materi my sql part 1
Materi my sql part 1Materi my sql part 1
Materi my sql part 1
Amar Senjaku Ofdetraisar
 
MySQL Console - Dasar I
MySQL Console - Dasar IMySQL Console - Dasar I
MySQL Console - Dasar I
Roni Darmanto
 

Similar to MySQL constraints (20)

Mysql basics1
Mysql basics1Mysql basics1
Mysql basics1
 
SQL Tutorial for BCA-2
SQL Tutorial for BCA-2SQL Tutorial for BCA-2
SQL Tutorial for BCA-2
 
My SQL
My SQLMy SQL
My SQL
 
database-querry-student-note
database-querry-student-notedatabase-querry-student-note
database-querry-student-note
 
Mysql alter-command
Mysql alter-commandMysql alter-command
Mysql alter-command
 
MySQL Database System Hiep Dinh
MySQL Database System Hiep DinhMySQL Database System Hiep Dinh
MySQL Database System Hiep Dinh
 
mysqlHiep.ppt
mysqlHiep.pptmysqlHiep.ppt
mysqlHiep.ppt
 
3. ddl create
3. ddl create3. ddl create
3. ddl create
 
DATA BASE || INTRODUCTION OF DATABASE \\ SQL 2018
DATA BASE || INTRODUCTION OF DATABASE \\ SQL 2018DATA BASE || INTRODUCTION OF DATABASE \\ SQL 2018
DATA BASE || INTRODUCTION OF DATABASE \\ SQL 2018
 
MySql slides (ppt)
MySql slides (ppt)MySql slides (ppt)
MySql slides (ppt)
 
My sql1
My sql1My sql1
My sql1
 
Sql basics
Sql basicsSql basics
Sql basics
 
Applied Partitioning And Scaling Your Database System Presentation
Applied Partitioning And Scaling Your Database System PresentationApplied Partitioning And Scaling Your Database System Presentation
Applied Partitioning And Scaling Your Database System Presentation
 
DBMS 4 | MySQL - DDL & DML Commands
DBMS 4 | MySQL - DDL & DML CommandsDBMS 4 | MySQL - DDL & DML Commands
DBMS 4 | MySQL - DDL & DML Commands
 
Optimizing queries MySQL
Optimizing queries MySQLOptimizing queries MySQL
Optimizing queries MySQL
 
[Www.pkbulk.blogspot.com]dbms10
[Www.pkbulk.blogspot.com]dbms10[Www.pkbulk.blogspot.com]dbms10
[Www.pkbulk.blogspot.com]dbms10
 
MySQL Essential Training
MySQL Essential TrainingMySQL Essential Training
MySQL Essential Training
 
Table partitioning in PostgreSQL + Rails
Table partitioning in PostgreSQL + RailsTable partitioning in PostgreSQL + Rails
Table partitioning in PostgreSQL + Rails
 
Materi my sql part 1
Materi my sql part 1Materi my sql part 1
Materi my sql part 1
 
MySQL Console - Dasar I
MySQL Console - Dasar IMySQL Console - Dasar I
MySQL Console - Dasar I
 

Recently uploaded

Walmart Business+ and Spark Good for Nonprofits.pdf
Walmart Business+ and Spark Good for Nonprofits.pdfWalmart Business+ and Spark Good for Nonprofits.pdf
Walmart Business+ and Spark Good for Nonprofits.pdf
TechSoup
 
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
PECB
 
The History of Stoke Newington Street Names
The History of Stoke Newington Street NamesThe History of Stoke Newington Street Names
The History of Stoke Newington Street Names
History of Stoke Newington
 
writing about opinions about Australia the movie
writing about opinions about Australia the moviewriting about opinions about Australia the movie
writing about opinions about Australia the movie
Nicholas Montgomery
 
PCOS corelations and management through Ayurveda.
PCOS corelations and management through Ayurveda.PCOS corelations and management through Ayurveda.
PCOS corelations and management through Ayurveda.
Dr. Shivangi Singh Parihar
 
বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdfবাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
eBook.com.bd (প্রয়োজনীয় বাংলা বই)
 
Your Skill Boost Masterclass: Strategies for Effective Upskilling
Your Skill Boost Masterclass: Strategies for Effective UpskillingYour Skill Boost Masterclass: Strategies for Effective Upskilling
Your Skill Boost Masterclass: Strategies for Effective Upskilling
Excellence Foundation for South Sudan
 
The basics of sentences session 6pptx.pptx
The basics of sentences session 6pptx.pptxThe basics of sentences session 6pptx.pptx
The basics of sentences session 6pptx.pptx
heathfieldcps1
 
Liberal Approach to the Study of Indian Politics.pdf
Liberal Approach to the Study of Indian Politics.pdfLiberal Approach to the Study of Indian Politics.pdf
Liberal Approach to the Study of Indian Politics.pdf
WaniBasim
 
ANATOMY AND BIOMECHANICS OF HIP JOINT.pdf
ANATOMY AND BIOMECHANICS OF HIP JOINT.pdfANATOMY AND BIOMECHANICS OF HIP JOINT.pdf
ANATOMY AND BIOMECHANICS OF HIP JOINT.pdf
Priyankaranawat4
 
What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...
What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...
What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...
GeorgeMilliken2
 
PIMS Job Advertisement 2024.pdf Islamabad
PIMS Job Advertisement 2024.pdf IslamabadPIMS Job Advertisement 2024.pdf Islamabad
PIMS Job Advertisement 2024.pdf Islamabad
AyyanKhan40
 
How to Make a Field Mandatory in Odoo 17
How to Make a Field Mandatory in Odoo 17How to Make a Field Mandatory in Odoo 17
How to Make a Field Mandatory in Odoo 17
Celine George
 
Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...
Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...
Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...
National Information Standards Organization (NISO)
 
How to Setup Warehouse & Location in Odoo 17 Inventory
How to Setup Warehouse & Location in Odoo 17 InventoryHow to Setup Warehouse & Location in Odoo 17 Inventory
How to Setup Warehouse & Location in Odoo 17 Inventory
Celine George
 
Pride Month Slides 2024 David Douglas School District
Pride Month Slides 2024 David Douglas School DistrictPride Month Slides 2024 David Douglas School District
Pride Month Slides 2024 David Douglas School District
David Douglas School District
 
Life upper-Intermediate B2 Workbook for student
Life upper-Intermediate B2 Workbook for studentLife upper-Intermediate B2 Workbook for student
Life upper-Intermediate B2 Workbook for student
NgcHiNguyn25
 
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptxC1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
mulvey2
 
Digital Artifact 1 - 10VCD Environments Unit
Digital Artifact 1 - 10VCD Environments UnitDigital Artifact 1 - 10VCD Environments Unit
Digital Artifact 1 - 10VCD Environments Unit
chanes7
 
BBR 2024 Summer Sessions Interview Training
BBR  2024 Summer Sessions Interview TrainingBBR  2024 Summer Sessions Interview Training
BBR 2024 Summer Sessions Interview Training
Katrina Pritchard
 

Recently uploaded (20)

Walmart Business+ and Spark Good for Nonprofits.pdf
Walmart Business+ and Spark Good for Nonprofits.pdfWalmart Business+ and Spark Good for Nonprofits.pdf
Walmart Business+ and Spark Good for Nonprofits.pdf
 
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
 
The History of Stoke Newington Street Names
The History of Stoke Newington Street NamesThe History of Stoke Newington Street Names
The History of Stoke Newington Street Names
 
writing about opinions about Australia the movie
writing about opinions about Australia the moviewriting about opinions about Australia the movie
writing about opinions about Australia the movie
 
PCOS corelations and management through Ayurveda.
PCOS corelations and management through Ayurveda.PCOS corelations and management through Ayurveda.
PCOS corelations and management through Ayurveda.
 
বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdfবাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
 
Your Skill Boost Masterclass: Strategies for Effective Upskilling
Your Skill Boost Masterclass: Strategies for Effective UpskillingYour Skill Boost Masterclass: Strategies for Effective Upskilling
Your Skill Boost Masterclass: Strategies for Effective Upskilling
 
The basics of sentences session 6pptx.pptx
The basics of sentences session 6pptx.pptxThe basics of sentences session 6pptx.pptx
The basics of sentences session 6pptx.pptx
 
Liberal Approach to the Study of Indian Politics.pdf
Liberal Approach to the Study of Indian Politics.pdfLiberal Approach to the Study of Indian Politics.pdf
Liberal Approach to the Study of Indian Politics.pdf
 
ANATOMY AND BIOMECHANICS OF HIP JOINT.pdf
ANATOMY AND BIOMECHANICS OF HIP JOINT.pdfANATOMY AND BIOMECHANICS OF HIP JOINT.pdf
ANATOMY AND BIOMECHANICS OF HIP JOINT.pdf
 
What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...
What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...
What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...
 
PIMS Job Advertisement 2024.pdf Islamabad
PIMS Job Advertisement 2024.pdf IslamabadPIMS Job Advertisement 2024.pdf Islamabad
PIMS Job Advertisement 2024.pdf Islamabad
 
How to Make a Field Mandatory in Odoo 17
How to Make a Field Mandatory in Odoo 17How to Make a Field Mandatory in Odoo 17
How to Make a Field Mandatory in Odoo 17
 
Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...
Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...
Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...
 
How to Setup Warehouse & Location in Odoo 17 Inventory
How to Setup Warehouse & Location in Odoo 17 InventoryHow to Setup Warehouse & Location in Odoo 17 Inventory
How to Setup Warehouse & Location in Odoo 17 Inventory
 
Pride Month Slides 2024 David Douglas School District
Pride Month Slides 2024 David Douglas School DistrictPride Month Slides 2024 David Douglas School District
Pride Month Slides 2024 David Douglas School District
 
Life upper-Intermediate B2 Workbook for student
Life upper-Intermediate B2 Workbook for studentLife upper-Intermediate B2 Workbook for student
Life upper-Intermediate B2 Workbook for student
 
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptxC1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
 
Digital Artifact 1 - 10VCD Environments Unit
Digital Artifact 1 - 10VCD Environments UnitDigital Artifact 1 - 10VCD Environments Unit
Digital Artifact 1 - 10VCD Environments Unit
 
BBR 2024 Summer Sessions Interview Training
BBR  2024 Summer Sessions Interview TrainingBBR  2024 Summer Sessions Interview Training
BBR 2024 Summer Sessions Interview Training
 

MySQL constraints

  • 2. What is Constraint?? Constraints are used to specify rules for the data in a table. If there is any violation between the constraint and the data action, the action is aborted by the constraint. Constraints can be specified when the table is created (inside the CREATE TABLE statement) or after the table is created (inside the ALTER TABLE statement).
  • 3. Types of Constraints NOT NULL DEFAULT UNIQUE Check Primary Key Foreign Key
  • 4. NOT NULL The NOT NULL constraint enforces a column to NOT accept NULL values. It enforces a field to always contain a value. This means that you cannot insert a new record, or update a record without adding a value to this field.
  • 5. NOT NULL Set NOT NULL constraint • While creating table • After creating table Verify NOT NULL in table structure Try to skip the NOT NULL column in INSERT INTO query Find what is stored, when we skip NOT NULL column values Try another ways to insert null into not null column DROP NOT NULL Constraint from Column
  • 6. Set NOT NULL constraint While creating table After creating table
  • 7. Set NOT NULL Constraint (While Creating Table) mysql> create table table1 -> ( -> rollno int, -> name varchar(20) not null -> ); Query OK, 0 rows affected (0.20 sec)
  • 8. Set NOT NULL Constraint (After Creating Table) mysql> alter table table1 -> modify name varchar(20) not null; Query OK, 0 rows affected (0.10 sec) Records: 0 Duplicates: 0 Warnings: 0
  • 9. 1. Verify NOT NULL in Table Structure NULL value not allowed in name column
  • 10. Try to enter Null value in name column Display Warningmysql> show warnings; +---------+------+-------------------------------------------+ | Level | Code | Message | +---------+------+-------------------------------------------+ | Warning | 1364 | Field 'name' doesn't have a default value | +---------+------+-------------------------------------------+ 1 row in set (0.00 sec)
  • 11. What has been Stored by Table???.1
  • 12. What has been Stored by Table???.2 mysql> select * from table1; +--------+------+ | rollno | name | +--------+------+ | 1 | | +--------+------+ 1 row in set (0.00 sec) Still not clear what is stored by Table in Name column
  • 13. What has been Stored by Table???.3 mysql> select length(name) -> from table1; +--------------+ | length(name) | +--------------+ | 0 | +--------------+ 1 row in set (0.02 sec) Table stored empty string BECAUSE if it is NULL; length function would have returned NULL
  • 14. Another way to check table has stored empty String in not null column.1 mysql> select * from table1 -> where name is null; Empty set (0.01 sec) BECAUSE table has stored empty string instead of null null != empty String (null is not equal to empty string )
  • 15. Another way to check table has stored empty String in not null column.1 mysql> select * from table1 -> where name =''; +--------+------+ | rollno | name | +--------+------+ | 1 | | +--------+------+ 1 row in set (0.00 sec) Hence Proved table has Stored empty String
  • 16. Conclusion: - MySQL has stored empty string because it cannot store NULL
  • 17. MySQL Stores these values when user doesn’t provide value and column cannot store NULL; They are not equivalent to NULL String ‘’(empty string) Number 0 Date 0000-00-00 time 00:00:00
  • 18. Another ways to Insert NULL value.1 mysql> insert into table1(name) -> values(NULL); ERROR 1048 (23000): Column 'name' cannot be null
  • 19. Another ways to Insert NULL value.2 mysql> insert into table1 -> values(23,NULL); ERROR 1048 (23000): Column 'name' cannot be null
  • 20. Another ways to Insert NULL value.3 mysql> insert into table1 -> values(23); ERROR 1136 (21S01): Column count doesn't match value count at row 1
  • 21. Another ways to Insert NULL value.4 mysql> insert into table1(rollno,name) -> values(456); ERROR 1136 (21S01): Column count doesn't match value count at row 1
  • 22. DEFAULT 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.
  • 23. DEFAULT Set DEFAULT constraint • While creating table • After creating table Verify DEFAULT in table structure Try to skip rollno column value in INSERT INTO Find what is stored, when we skip NOT NULL column values Try another ways to insert null into not null column
  • 24. Set DEFAULT Constraint While creating table After creating table
  • 25. Set DEFAULT Constraint (While Creating Table) mysql> -> -> -> -> create table table1 ( rollno int default 500, name varchar(20) ); Query OK, 0 rows affected (0.08 sec)
  • 26. Set DEFAULT Constraint (After Creating Table) mysql> alter table table1 -> alter rollno -> set default 500; Query OK, 0 rows affected (0.03 sec) Records: 0 Duplicates: 0 Warnings: 0
  • 27. Verify DEFAULT in Table Structure mysql> DESC table1; +--------+-------------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +--------+-------------+------+-----+---------+-------+ | rollno | int(11) | YES | | 500 | | | name | varchar(20) | YES | | NULL | | +--------+-------------+------+-----+---------+-------+ 2 rows in set (0.03 sec) Instead of null value, default value 500 is stored DEFAULT value for rollno column is 500
  • 28. Try to skip rollno column value in INSERT INTO mysql> INSERT INTO table1(name) -> VALUES('harish'); Query OK, 1 row affected (0.03 sec)
  • 29. What has been Stored by Table???
  • 30. Simple!!! The DEFAULT value mysql> SELECT * FROM table1; +--------+--------+ | rollno | name | +--------+--------+ | 500 | harish | +--------+--------+ 1 row in set (0.00 sec) Default Value 500 is Stored when we did not specify any value
  • 31. What happens when we specify a value???? mysql> INSERT INTO table1 -> VALUES(1,'ramesh'); Query OK, 1 row affected (0.03 sec)
  • 32. Simple !!! The Specified value is Stored mysql> SELECT * FROM table1; +--------+--------+ | rollno | name | +--------+--------+ | 500 | harish | | 1 | ramesh | +--------+--------+ 2 rows in set (0.00 sec) The specified value in INSERT INTO statement is stored
  • 33. What happens when we store null in rollno column??? mysql> insert into table1 -> values(NULL,'suresh'); Query OK, 1 row affected (0.07 sec)
  • 34. NULL is stored but why??? mysql> select * from table1; +--------+--------+ | rollno | name | +--------+--------+ | 500 | harish | | 1 | ramesh | | NULL | suresh | +--------+--------+ 3 rows in set (0.00 sec) NULL can be stored with DEFAULT constraint column
  • 35. Because….. mysql> desc table1; +--------+-------------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +--------+-------------+------+-----+---------+-------+ | rollno | int(11) | YES | | 500 | | | name | varchar(20) | YES | | NULL | | +--------+-------------+------+-----+---------+-------+ 2 rows in set (0.03 sec) NULL is allowed
  • 36. What happens when we Do not specify any value???? mysql> insert into table1() -> values(); Query OK, 1 row affected (0.03 sec)
  • 37. Simple!!! Default values are stored mysql> select * from table1; +--------+--------+ | rollno | name | +--------+--------+ | 500 | harish | | 1 | ramesh | | NULL | suresh | NULL is stored because it is| 500 | NULL | 1. Default value for this column +--------+--------+ 2. NULL is allowed 4 rows in set (0.00 sec) Rollno has default value 500, that’s why it is stored
  • 38. Can we specify DEFAULT constraint in filled table???
  • 39. Yes!!! We can When we add DEFAULT Constraint in a Filled Column, No Old Values are altered
  • 40. How to Drop DEFAULT?? mysql> alter table table1 -> alter rollno -> drop default; Query OK, 0 rows affected (0.08 sec) Records: 0 Duplicates: 0 Warnings: 0
  • 41. Verify, DEFAULT Dropped or Not…. mysql> desc table1; +--------+-------------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +--------+-------------+------+-----+---------+-------+ | rollno | int(11) | YES | | NULL | | | name | varchar(20) | YES | | NULL | | +--------+-------------+------+-----+---------+-------+ 2 rows in set (0.00 sec) Returned Back to NULL, like other columns NO Default value, Only NULL
  • 43. What is Foreign key? 1. 2. 3. 4. 5. 6. 7. A foreign key is a field (or collection of fields) in one table that uniquely identifies a row of another table. In other words, a foreign key is a column or a combination of columns that is used to establish and enforce a link between two tables. The table containing the foreign key is called the referencing or child table, and the table containing the candidate key is called the referenced or parent table. A FOREIGN KEY in one table points to a PRIMARY KEY in another table. The FOREIGN KEY constraint also prevents invalid data from being inserted into the foreign key column, because it has to be one of the values contained in the table it points to. A table can contain more than one foreign key. This is sometimes called a referencing key.
  • 44. Example Scenario For example, consider a database with two tables: a CUSTOMER table that includes all customer data and an ORDER table that includes all customer orders. Suppose the business requires that each order must refer to a single customer. To reflect this in the database, a foreign key column is added to the ORDER table (e.g., CUSTOMERID), which references the primary key of CUSTOMER (e.g. ID). Because the primary key of a table must be unique, and because CUSTOMERID only contains values from that primary key field, we may assume that, when it has a value, CUSTOMERID will identify the particular customer which placed the order.
  • 45. Example 2 Persons table P_Id LastName FirstName Address City 1 Hansen Ola Timoteivn 10 Sandnes 2 Svendson Tove Borgvn 23 Sandnes 3 Pettersen Kari Storgt 20 Stavanger Orders table O_Id OrderNo P_Id 1 77895 3 2 44678 3 3 22456 2 4 24562 1 P_id column is common in these tables. P_id is primary key in persons table. The other way to check is, p_id values are not unique in orders table. It means persons table which contains p_id as primary key is parent table and orders table is child table.
  • 46. Student Table Example 3 Course Table Course table is parent because courseid is primary key in course table.
  • 47. Example 4 City table is parent because cityid is primary key in course table.
  • 48. Example 5 Address table is parent because address_id is primary key in address table. Telephone table is child. You must have a contact before an address or telephone number. Contact table is parent because contact_id is primary key in contact table. Address and telephone tables are children.
  • 58. Exercise 7 Student table +------+--------+-----------+ | sid | sname | branch_no | +------+--------+-----------+ | s001 | Ram | br001 | | s002 | Shyam | br001 | | s003 | Sita | br002 | | s004 | Geeta | br003 | | s005 | Naresh | br002 | +------+--------+-----------+ Branch table +-----------+-------------+ | branch_no | branch_name | +-----------+-------------+ | br001 | IT | | br002 | CSE | | br003 | ECE | +-----------+-------------+
  • 59. How to add foreign key in MySQL/Oracle While creating table SyntaxCONSTRAINT <constraint_name> FOREIGN KEY(<column name of this/child table>) REFERENCES <Parent Table Name> (<column name of parent table>) ExampleCREATE TABLE Orders ( O_Id int NOT NULL, OrderNo int NOT NULL, P_Id int, PRIMARY KEY (O_Id), CONSTRAINT fk_PerOrders FOREIGN KEY (P_Id) REFERENCES Persons(P_Id) )
  • 60. How to add foreign key in MySQL/Oracle After creating table SyntaxALTER TABLE <child table name> ADD CONSTRAINT <constraint_name> FOREIGN KEY(<column name of this/child table>) REFERENCES <Parent Table Name> (<column name of parent table>); ExampleALTER TABLE Orders ADD CONSTRAINT fk_PerOrders FOREIGN KEY (P_Id) REFERENCES Persons(P_Id);
  • 61. How to check foreign keys in a table mysql> DESC orders; +---------+---------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +---------+---------+------+-----+---------+-------+ | O_Id | int(11) | NO | PRI | NULL | | | OrderNo | int(11) | NO | | NULL | | | P_Id | int(11) | YES | MUL | NULL | | +---------+---------+------+-----+---------+-------+ This shows a foreign key constraint is set to p_id column in orders table. But Where are the Details??? Its parent table? Linked column in parent table?
  • 62. Check full details of foreign keys mysql> SHOW CREATE TABLE orders; | Table | Create Table --------------------------------------------------------+ | orders | CREATE TABLE `orders` ( `O_Id` int(11) NOT NULL, `OrderNo` int(11) NOT NULL, `P_Id` int(11) DEFAULT NULL, PRIMARY KEY (`O_Id`), KEY `fk_PerOrders` (`P_Id`), CONSTRAINT `fk_PerOrders` FOREIGN KEY (`P_Id`) REFERENCES `persons` (`p_id`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1 | +--------+---------------------------------------------------------------------Column in parent table Foreign key constraint name Column of this table Parent table name
  • 63. Drop Foreign key in MySQL/Oracle MySQL Oracle SyntaxALTER TABLE <child table name> DROP FOREIGN KEY <constraint name>; SyntaxALTER TABLE <child table name> DROP CONSTRAINT <constraint name>; ExampleALTER TABLE Orders DROP FOREIGN KEY fk_PerOrders; ExampleALTER TABLE Orders DROP CONSTRAINT fk_PerOrders
  • 64. References • http://rdbms.opengrass.net/2_Database%20Design/2.1_TermsOfRe ference/2.1.2_Keys.html • http://www.teachict.com/as_as_computing/ocr/H447/F453/3_3_9/dbkey/miniweb/p g3.htm • http://databaserefactoring.com/AddForeignKey.html • http://www.ssw.com.au/ssw/SQLAuditor/UserguideWizards.aspx • http://www.cs.usfca.edu/~parrt/course/601/lectures/db.html • http://www.teachict.com/as_a2_ict_new/ocr/AS_G061/315_database_concepts/ter minology/miniweb/pg13.htm • http://www.sparxsystems.com/enterprise_architect_user_guide/9. 0/database_engineering/create_a_foreign_key.html