Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
AIM
To implement INTEGRITY CONSTRAINTS using SQL.
SYNTAX
create table <table name> (column 1 datatype 1 not null,
……., column n datatype n);
EXPLANATION
EXAMPLE
SQL> create table ace (VT number not null, name varchar (10));
2. CHECK CONSTRAINT
SYNTAX:
alter table <table name> add constraint constraint_name check<condition>;
EXPLANATION
EXAMPLE
SQL> alter table ace add constraint RX check (VT between 4100 and 4200);
II. ENTITY INTEGRITY CONSTRAINTS
1. UNIQUE CONSTRAINT
SYNTAX
alter table <table name> add/modify constraint constraint_name
unique (column name);
EXPLANATION
EXAMPLE
SYNTAX
alter table <table name> add/modify constraint constraint_name
primary key (column name);
EXPLANATION
A primary key is one or more column in a table which identifies each row
in the table uniquely. The constraint does not allow null values and
duplicate values in columns.
EXAMPLE
SQL> alter table ace add constraint accue primary key (VT);
III. REFERENTIAL INTEGRITY CONSTRAINTS
1. REFERENCE COMMAND
SYNTAX
create table <table name> (column 1 datatype 1 references
<table name> (column name),……., column n datatype n);
EXPLANATION
EXAMPLE
SQL> create table semnr (VT number references ace (VT), subject varchar (10));
2. FOREIGN KEY
SYNTAX
create table <table name> (column 1 datatype 1,……., column n datatype n
foreign key (column name) references <table name> (column name));
EXPLANATION
EXAMPLE
SQL> create table wise (roll number, iq int, foreign key (roll) references ace(VT));