關系代數基本運算
Definition
定義
Every DBMS must define a query language to enable users to access the data which is stored in the database. Relational Algebra is a procedural query language. It is used to query the database tables in order to access data in several ways. In this algebra, the input is a relation and output is also a relation. Operators are used to performing queries. It can be either unary or binary operator.
每個DBMS必須定義一種查詢語言,以使用戶能夠訪問存儲在數據庫中的數據。 關系代數是一種過程查詢語言。 它用于查詢數據庫表,以便以多種方式訪問??數據。 在這個代數中,輸入是一個關系,輸出也是一個關系。 運算符用于執行查詢。 它可以是一元或二進制運算符。
Basic Operations
基本操作
SELECT (unary)
SELECT(一元)
PROJECT (unary)
項目(一元)
UNION (binary)
UNION(二進制)
SET DIFFERENCE (binary)
設置差異(二進制)
CARTESIAN PRODUCT (binary)
笛卡爾積(二進制)
RENAME (unary)
重命名(一元)
Other Operations
其他作業
SET INTERSECTION
設置相交
NATURAL JOIN
自然加入
DIVISION
師
ASSIGNMENT
分配
1)選擇運算(σ) (1) Select Operation (σ))
This is used to get rows (tuples) from the table (relation) which fulfill a given condition.
這用于從滿足給定條件的表(關系)中獲取行(元組)。
Syntax: σp(r)
語法: σp(r)
Where σ is used for the Select Predicate, r is the name of relation or table, and p is used as the propositional logic, where we give the conditions that must be fulfilled by the data. In this, unary and binary operators like =, etc., to mention the condition can be used.
其中σ用于Select謂詞,r是關系或表的名稱,而p用作命題邏輯,在此我們給出數據必須滿足的條件。 在這種情況下,可以使用一元和二進制運算符(例如=等)來提及條件。
Example: Student table and get data for students with age more than 20.
示例: Student表并獲取20歲以上學生的數據。
σage> 20 (Student)
年齡> 20(學生)
2)項目運營(∏) (2) Project Operation (∏))
Project operation is used to project or show only a desired set of attributes of a relation. In other words, if we wish to see only the names all of the students in the Student table, then the project operation can be used. It will only project the columns or attributes chosen and will delete duplicate data from the columns.
項目操作用于計劃或僅顯示關系的所需屬性集。 換句話說,如果我們希望僅在“學生”表中看到所有學生的姓名,則可以使用項目操作。 它只會投影選定的列或屬性,并且將從列中刪除重復的數據。
Syntax: ∏A1, A2...(r)
語法: ∏A1,A2 ...(r)
Here A1, A2 etc. are attribute names (name of columns).
在此,A1,A2等是屬性名稱(列名)。
Example:
例:
∏Name, Age(Student)
∏姓名,年齡(學生)
3)聯合行動(∪) (3) Union Operation (∪))
This is used to fetch data from two (relations)tables or temporary relations (the result of other operation).
這用于從兩個(關系)表或臨時關系(其他操作的結果)中獲取數據。
For union operation to work, the condition is that the relations(tables) taken should have an equal number of attributes(columns) and equal attribute domain. Even the duplicate tuples are automatically removed from the result.
為了使聯合操作起作用,條件是所采用的關系(表)應具有相等數量的屬性(列)和相等的屬性域。 即使重復的元組也會自動從結果中刪除。
Syntax: P ∪ Q
語法: P∪Q
Where P and Q are relations.
其中P和Q是關系。
Example: if we have two tables Regular class and Extra class, both have an attribute student to save the name of the student, then,
示例:如果我們有兩個表常規班級和額外班級,它們都具有屬性student來保存學生的姓名,那么,
∏Student(Regular class) ∪ ∏Student(Extra class)
∏學生(普通班)∪學生(普通班)
4)設置差異(-) (4) Set Difference (-))
This operation is used to find data which present in one relation but not present in the other relation. This operation can be applied to two relations, just like the Union operation.
此操作用于查找以一種關系存在但不以另一種關系存在的數據。 就像聯合操作一樣,此操作可以應用于兩個關系。
Syntax: P - Q
語法: P-Q
Where P and Q are relations.
其中P和Q是關系。
Example: if we want to find the name of students who take the regular class but miss the extra class, then, the below operation can be used as:
示例:如果我們想查找參加普通班但錯過額外班級的學生的姓名,則可以將以下操作用作:
∏Student(Regularclass) - ∏Student(Extraclass)
∏學生(普通班)-∏學生(額外班)
5)笛卡爾積(X) (5) Cartesian Product (X))
This operation is used to combine data of two separate relations into single and fetch data from the combined result relation.
此操作用于將兩個單獨關系的數據合并為單個數據,并從合并結果關系中獲取數據。
Syntax: A X B
語法: AXB
Example: to find the information for Regular Class and Extra Class which are conducted in the morning, then, the following operation can be used:
示例:要查找早晨進行的常規班和額外班的信息,則可以使用以下操作:
σtime = 'morning' (Regularclass X Extraclass)
σtime='早晨'(常規類X附加類)
6)重命名操作(ρ) (6) Rename Operation (ρ))
Rename operation is used to change the name or rename the output relation for any query operation which returns or gives the result like Select, Project etc. Or in simple words to rename a relation(table).
重命名操作用于為返回或給出諸如Select,Project等結果的任何查詢操作更改名稱或重命名輸出關系。或者用簡單的語言重命名關系(表)。
Syntax: ρ(Relationnew, Relationold)
語法: ρ(Relationnew,Relationold)
翻譯自: https://www.includehelp.com/dbms/basic-and-additional-operations-of-relational-algebra.aspx
關系代數基本運算