Questions tagged [database-relations]

A relation is a data structure which consists of a heading and an unordered set of tuples which share the same type.

A relation is a data structure which consists of a heading and an unordered set of tuples which share the same type.

When Edgar F. Codd invented the relational model, he generalized the concept of binary relation (mathematical relation) to n-ary relation. Relation is a fundamental concept in relational model.

  • A relation has zero or more tuples.
  • A relation value is an instance of a relation.
  • A relation variable (relvar) is a variable which has a relation value.

In some contexts, relation means relation variable. In other contexts, relation means relation value.

In SQL, a database language for relational databases, a relation variable is called a table. Relational model concepts including relation

A relation value, which is assigned to a certain relation variable, is time-varying. By using a Data Definition Language (DDL), it is able to define relation variables.

  • A heading is the unordered set of certain attributes (columns). A heading has zero or more attributes.
  • A body is the unordered set of tuples, which constitutes a relation value. In other words, a relation value consists of a heading and a body.
  • A tuple is a data structure which consists of the unordered set of zero or more attributes.
  • An attribute (column) is a pair of its attribute name and domain name. Domain can be considered data type, or simply, type.
  • An attribute has an attribute value which conforms to its domain. An attribute value is a scalar value or a more complex structured value.
  • The degree of a relation is the number of attributes which constitute a heading. The degree of a relation value is zero or more integer. An n-ary relation is a relation value in which its degree is n.
  • The cardinality of a relation is the number of tuples which constitutes a relation value. The cardinality of a relation value is zero or more integer.

There are no duplicate tuples in a relation value. A candidate key is a certain minimal set of one or more attributes that can uniquely identify individual tuples in a relation value.

319 questions
1
vote
0 answers

Can I set a generic yii view string based on model instead of individual widgets

I have set up relationships between several tables. I got the view in tableFoo to look up the Name in tableBar instead of showing barId, by putting the following into the widget: array( 'label' => $model->Bar->getAttributeLabel('Bar'), …
Phil H
  • 19,928
  • 7
  • 68
  • 105
1
vote
0 answers

Database: relationship among multiple tables

A worker need to pass controlTests. Each test consists on 50 controls divided on 5 categories, Ex: Category1: "Fire Security". Controls: "Extinguisher","Emergency exit","fire-fighting services" Category2: "Anti-thief system"..... It's…
1
vote
1 answer

What is the best database schema to connect "students" and "schools"

Using this simplified example; what approach do you think is better and why? Edit: The relation must be 1 to 1. A student only exists in one school. Option1 **Table Schools:** id int primary key; name string; **Table students:** id int primary…
Rick Deckard
  • 61
  • 1
  • 4
1
vote
1 answer

Rails multiple has_many :through and displaying associations

I'm building an application where a user can build a lesson from an assortment of standards and questions to teach the standards, but I'm not exactly sure if I have set up everything correctly or not. The 'new' page allows the user to use drop down…
1
vote
2 answers

How to combine cascading updates/deletes between SQL Server and NHibernate?

I am writing an application with a hand-crafted domain model (classes) and a hand-crafted data model (tables/relationships), and letting NHibernate take care of the mapping. Is it best to tell the database to perform cascading updates or deletes or…
yfeldblum
  • 65,165
  • 12
  • 129
  • 169
1
vote
1 answer

How to sort by nested field value with Mongoid?

Let's say I have a User with a field name, and which has_many teams, and a Team that belongs_to a user, and belongs_to a sport. A Sport has a field name and has_many teams. I want to walk through the sports, do some stuff, and collect an array of…
Dave Sag
  • 13,266
  • 14
  • 86
  • 134
1
vote
2 answers

How to implement mySQL self-relationship?

How can I create a Message table such as this in mySQL where it stores messages and their responses?
Ciphor
  • 732
  • 4
  • 11
  • 25
1
vote
1 answer

"Chained" relations (1:n:m) with Mongoid and Rails

I'm trying to achieve a really simple "multiple relationship" in Rails (3.2.12) with Mongoid (3.1.2). I got three models: class User include Mongoid::Document field :name has_many :collections end class Collection include Mongoid::Document …
jlxq0
  • 87
  • 1
  • 8
1
vote
0 answers

Relations with view oracle forms

I have two blocks on my form. The firs block: "vista_clientes", and the second "pedidos". The first is based on a view, and the second on a table. I go to relations on my first block, and press "create", then, I choose "pedidos" how detail block. I…
Genaut
  • 1,810
  • 2
  • 29
  • 60
1
vote
2 answers

Mongoid update_attributes creating new referenced document

I'm having trouble using update_attributes with referenced documents. I've reduced my problem to a simple example that AFAICT should work, but doesn't: class Account include Mongoid::Document has_many :submissions, :autosave => true end class…
Leopd
  • 41,333
  • 31
  • 129
  • 167
1
vote
1 answer

Using relations for models with namespace in Rails

How do I write relations for models with namespace? if I have Class Foo::Bar and Class Employee and I want to have habtm between them would I write Class Foo::Bar has_and_belongs_to_many :employees end and in Class…
Nick Ginanto
  • 31,090
  • 47
  • 134
  • 244
1
vote
3 answers

MySQL Family Tree: Hierarchy, Marriage ref, and Display

I am building a Family Tree + History [PHP] website to accompany and showcase my mom's genealogy report that she had put together for her parents' Christmas gift. The tree at least will be based upon a MySQL database ('family') in which I am…
user163831
  • 1,031
  • 3
  • 13
  • 25
1
vote
1 answer

Referencing table with two different foreign keys to the same table in Kohana ORM

table user: |id|name|employee_priority_id|user_priority_id| table priority: |id|name| As you can see, there are two foreign fields to the same table. But Kohana ORM default looks for a field called priority_id, which doesn't exist. Is there a way…
Ikke
  • 99,403
  • 23
  • 97
  • 120
1
vote
1 answer

Model association trouble with cakephp

I was having trouble with a voting system that I'm trying to make in cakePHP (found here cakephp is querying extra column and I can't figure out why) but I figured that out and now I'm having another issue. I'm making a voting system, and the…
user1406951
  • 454
  • 1
  • 10
  • 28
1
vote
7 answers

Conflicting desires in Database Design, with fields of two similar functions

Okay, so I'm making a table right now for "Box Items". Now, a Box Item, depending on what it's being used for/the status of the item, may end up being related to a "Shipping" box or a "Returns" box. A Box Item may be defective:if it is, a flag will…
EdgarVerona
  • 1,488
  • 1
  • 15
  • 23