You are on page 1of 3

joining :

when we want to join more than one taqble to establish relationship between
them then it is called as joining .
if we want to join n number of tables then we must require n-1 number of codition .
there are 5 types of joining available in sql.
1.equal /inner/natural join
: when we want to join more than one tables having a common fields in all the
tavles then it is called as equal join .
there are 5 processes to solve equal join.
a.using theta process:
select emp ,eneame,dept,,dname from emp ,dept where
emp.deptno=dept.depno;
b.using ansi process:
select e.ename,d.dname from emp,dept d where e.deptno=d.deptno;
c.using natural join:

select sname,dname from emp natural join dept;


d.using inner join and on clause:
select e.ename,d,dname from emp e inner join dept d
on(e.deptno=d.deptno);
e.using inner join and using clause :
select ename,dname from emp inner join dept using (deptno);

2.cross join:/(cartesian product in math:)


when we want to process the result form differt differ=ent tavles
findiing maximum probability values then it is called cross join .
slect ename,dname from emp corss join dept;
select ename,dname from emp.dept;
3.outer join :
it is used to fetch the matched data along with unamtched /extra
data from the databas tables.
there are 3 types of outer join available in dbms.
left join:
when we want tp fetch matched data from all the tables
along with unmatched data from left side table only then it is called as left outer
join.
-->select ename,dname from emp left outer join dept using using
(deptno);
b.right outer join:
it is used to fetch the matched data along with unamtched /extra data from
the databas tables.
there are 3 types of outer join available in dbms.
left join:
when we want tp fetch matched data from all the tables
along with unmatched data from right side table only then it is called as right
outer join.
-->select ename,dname from emp right outer join dept using using
(deptno);
c.full outer join:
it is used to fetch the matched data along with
unamtched /extra data from the databas tables.
there are 3 types of outer join available in dbms.
left join:
when we want tp fetch matched data from all the tables
along with unmatched data from both the table only then it is called as full outer
join.
-->select ename,dname from emp full outer join dept using using
(deptno);
4.non equal join :
when we want to join more than one table ata a time without
using any common field for joining condition then it is called as non equi join.
selec e.ename,w.sal,d.deptno,d.dname from emp e,dept d where
e.sal between 3500 and 5000 and d.deptno=20;

5.self join:

it is possible onlyh for one table .


so when a tab le joins itself then it is called as self join.
selec e.ename,e.sal,d.deptno from empe, where e.sal between 3500
and 5000 and d.deptno=20;

SET OPERATION :
it is divided in to catagories:
1.union
It is used to join the data two tables.
select deptno from emp union select deptno from dept;
2.intersection
It is used to delete the duplicate data from a table.
select deptno from emp intersect select deptno from dept;
3.minus
It is used to delete the duplicate data from a table where there is common data
present inside it.
select deptno from emp minus select deptno from dept;
4.union all
It is used to join the data from both the tables.
select deptno from emp union all select deptno from dept;

constraint:
are the rules applied to the database table to make the data more than accurate.
when there are 5 types of constraint available in sql.
1.unique key constraint

2.NOT NULL constraint


3.primary key constraint
4.foreign key constraint
5.check constraint

A constraint is a rule that is used for optimization purposes.

Constraints can be categorized into five types:

A NOT NULL constraint is a rule that prevents null values from being entered into
one or more columns within a table.

A unique constraint (also referred to as a unique key constraint) is a rule that


forbids duplicate values in one or more columns within a table. Unique and primary
keys are the supported unique constraints. For example, a unique constraint can be
defined on the supplier identifier in the supplier table to ensure that the same
supplier identifier is not given to two suppliers.

A primary key constraint is a column or combination of columns that has the same
properties as a unique constraint. You can use a primary key and foreign key
constraints to define relationships between tables.

A foreign key constraint (also referred to as a referential constraint or a


referential integrity constraint) is a logical rule about values in one or more
columns in one or more tables. For example, a set of tables shares information
about a corporation's suppliers. Occasionally, a supplier's name changes. You can
define a referential constraint that states the ID of the supplier in a table must
match a supplier ID in the supplier information. This constraint prevents insert,
update, or delete operations that would otherwise result in missing supplier
information.

A table check constraint (also called a check constraint) sets restrictions on data
that is added to a specific table. For example, you can use a table check
constraint whenever salary data is added or updated in a table that contains
personnel information. For such operations, the table check constraint can ensure
that the salary level for an employee is at least $20 000.

An informational constraint is an attribute of a certain type of constraint, but


the attribute is not enforced by the database manager.

NOT NULL constraints


NOT NULL constraints prevent null values from being entered into a column.
Unique constraints
Unique constraints ensure that the values in a set of columns are unique and not
null for all rows in the table. The columns specified in a unique constraint must
be defined as NOT NULL. The database manager uses a unique index to enforce the
uniqueness of the key during changes to the columns of the unique constraint.
Primary key constraints
You can use primary key and foreign key constraints to define relationships between
tables.
(Table) Check constraints
A check constraint (also referred to as a table check constraint) is a database
rule that specifies the values allowed in one or more columns of every row of a
table. Specifying check constraints is done through a restricted form of a search
condition.
Foreign key (referential) constraints
Foreign key constraints (also known as referential constraints or referential
integrity constraints) enable definition of required relationships between and
within tables.
Informational constraints
An informational constraint is a constraint attribute that can be used by the SQL
compiler to improve the access to data. Informational constraints are not enforced
by the database manager, and are not used for additional verification of data;
rather, they are used to improve query performance.

You might also like