What are various constraints used in SQL?

  • NULL
  • NOT NULL
  • CHECK
  • DEFAULT

Showing Answers 1 - 25 of 25 Answers

pallavi

  • Aug 24th, 2005
 

There are five classes of constraints: 
 
NOT NULL. Specifies that a column does not accept nulls.  
PRIMARY KEY. Specifies the column or columns whose values uniquely identify a row in a table. Primary key columns are automatically NOT NULL. 
UNIQUE. Specifies that a column has all unique values. 
CHECK. Limits the domain of acceptable values for a column. 
 
FOREIGN KEY. Aka a DRI constraint (Declarative Relational Integrity). Identifies relationships between tables. A foreign key in a table points to a candidate key (usu. a primary key) in another table. A table can have up to 253 FOREIGN KEY contraints

Jo

  • Sep 7th, 2005
 

NOT NULL is a check constraint

  Was this answer useful?  Yes

Durga Prasad

  • Sep 14th, 2005
 

UNIQUE

PRIMARY KEY/FOREIGN KEY

REFERENTIAL INTEGRITY

NULL

NOT NULL

CHECK

DEFAULT

V. Ramalingam

  • Sep 30th, 2005
 

Primary Constraint

  Was this answer useful?  Yes

anil

  • Oct 4th, 2005
 

 Primary constraints,foreign constrains,not null constraint

  Was this answer useful?  Yes

annathurai

  • Oct 15th, 2005
 

constraints

   there are two type of constraints

1) table level

2)column level

integrity constraints

primary key

foreign key

not null

check

default

unique

Suresh

  • Oct 31st, 2006
 

Primary Key

Foreign Key

Unique

Not Null

Check

Two types of constraints -Table level and Column level.

Except Not null all others can be defined as Both table and column level. But Not null as only column level.

There are basically 5 types of constraints that are used in creating and managing tables in SQL

1) Not Null: This doesn't accept null values.. in other words when u declare a column as not null then its mandatory to enter a value for that column without leaving it blank 

eg:  create table emp(empno int not null)

The above example will create a table emp with field empno with not null constraint

2) Unique: This uniquely identifies every row in the table... it restricts the entry of duplicate values in the table

eg : Create table emp(ename varchar2(20), empno int unique)

In the example when u try to enter a empno which is already existing it will not accept

3) Primary Key: it is also known as not null key... this uniquely identifies each row in the table. observe this example

create table emp ( empno int not null unique)

Here we created a table emp with a field empno as not null and unique.  Instead of using both not null and unique constraints simply declare the field as "PRIMARY KEY" wch satisfies both constraint conditions

create table emp(empno int primary key)

Therefore a primary key is not null and a unique key

4) Foreign key/Referencial Intergrity: This establishes a relationship between the parent table and child table.. this is very helpful in retreiving the data from more than 1 tables by providing a link between them.

5) Check Constraint: This defines a condition that each row must satisfy

eg:  create table emp(
empno int primary key,
ename varchar(10),
deptno number(10),                                   
salary number(10),
constraint emp_min_sal check (salary>0));

In the above example we have provided a check condition that the salary you enter must be greater than 0..

  Was this answer useful?  Yes

Amarjeet

  • Jul 7th, 2017
 

NOT NULL

  Was this answer useful?  Yes

ASISH PATRO

  • Jan 8th, 2018
 

Constraints are divided into two part
field level
Default
check
not null
column level
unique
primary
foreign

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions