What is the Difference Between a Relation and a Function

The main difference between a relation and a function is that a relation is a table in a relational database while a function is a set of statements to perform a specific task in a program.

A table in a relational database system is called a relation. The user can design multiple tables or relations in a single database. He can perform normalization on the tables to minimize data redundancy. Furthermore, he can use SQL to retrieve and manipulate data in these relations. In contrast, a function is a group of statements that perform a task in a program. There can be one or more functions in a single program.

Key Areas Covered

1. What is a Relation
     – Definition, Operation
2. What is a Function
     – Definition, Operation
3. What is the Difference Between a Relation and a Function
     – Comparison of Key Differences

Key Terms

Function, Relation, Relational Database, SQL

Difference Between a Relation and a Function- Comparison Summary

What is a Relation

A database is a collection of related data that helps to organize data. DBMS (Database Management System) is a software that allows managing and retrieving data in the databases easily. A database model describes the logical design and structure of a database. Moreover, it defines how to store, access and update data in a DBMS. The most common database model is a relational model which was introduced by E.F. Codd introduced in the year 1970.

Difference Between a Relation and a Function

Figure 1: Relational Model

A DBMS that uses the relational model is a Relational DBMS. The databases in RDBMS are relational databases. They store data in tables. These tables are connected to each other, and each table has rows and columns. A row or a tuple represents a record while a column represents an attribute. In a sales database of a company, the customer table has columns such as customer_name, contact_number, city and email. Each record of the customer is a row. This table is a relation. Likewise, a table in a relational database is a relation.

What is a Function

A function is a set of statements to perform a certain task. It is also called a procedure or method. A programmer can divide the main program into multiple functions and call them as required. And, this makes the program more manageable.

Furthermore, it improves code reusability. Every function has a name to identify it. However, multiple functions cannot have the same name. A function can accept no parameters or multiple parameters. It, according to the returning value, has a return type. If it does not return any value, then the return type is void.

Refer below program.

Main Difference - a Relation avnd a Function

Figure 2: Function

In the main program, there is a Scanner object. In line 10 and 11, the user can give values to num1 and num2 variables. These values are passed to the maximum function. It finds the maximum number between the two numbers and returns the maximum value. In the main program, the variable result stores the returned value of the function. Finally, the results are printed on the screen. The output is visible on the left side of the program. The user enters the values 50 and 40, and the maximum value 50 displays on the console.

Difference Between a Relation and a Function

Definition

A relation refers to a table in a relational database. In contrast, a function is a unit of code that is often defined by its role within a greater code structure. Hence, these definitions describe the main difference between a relation and a function.

Usage

Another difference between a relation and a function is that the relations help to store data in the relational database in an organized manner while the functions help to make the program maintainable and readable.

Conclusion

Relation and function are two concepts in a relational database system. The main difference between a relation and a function is that a relation is a table in a relational database while a function is a set of statements to perform a specific task in a program.

Reference:

1. “DBMS Database Models.” Database Models in DBMS | Studytonight, Available here.

Image Courtesy:

1. “Rel model” By Tsedenjav.Sh – Own work (CC BY-SA 4.0) via Commons Wikimedia

About the Author: Lithmee

Lithmee holds a Bachelor of Science degree in Computer Systems Engineering and is reading for her Master’s degree in Computer Science. She is passionate about sharing her knowldge in the areas of programming, data science, and computer systems.

Leave a Reply