INTRODUCTION TO DATABASE Contd.
Hello All...
welcome every one. I'm going to start PHP lectures for Very Beginners, who
wants to learn PHP from very beginning. No matter if you do not have any basic
programming concept. If you follow my tutorials I hope you will surely get some
how good knowledge of PHP.
Today our
Topic is
DATABASE- SQL CONSTRAINTS
A constraint is simply a rule, or condition that is applied
on a column or multiple columns in a table. Following are some of the important
constraint that are briefly discussed.
ð Null Constraint: By
default a column contains NULL values. Null means empty or nothing. Whenever
there is Null constraint in a column means that column can hold no value or
that column can be left empty.
ð Not Null Constraint: Not null
constraint forces a column not to left empty cell or no any column can have 0
value. Any column with Not Null constraint must contain a value.
ð Unique Constraint (UC): This
constraint enforces that no two rows can have same value in a specified column.
Each value that is filled in a rows must be unique.
ð Primary Key Constraint (PK): More
similar to Unique constraint but unique constraint can be applied on multiple
columns but Primary key constraint can only be applied on a single column
within a table. Primary key cannot contain null values, cannot hold same values.
PK uniquely identifies a record and its best approach to have Primary Key in
each table so that record can easily be fetched.
ð Default Constraint (DC): Default
value is specified when w user does not enter any value within a column then Default
value should be saved by using Default clause.
ð Foreign Key Constraint (FK): Foreign
key is formed when we have a relationship between two tables via a single
common column and that common column is usually the Primary Key of one table and
that same column is the Foreign Key in other table. Let suppose we have two
table of Teachers and Departments and each record of teacher and department is
differentiated by Primary Key in each table. What could be the relation between
these two that if we want to display those teachers who are in the same
department then surely we have relationship between these two tables. In order
to get those teachers we will have a column as Primary Key in Department Table
and Foreign Key in Teachers table.
How will you apply these constraints to the columns will be
told in next lecture for now I think you all got the concept about `Database
Constraints`.
Thanks Guys.
Any thing missing or any question from this topic you can comment below, I will
be trying to solve and answer your question.
Our topic
continues to `Database`
Good Luck J
No comments:
Post a Comment