数据库中元组关系演算
Tuple Relational Calculus is a non-procedural and declarative query language. The declarative query procedure gives logical condition which is required to be satisfied by the results. In the non-procedural query language, the user always tries to find out the details of how to get the results. Tuple Relational Calculus explains what to do by describing query but not explain how to do by does not provide the methods to solve.
元组关系演算是一种非过程性和声明性查询语言。 声明性查询过程给出了结果必须满足的逻辑条件。 在非过程查询语言中,用户始终尝试查找如何获取结果的详细信息。 元组关系演算通过描述查询来解释做什么,但没有解释如何做则没有提供解决方法。
Tuple Relational Calculus in a relation is specified in the selection of tuples with details. In relation, the tuples are used by filtering variables. The result which comes out as a resultant relation can have one or more than one tuples in a resultant relation. It is easy to use by someday who is not a skilled person also. Tuple variable which integrated with a relation is called the range relation.
在选择具有详细信息的元组时,指定了关系中的元组关系演算 。 相对地,元组通过过滤变量来使用。 作为结果关系得出的结果在结果关系中可以具有一个或多个元组。 也有一天不是技术人员也容易使用。 与关系集成的元组变量称为范围关系。
In Tuple Calculus, the notation of a query is:
在Tuple Calculus中,查询的符号为:
{T | P (T)} or {T | Condition (T)}
Where,
哪里,
T = resulting tuples,
T =结果元组,
P(T) = called as Predicate and It is a condition which is used to fetch T.
P(T) =称为谓词,它是用于获取T的条件 。
Example
例
Table 1: Engineer
表1:工程师
Engineer Name | Address | City |
---|---|---|
Raghav | A23/B6 | Mumbai |
Sameer | 567/453 | Delhi |
Sujata | 543/27 | Kanpur |
Shivani | D35 | Jaipur |
Amar | B82/78 | Kolkata |
工程师姓名 | 地址 | 市 |
---|---|---|
拉加夫 | A23 / B6 | 孟买 |
沙美尔 | 567/453 | 新德里 |
Sujata | 543/27 | 坎普尔 |
西瓦尼 | D35 | 斋浦尔 |
阿玛 | B82 / 78 | 加尔各答 |
Table 2: Company
表2:公司
Company | City |
---|---|
Wipro | Chennai |
Accenture | Delhi |
Infosys | Bangalore |
公司 | 市 |
---|---|
威普罗 | 钦奈 |
埃森哲 | 新德里 |
信息系统 | 班加罗尔 |
Table 3: Salary
表3:薪金
Engineer Name | Company | Salary |
---|---|---|
Raghav | Wipro | 24,000 |
Sameer | Infosys | 23,000 |
Sujata | Accenture | 25,000 |
Shivani | Wipro | 27,000 |
Amar | Accenture | 30,000 |
工程师姓名 | 公司 | 薪水 |
---|---|---|
拉加夫 | 威普罗 | 24,000 |
沙美尔 | 信息系统 | 23,000 |
Sujata | 埃森哲 | 25,000 |
西瓦尼 | 威普罗 | 27,000 |
阿玛 | 埃森哲 | 30,000 |
Table 4: Incentive + Bonus
表4:奖励+奖金
Company | Incentive + Bonus |
---|---|
Wipro | 4,000 |
Accenture | 5,000 |
Infosys | 7,000 |
公司 | 激励+奖金 |
---|---|
威普罗 | 4,000 |
埃森哲 | 5,000 |
信息系统 | 7,000 |
Table 5: Salary (Included Incentive + Bonus)
表5:薪金(包括奖励+奖金)
Engineer Name | Company | Salary |
---|---|---|
Raghav | Wipro | 28,000 |
Sameer | Infosys | 30,000 |
Sujata | Accenture | 30,000 |
Shivani | Wipro | 31,000 |
Amar | Accenture | 35,000 |
工程师姓名 | 公司 | 薪水 |
---|---|---|
拉加夫 | 威普罗 | 28,000 |
沙美尔 | 信息系统 | 30,000 |
Sujata | 埃森哲 | 30,000 |
西瓦尼 | 威普罗 | 31,000 |
阿玛 | 埃森哲 | 35,000 |
Query 1: Find the Engineer Name, Company and Salary of those whose salaries are greater than 23,000 excluded Incentive + Bonus.
查询1:找到薪金高于23,000(不含激励和奖金)的工程师的姓名,公司和薪水。
{T| T ∈ Engineer ∧ T [Salary]>= 23,000}
The Resultant relation is:
结果关系为:
Engineer Name | Company | Salary |
---|---|---|
Raghav | Wipro | 24,000 |
Sujata | Accenture | 25,000 |
Shivani | Wipro | 27,000 |
Amar | Accenture | 30,000 |
工程师姓名 | 公司 | 薪水 |
---|---|---|
拉加夫 | 威普罗 | 24,000 |
Sujata | 埃森哲 | 25,000 |
西瓦尼 | 威普罗 | 27,000 |
阿玛 | 埃森哲 | 30,000 |
In the above query, The T [Salary] is called as Tuple variable.
在上面的查询中,T [Salary]被称为Tuple变量。
Query 2: Find the Engineer Name of all the Company whose salaries are less than 27,000 excluded Incentive + Bonus.
查询2:查找所有薪水少于27,000(不含激励和奖金)的公司的工程师名称。
{T| ∃ S ∈ Engineer ( T[Company] = S[Company]
∧ S [Salary]< 27,000)}
The Resultant relation is:
结果关系为:
Engineer Name |
---|
Raghav |
Sameer |
Sujata |
工程师姓名 |
---|
拉加夫 |
沙美尔 |
Sujata |
Query 3: Find the Engineer Name of those who works in Accenture and their cities are Kanpur and Kolkata.
问题3:找到在埃森哲工作的工程师的名字,他们的城市是坎普尔和加尔各答。
{T| ∃ S ∈ Engineer (T [Engineer Name]) = S[Engineer Name])
∧∃ U ∈ Salary (T [Engineer Name] = U [Engineer Name])}
The Resultant relation is:
结果关系为:
Engineer Name |
---|
Sujata |
Amar |
工程师姓名 |
---|
Sujata |
阿玛 |
Query 4: Find the Engineer Name of those whose salaries included incentive + Bonus is "30,000" and their cities are Delhi and Kanpur.
查询4:找到薪金中包含奖励+奖金为“ 30,000”且其城市为德里和坎普尔的工程师的姓名。
{T | ∃ S ∈ Engineer (T [City] = S[City]
∧ ∃ U ∈ Salary(Included Incentive + Bonus)(U[Salary] = "30,000"
∧ U[Engineer Name] = S[Engineer Name] ) ) }
The Resultant relation is:
结果关系为:
Engineer Name |
---|
Sameer |
Sujata |
工程师姓名 |
---|
沙美尔 |
Sujata |
翻译自: https://www.includehelp.com/dbms/tuple-relational-calculus.aspx
数据库中元组关系演算