Online Learning Platform

DBMS > Relational Algebra > What is relational Algebra?

Relational algebra

Relational algebra are formal languages associated with the relational model.  In this language, different operations on the database relations are expressed using symbols.

  • Actually, relational algebra is a (high-level) procedural query language. It gives a step by step process to obtain the result of the query.
  • Relational algebra operations work on one or more relations to define another relation without changing the original relations.
  • Both operands and results are relations, so output from one operation can become input to another operation.

 

Types of Relational operation

 

Let we have the following two relations: emp and dept:

Emp Table:

Dept Table:

 

The following are the codes to create the tables. Note that these codes (written for MySQL) are called Structural Query Language: Data Definition Language (SQL: DDL). We will use these tables to provide example:

create table dept(

    deptno int primary key,

    dname varchar(30),

    loc varchar(20)

    );

insert into dept values(10, 'Head Office','Dhaka');

insert into dept values(20, 'Account','Dhaka');

insert into dept values(30, 'Transport','Dhaka');

insert into dept values(40, 'Marketing','Dhaka');

 

CREATE TABLE emp (

  empno    int,

  ename    VARCHAR(10),

  job      VARCHAR(9),

  mgr      int,

  hiredate DATE,

  sal      decimal(7,2),

  comm     decimal(7,2),

  deptno   int,

  PRIMARY KEY (empno),

  FOREIGN KEY (deptno) REFERENCES dept (deptno)

);

INSERT INTO emp VALUES

(7839, 'KING', 'PRESIDENT', null, '17-11-1981', 5000, null, 10 ),

(7698, 'BLAKE', 'MANAGER', 7839, '1-5-1981', 2850, null, 30),

(7782, 'CLARK', 'MANAGER', 7839, '9-6-1981', 2450, null, 10),

(7566, 'JONES', 'MANAGER', 7839, '2-4-1981', 2975, null, 20),

(7788, 'SCOTT', 'ANALYST', 7566, '13-JUL-87', 3000, null, 20),

(7902, 'FORD', 'ANALYST', 7566, '3-12-1981', 3000, null, 20 ),

(7369, 'SMITH', 'CLERK', 7902, '17-12-1980', 800, null, 20 ),

(7499, 'ALLEN', 'SALESMAN', 7698, '20-2-1981', 1600, 300, 30),

(7521, 'WARD', 'SALESMAN', 7698, '22-2-1981', 1250, 500, 30 ),

(7654, 'MARTIN', 'SALESMAN', 7698, '28-9-1981', 1250, 1400, 30 ),

(7844, 'TURNER', 'SALESMAN', 7698, '8-9-1981', 1500, 0, 30),

(7876, 'ADAMS', 'CLERK', 7788, '13-JUL-87',1100, null, 20 ),

(7900, 'JAMES', 'CLERK', 7698, '3-12-1981', 950, null, 30 );

 

No More

No More

Feedback
ABOUT

Statlearner


Statlearner STUDY

Statlearner