Relational Schemas and Predicate Logic Notation Relations Let

  • Slides: 12
Download presentation
Relational Schemas and Predicate Logic: Notation

Relational Schemas and Predicate Logic: Notation

Relations • Let E 1, . . , En be sets of entities or

Relations • Let E 1, . . , En be sets of entities or objects (we may have Ei = Ej). • The Cartesian product E 1 x … x En is the set of tuples of the form (e 1, . . , en) where ei is in set Ei. • A relation R on E 1, . . , En is a subset of the Cartesian product E 1 x … x En. We say that n is the arity of the relation. Note that a relation may be unary.

Relational Schemas • A schema specifies a finite set of relations R 1, .

Relational Schemas • A schema specifies a finite set of relations R 1, . . Rn with additional structure: • Each column/field in a relation gets a name (can also just use position) and a domain. • A subset of fields is identified as the key. • The non-key fields are often called (descriptive) attributes. The values of the attributes are determined by the values of the key field. • Common Notation – Student(Name: string, GPA: numeric, Age: integer) – Registered(Name: string, Course: string, grade: nume

name ssn ER Model: Entities lot Employees • Entity: Real-world object distinguishable from other

name ssn ER Model: Entities lot Employees • Entity: Real-world object distinguishable from other objects. An entity is described (in DB) using a set of attributes. • Entity Set: A collection of similar entities. E. g. , all employees. – – All entities in an entity set have the same set of attributes. Each entity set has a key. Each attribute has a domain. A key defines the values of attributes---the attributes are functions of the keys.

name ER Model: Relationships ssn lot Employees dname did Works_In lot Employees since name

name ER Model: Relationships ssn lot Employees dname did Works_In lot Employees since name ssn budget Departments supervisor subordinate Reports_To • Relationship: Association among two or more entities. E. g. , Attishoo works in Pharmacy department. • Relationship Set: Collection of similar relationships. – An n-ary relationship set R relates n entity sets E 1. . . En; each relationship in R involves entities e 1, . . . , en • Same entity set could participate in different relationship sets, or in different “roles” in same set.

Notes on ER relationships • Note that relationships can have descriptive attributes too. •

Notes on ER relationships • Note that relationships can have descriptive attributes too. • The values of the descriptive attributes are determined once we have identified the entities involved: grade(Joe, CMPT 354). • The fields that identify the entities involved are callled foreign key pointers.

Relational Instance and Finite Models • A relational instance is a relational schema +

Relational Instance and Finite Models • A relational instance is a relational schema + set of tuples specified for each relation. • The list <R 1, . . , Rn> of relations (with tuples specified, but without field names and key constraints) is called a finite model in logic.

Graphical Visualization • A graph on set S is a binary symmetic relation over

Graphical Visualization • A graph on set S is a binary symmetic relation over S x S. • If the relation instance contains only one binary symmetric relation, it can be visualized as a graph whose edges and nodes are annotated with the values of descriptive attributes. • Classic social network analysis considers only the graph structure, not the attributes.

Translating Schemas Into Logic: no functions • Each relation of arity n predicate symbol

Translating Schemas Into Logic: no functions • Each relation of arity n predicate symbol with n arguments. • E. g. , “A student with GPA 3. 0 is younger than 40” Student(S, G, A) AND G = 3. 0 A < 40. • Pros: – Simple Translation. – Simple logic. • Cons: – Loses information about key fields. – Not always natural to read.

Translating Schemas Into Logic: Functions • Introduce one function symbol for each descriptive attribute.

Translating Schemas Into Logic: Functions • Introduce one function symbol for each descriptive attribute. The arguments are the key fields. • E. g. , Age(S), grade(S, C). Also: S. age, Registered. grade. • E. g. , “A student with GPA 3. 0 is younger than 40” GPA(S) = 3. 0 Age(S) < 40. • Pros: – Keeps information about keys and foreign keys. – Natural to read. • Cons: a bit more complex mathematically.

Formal definitions in logic • Use the function-free formulation, with predicate symbols R 1,

Formal definitions in logic • Use the function-free formulation, with predicate symbols R 1, . . , Rn. • The language contains a set of constants and variables. • A term is a constant or a variable. • An atom is: – a predicate symbol with the required numbers of terms, e. g. Student(N, G, 40), Student(Jack, 3. 0, 40). – A comparison of terms, e. g. X > 3, X = Y, 5 > 1. • A literal is an atom or a negated atom.

Clauses • A clause is a set of literals. • The negated literals are

Clauses • A clause is a set of literals. • The negated literals are called the body, the positive ones the head. • A clause is often written in implication form: b 1 AND b 2 h 1. • Also h 1 : - b 1, b 2. • A clause with a single positive literal is a Horn clause.