View on GitHub

ra_console

Implementation of Relational Algebra functions

Implementation of Relational Algebra functions


Aim of the Project

To write a program in C++ to implement Relational Algebra functions present in DBMS.


Functions implemented

The program implements the following Relational Algebra functions:

  1. SELECT

  2. PROJECT

  3. RENAME

  4. UNION

  5. SET DIFFERENCE

  6. CARTESIAN PRODUCT


Project Details

The program assumes the following:


Syntax

The basic syntax of the queries is as follows:

Show tables in database as specified in db_info.txt:

SHOW_TABLES;

SELECT:

SEL{predicate}(table_name);

PROJECT:

PRO{column_name1:column_name2}(table_name);

RENAME:

REN{new_table_name|column_name1:column_name2}(table_name);

UNION:

UNI(table_name1, table_name2);

SET DIFFERENCE:

DIF(table_name1, table_name2);

CARTESIAN PRODUCT:

CRP(table_name1, table_name2);

EXIT:

EXIT;

The predicate syntax for SEL:

SEL{(a > b | c = d) & e ! f}(table_name);

The available operators are:

  1. + : Add two ints or floats
  2. - : Subtract two ints or floats
  3. ____ : Multiply two *ints or floats
  4. / : Divide two ints or floats
  5. = : Compare two operands, TRUE if equal
  6. ! : Compare two operands, TRUE if unequal
  7. > : Compare two operands, TRUE if former is greater than latter
  8. < : Compare two operands, TRUE if former is lesser than latter
  9. & : Logical AND
  10. ** ** : Logical OR

NOTES:

The predicate syntax for PRO:

PRO{a:b:c:d}(table_name);

NOTES:

The predicate syntax for REN:

REN{new_table_name|a:b:c:d}(table_name);
REN{new_table_name}(table_name);

NOTES:


Sample Queries

1. SEL{faculty.salary > 80000 & dept = 'CSE'}(faculty);
2. PRO{id:name:grade}(studuent);
3. UNI(PRO{name}(faculty), PRO{name}(student));
4. DIF(PRO{name}(faculty), PRO{name}(student));
5. CRP(student, course);
6. REN{stud|stud_id:name:cgpa}(student);

For more queries, see Query file


Comments: