Professional Documents
Culture Documents
MySql Exercise 1- Create Table
MySql Exercise 1- Create Table
Create Table
Create Database Syntax
CREATE DATABASE database_name;
Create Database
);
Foreign key Constraints
• On DELETE
– Restrict
– No action
– Cascade
– Set null
• On Update
– Restrict
– No action
– Cascade
– Set null
Restrict
• RESTRICT option prevents the removal (i.e.
using delete) or modification (i..e using an
update) of rows from the parent table.
• means that any attempt to delete and/or
update the parent will fail throwing an error.
NO Action
PARENT CHILD
A B X A
a1 b1 X1 a1
a2 b2 X2 a1
X3 a2
• Delete: the referencing rows will be deleted automatically along with the
referenced ones.
• IF WE DELETE row 1(a1) FROM parent it will delete rows 1 and 2 entries from
child.
• Problem need to keep history
• CASCADEif the parent primary key is changed, the child value will also
change to reflect that.
• IF WE Update in row 1(a1) FROM parent it will update rows 1 and 2 entries
from child.
SET NULL
PARENT CHILD
A B X A
a1 b1 X1 a1
a2 b2 X2 a1
X3 a2