Saturday, 19 November 2011


SQL Constraints

Constraints are used to limit or validated type of data that can go into a table.
Constraints: Rules which are enforced on data being entered and prevents the user from entering invalid data into tables are called constraints.

Types of Data constraints:

  • Input/Output constraints (primary key /foreign key): This constraint determines the speed at which data can be inserted or extracted from oracle table
  • Business Rule constraints: These rules are applied to data prior(first) the data being inserted into the table columns.

Defining a constraint

Oracle allows programmers to define constraints at:
  • Table level
  • Column level
1.)Column Level Constraints: A column level constraint references a single column/attribute and is defined along with the definition of column/attribute.
Syntax:
Column DataType(Size) Constraint_Type
2.)Table Level Constraints: If data constraints are defined after defining all the table columns when creating or altering a table structure , it is a table level constraint.
Syntax:
Constraint_Type(Column,.)

Naming a constraint:

Syntax:
<Table name>_<attribute name>_<constraint type>
Ex: emp_deptno_fk refers to a constraint in table EMP on attribute DeptNo of type Foreign Key.
Oracle Server will automatically generate a name for constraint by using a format SYS_Cn, where n is unique number.

We will focus on the following constraints:
  • NOT NULL
  • UNIQUE
  • PRIMARY KEY
  • FOREIGN KEY
  • CHECK
  • DEFAULT

0 comments:

Post a Comment

TrainingHUB. Powered by Blogger.

Total Pageviews

THE BEST QTP TRAINING INSTITUTE IN HYDERABAD

QTP Training in hyderabad

Sql Tutorial

Popular Posts

Our Facebook Page

TrainingHUB

Followers