The Select, Project & Rename Operation​ in Relational Algebra


The Select Operation​

  • The select operation select tuples that satisfy a given predicate.​
  • The small Greek letter sigma(σ) is use to denote select operation​
  • The predicate appears as a subscript to σ​
  • The Comparison operator =,≠,<,>,≤,≥​
  • The Connectives and(∧ ), or( v), not(¬)​

  



Examples

  • To Select the tuples from employee relations those employees belong to CSE Department
    • σdept_name='CSE'(employees)
  • The employees whose salary greater than 12000/-​
    •  Ļƒemp_salary>12000(employees)
  • Department is CSE and Salary is greater than 12000/- ​
    • σdept_name='CSE' ∧ emp_salary>12000(employees)


Project Operation

  • It is Unary operation​
  • It selects certain columns from a table while discarding others. ​
  • It removes any duplicated rows from the result relation.​
  • Denoted by the uppercase Greek letter pi (Ī )​
  • The attribute list appears in the subscript to  Ī   with argument relation in parentheses. ​

Examples:

  • Ī Id,name,dept,salary(employees)
    • Selects only id, name, dept_salary Form employees relation.​
  • Ī title,Author(Book)
    • Display all title and author from book relation

Composition of Relation Operations
  • The relational-algebra operations can be composed together into a relational-algebra expression it is just like composing arithmetic operations into athematic expression. ​
  • Example​
    • Ī name(σdept_name='CSE'(employees))


Rename Operation


  • In Relational algebra, we can rename either the relation or the attributes or both.​
  • It is denoted by lowercase Greek letter rho (ρ)​
    • ρs(new attribute name)(R)
    • ρs(R)
    • ρ(new attribute name)(R)

Examples:

  • ρt1(fn,ln,sal)(R)
    • Rename relation R with new relation t1 with  new name for the listed attributes ​
  • ρ(fn,ln,sal)(R)
    • Rename only attributes listed in the brackets.​
  • ρt1(R)
    • Rename only relation R with new name t1.​

Relational Algebra

RelationalĀ Algebra

  • Relational Algebra is is a procedural query language​
  • The relational algebra provides a set of operations that take one or more relations as input and return a relation as an output.​
  •  Practical query languages such as SQL are based on the relational algebra.​
  • The fundamental operations are ​
    • Select, Project, Union, Set Difference, Cartesian Product and Rename.​
  • Additional to the fundamental operations are​
    • Intersection, join and assignment.​
  • he select, project and rename operations are called unary operations because they operate on one relation.​
  • The other operation which operate on pair of relations and are called binary operations.​
  • A basic expression in the relational algebra consists of either one of the following: ​
  •  A relation in the database ​
    •  A constant relation
    • A constant relation is written by listing its tuples within { }, ​
      •  Example { (22222, Einstein, Physics, 95000), (76543, Singh, Finance, 80000) }.​

Java Database Connectivity with MySQL


To connect Java application with the MySQL database, we need to follow 5 following steps.

In this example we are using MySQL as the database. So we need to know following information for the MySQL database:

Driver class: The driver class for the MySQL database is com.mysql.cj.jdbc.Driver.

Connection URL: The connection URL for the MySQL database is jdbc:mysql://localhost:3306/dbname where jdbc is the API, mysql is the database management system, localhost is the server name on which mysql is running, we may also use IP address, 3306 is the port number and dbname is the database name. We may use any database, in such case, we need to replace the dbname with your database name.

Username: The default username for the MySQL database is root.

Password: It is the password given by the user at the time of installing the mysql database. In this example, we are going to use root as the password.

Let's first create a table in the mysql database, 

create database dbname;

use dbname;

create table students(stu_id int,stu_name varchar(100));


Sample Java Code : MyDBExample.java

import java.sql.*;  
class MyDBExample{  
public static void main(String args[]){  
try{  
Class.forName("com.mysql.jdbc.Driver");  
Connection con=DriverManager.getConnection("jdbc:mysql://localhost:3306/dbname","root","root");  
//here dbname is database name, root is username and password  
Statement stmt=con.createStatement();  
ResultSet rs=stmt.executeQuery("select * from students");  
while(rs.next())  
System.out.println(rs.getInt(1)+"  "+rs.getString(2));  
con.close();  
}catch(Exception e){ System.out.println(e);}  
}  
}  


To connect java application with the MySQL database, mysql-connector-j-x.x.xx.jar file is required to be loaded.


Select operating system : Platform Independent  and download zip file and extract in c/d/e.. drive. Here I am demonstrating extraction in c drive. 





Two ways to load the jar file:

  1. Paste the mysqlconnector.jar file in jre/lib/ext folder
  2. Set classpath
1) Paste the mysql-connector-j-x.x.xx.jar file in JRE/lib/ext folder:
Download the mysql-connector-j-x.x.xx.jar file. Go to jre/lib/ext folder and paste the jar file here.


2) Set classpath:
There are two ways to set the CLASSPATH:
  1. Temporary
  2. Permanent
How to set the temporary CLASSPATH
open command prompt and write:  set CLASSPATH=c:\folder\mysql-connector-j-x.x.xx.jar;.;  

How to set the permanent CLASSPATH
Go to environment variable then click on new tab.


In variable name write CLASSPATH and in variable value paste the path to the mysql-connector-j-x.x.xx.jar file by appending ;.; as c:\folder\mysql-connector-j-x.x.xx.jar;.;


Here . indicates the current directory where your class files creates after compilation of java program. 




What is an aptitude?


What are aptitudes? Aptitudes are an individual's inherent talents and abilities for learning or doing certain things in different areas. For example, a person's ability to carry a tune is considered an aptitude. Most people have several related talents, such as singing, reading music, and playing a musical instrument


Aptitude is the innate or acquired capacity for something. Aptitudes can range from developed knowledge, learned or acquired abilities (otherwise known as skills), talents, or attitudes necessary to perform a task. In essence, aptitudes are traits that help us accomplish tasks.










What is Value Education?

What is Value Education?

The part of education that deal with the understanding of one's participation in the larger order, and thus ensuring it in living, is called as Value Education.

The value of a human being is its natural or expected participation in the larger order - at the level of the individual, at the level of family, at the level of society and ultimately, at the level of nature/existence.

It is interesting to note that you feel happy in the process of fulfilling your participation in the larger order.