Базы данных
Реляционное исчисление
Определения переменных select СписокАтрибутов from Переменные where Условие
select S.SId from S where ∃G (S.GId = G.GId ∧ G.Name = 'M34371')
select SId from S where ∃GId (S{SId=SId, GId=GId} ∧ G{GId=GId, Name = 'M34371'})
Переменная :: Отношение
S :: Students G :: Groups G4 :: Groups where Name = 'M34351' ∨ Name = 'M34371' ∨ Name = 'M34391'
Отношения where Условие
Отношение1, Отношение2
Groups where Name = 'M34371'
G4 :: Groups where Name = 'M34351', Groups where Name = 'M34371', Groups where Name = 'M34391'
S.Name = 'Иван'
S.Id < 5
S.Id ≥ G.Id
length(S.FirstName) = length(S.LastName) + 3
G where Name = 'M34371' ∨ Name = 'M34391'
S where FirstName = 'Иван' ∧ LastName <> 'Иванов'
Квантор Переменная (Условие)
G where ∃S (S.FirstName = 'Иван' ∧ S.GId = G.GId)
G where ∀S (S.FirstName = 'Иван' ∨ S.GId <> G.GId)
S :: Students; G :: Groups; C :: Courses; P :: Point; G4 :: Groups where Name = 'M34351' ∨ Name = 'M34371' ∨ Name = 'M34391'
select G.GId from G where ∀S (S.GId = G.GId → ∀C (∃P ( S.SId = P.SId ∧ C.CId = P.CId ∧ P.Points ≥ 60)))
select S.FirstName, S.LastName, G.Name from S, G where S.GId = G.GId
select A1, ..., An from R
from R where θ
select R.*, expr as A from R
R :: R1, R2
R :: R1 where ¬∃R2 (R1 = R2)
R1.*, R2.* from R1, R2
R1.*, R2.* from R1, R2 where R1.Атрибуты = R2.Атрибуты
select G.GId where ∃S (∀C (∃P (G.GId = S.GId ∧ S.SId = P.SId ∧ C.CId = P.CId ∧ P.Points ≥ 60)))
Переменная :: Тип
SId :: Int
FirstName :: Varchar(100)
Отношение { Атрибут1 = Значение1, Атрибут2 = Значение2, ... }
S{FirstName = 'Иван', LastName = 'Иванов'}
S{SId = Id}
S{SId = SId}
SId where S{SId = SId}
SId where S{SId = SId, GId = 'M34371'}
SId where S{SId = SId, GId = 'M34371'} ∨ S{SId = SId, GId = 'M34391'}
SId where ¬∃Points (Points ≥ 60 ∧ P {SId = SId, Points = Points, CId = 10})
A1, ..., An from R where R{A1=A1, ..., An = An}
A1, ..., An from R where R{A1=A1, ..., An = An} ∧ θ
expr as A from R where R{A1=A1, ..., An = An}
A1, ..., An where R1{Ai=Ai} ∨ R2{Ai=Ai}
A1, ..., An where R1{Ai=Ai} ∧ ¬R2{Ai=Ai}
A1, ..., An, B1, ..., Bm where R1{Ai=Ai} ∧ R2{Bj=Bj}
A1, ..., An, B1, ..., Bm, C1, ..., Cl where R1{Ai=Ai, Bj=Bj} ∧ R2{Ck=Ck, Bj=Bj}
R(x1, x2, ..., xn)
¬R(x1, x2, ..., xn)
Отношение(x1, x2, ..., xn) :- цель .
Ivans(Id, LastName) :- Students(Id, FirstName, LastName), FirstName = 'Иван'.
Ivans(Id, LastName) :- Students(Id, 'Иван', LastName).
Names(Name) :- Students(_, Name, _). Names(Name) :- Lecturers(_, Name, _).
Less(x, y) :- x < y.
NotStudent(Id, Name) :- ¬Students(Id, Name, _).
Q(A1, ..., An) :- R(A1, ..., An, _, ..., _).
Q(A1, ..., An) :- R(A1, ..., An), θ.
Q(A1, ..., An) :- R1(A1, ..., An). Q(A1, ..., An) :- R2(A1, ..., An).
Q(A1, ..., An) :- R1(A1, ..., An), ¬R2(A1, ..., An).
Q(A1, ..., An, B1, ..., Bm) :- R1(A1, ..., An), R2(B1, ..., Bm).
Q(A1, ..., An, B1, ..., Bm, C1, ..., Cl) :- R1(A1, ..., An, B1, ..., Bm), R2(B1, ..., Bm, C1, ..., Cl).
Person(Id, Name, FatherId, MotherId)
Parents(N, FN, MN) :- Person(_, N, FId, MId), Person(FId, FN, _, _), Person(MId, MN, _, _).
Parents(N, FN) :- Person(_, N, FId, _), Person(FId, FN, _, _). Parents(N, MN) :- Person(_, N, _, MId), Person(MId, MN, _, _).
Parent(Id, ParentId)
Ancestor(Id, PId) :- Parent(Id, PId). Ancestor(Id, GId) :- Parent(Id, PId), Ancestor(PId, GId).
[not] exists (select ...)
select G.Name from G where not exists (select * from S where S.GId = G.GId)
(выражения) [not] in (select ...)
select * from P where P.CId in (select CId from C where Year = 4)
выражение условие { any | all } (select ...)
select SId, CId from P as PE where PE.Points >= all (select Points from P where P.CId = PE.CId)
(select ...)
select SId, (select Name from G where G.GId = S.GId) from S
select SId, CId from P as PE where PE.Points >= all (select Points from P where P.CId = PE.CId)
select * from P where P.CId in (select CId from C where Year = 4)
with recursive Отношение(колонки) as ...
with recursive Ancestor(Id, AId) as select Id, PId from Parent union select P.Id, A.AId from Ancestor A inner join Parent P on A.Id = P.PId select * from Ancestor;