Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to realize three basic Relational Operations in Relational Database system

2025-04-02 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly introduces how to realize the three basic relational operations in the relational database system, which can be used for reference by friends who need it. I hope you will learn a lot after reading this article. Next, let the editor take you to learn about it.

The three basic relational operations that can be realized by a relational database management system are selection (the operation of finding tuples that meet a given condition from a relationship is called selection), projection (specifying several attributes from a relational schema to form a new relationship), and join (is a horizontal combination of relationships).

Choice

Use comparison operators and logical operators to pick out tuples that meet the conditions and work out the results!

(recommended study: MySQL video tutorial)

Examples

Find out the names of employees whose salary is more than 2000.

SELECT ename FROM emp WHERE sal > 2000

Process: first query all the results of the emp table, use the selection operation to filter out the results of the salary greater than 2000, and finally use the projection operation to get the names of the employees whose salary is greater than 2000!

Projection

Recommended course: MySQL tutorial.

The operation process of projection:

First of all, according to J1 ~ J2, … , in the order of jk, the column sequence number is j1jj2, which is taken from relation R. , jk (or the attribute name is listed as Aj1,Aj2, … , Ajk), and then remove the repeated tuples in the result to form an Aj1,Aj2,... Ajk is the k-item relation in the order of attributes.

To put it simply: take a so-and-so column in a query result and eliminate duplicate data, this is projection!

Projection is an operation from the point of view of a column

The subscript of the projection is not only a column number, but also a column attribute name.

Examples

Find out the numbers of all departments.

SELECT deptno FROM dept

Query process: first query all the results of the dept table, and then extract only the column data of "deptno" through the projection operation. If the SELECT is followed by "*", then all the data is projected!

Join operation

In fact, the join operation is based on the Cartesian product operation to limit the conditions (a column is greater than, less than, or equal to a column), only match with the conditions, so as to get the result!

Natural connection

Natural join is a special join operation, which is defined by the condition that a column is equal to a column. The natural connection we often use. Eliminating Cartesian product is actually a natural connection!

Examples

SELECT * FROM emp,dept WHERE dept.deptno = emp.deptno

Set the deptno column of the dept table to be the same as the deptno column of emp [this is the natural join]

Thank you for reading this article carefully. I hope it will be helpful for everyone to share the three basic relational operations of the relational database system. At the same time, I also hope that you will support more, pay attention to the industry information channel, and find out if you encounter problems. Detailed solutions are waiting for you to learn!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report