Constraint : Rules to be forced when ever a user try inserting data into a constraint controlled column.
Types Of Constraints : Primary Key - Foreign Key - Unique - Not Null - Check Constraint
* Primary Key : Guarantees that data inserted by user in this column ( Not Null , Unique )
* Not Null : Value Must Be Inserted , Cannot be blank.
* Unique : value cannot be repeated in 2 rows , if we consider a column called e-mail which have Unique Constraint .. this means that 2 users cannot have the same data in the e-mail field .
* Foreign Key : The relation between Primary Key (PK) and Foreign Key (FK) is : 1 to many .
ex: if user_id column (1) is primary key in the table Employees , this user_id may have data in another table , say Departments .
so , in the Departments table , a Foreign Key must be added to use the User_id Column from Employees .
This Departments table contains data like department_id , department_name (many) .
so this confirms relation is (1) to (many) .
* Check Constraint : It Checks user inserted data to satisfy pre defined condition . and reject the process if the condition is not met .
Create Table My_Employees
(Id Number (4) , Salary Number (6,2) Constraint My_Employees_salary_c Check(Salary>1000) ;
the previous example shows check constraint name "My_Employees_salary_c" and the condition to be applied "Salary>1000"
Missing
15 years ago
weldone,go on
ReplyDeleteThanks Alot Hoss !
ReplyDeleteyour blog is the best :)