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
6
votes
1 answer

Two 1 - N relations in Mongoid (Rails)

The scenario is: How can an Account give ratings to another account? This results in two lists on the Account. Those who I have rated and those who have rated me. (my_ratings and ratings_given) This boils down to: How can multiple 1 - N…
Arron S
  • 5,511
  • 7
  • 50
  • 57
6
votes
1 answer

How can I make and enforce a generic OneToOne relation in django?

I'd like the exact same thing as django.contrib.contenttypes.generic.GenericForeignKey, but OneToOne instead of ForeignKey. I thought an easy (albeit marginally inelegant) workaround was to add unique=True to the field in question, but that borks.
jMyles
  • 11,772
  • 6
  • 42
  • 56
6
votes
1 answer

Django Multi-User logins - best approach?

I'm currently developing a Django site in which users can have multiple 'accounts', so that they can seamlessly switch between different public profiles when interacting through the site. What I'm designing is likely to attract multiple…
5
votes
3 answers

MySQL: Getting Posts from Categories

I'm trying to learn MySQL so I have created a little blog system. I have 3 tables in MySQL: posts : id | title ---------------- 1 | Post Title 1 2 | Post Title 2 categories : id | title |…
Adam Halasz
  • 57,421
  • 66
  • 149
  • 213
5
votes
1 answer

How to create nested objects in Rails3 using accepts_nested_attributes_for?

I cannot figure out how I can setup a form that will create a new Study while also creating the related StudySubject and the Facility. The user_id, facility_id and study_subject_id have to be available to create the Study object as you can see in…
JJD
  • 50,076
  • 60
  • 203
  • 339
5
votes
2 answers

Laravel get second level relations

I have three database tables: +------+-----------+---------------------+ | user | user_type | user_type_relations | +------+-----------+---------------------+ Each user can have many types, but one user type can only have one user. To store this…
Peter
  • 233
  • 2
  • 4
  • 8
5
votes
2 answers

Strongloop loopback: How can I add related model instances on a model instance in a boot script

I'm working on an API for a school platform. I want to migrate and seed the database in a boot script, while I'm still developing. I can make school instances, group instances, and person instances, but I cannot figure out how to add a relation…
Ernie
  • 972
  • 1
  • 10
  • 23
5
votes
1 answer

Laravel Querying Relations Model::has('relation') doesn't work

In the Laravel documentation it says you can use this syntax for querying an object relation to get only the Posts that have at least one Comment: $posts = Post::has('comments')->get(); I'm trying something similar where I want to fetch only…
Mat
  • 187
  • 2
  • 10
4
votes
2 answers

Estimated size of the self-join operation on a relation R, given a histogram for R

Query optimizers typically use summaries of data distributions to estimate the sizes of the intermediate tables generated during query processing. One popular such summarization scheme is a histogram, whereby the input range is partitioned into…
user966892
4
votes
4 answers

How to insert into another table after Registration on Laravel?

So, I have a laravel web and have some tables, two of them are users and user_data. user_data have a foreign key user_id that references to id on users. users have general attributes like username, email, password, etc. and user_data have 1 on 1…
Evan Gunawan
  • 387
  • 4
  • 17
4
votes
1 answer

cakephp two foreign keys in same table

I have a tournament website with CakePHP, where i needs to manage a condition like below details: There will be a fight competition between two competitor's where I needs to manage a match division and match schedules, and here Competitor and…
Aditya P Bhatt
  • 21,431
  • 18
  • 85
  • 104
4
votes
1 answer

How to add a category to a post in rails without a category controller

thank you all for your help in advanced. I'm an absolute beginner in rails and I'm trying to work through a tutorial. The task is as follows. I have a post model built from a scaffold with only the content:string field. Then a category model, not…
Leon92
  • 505
  • 1
  • 9
  • 15
4
votes
2 answers

Delete all rows which has no id existing in another table

I want to delete all rows which has no existing foreign key in another table example: table1 +----+-------+ |id | data | +----+-------+ | 1 | hi | +----+-------+ | 2 | hi | +----+-------+ | 3 | hi | +----+-------+ | 4 | hi …
4
votes
1 answer

Duplicate tables having N:M relationship (including relationship)

Working on an existing webapp (PHP/MySQL) I came to this point: I have 2 tables storing names and types id. The relation between them being N<---->N I have another table in between. (see picture) I have a last table called "category" which is…
monsieur_h
  • 1,360
  • 1
  • 10
  • 20
3
votes
3 answers

Implementing foreign key type relationships in XSD schema

I'm trying to wrap my head around xml schemas and one thing I'm trying to figure out is how to do relational type schemas where on element refers to another, possibly in another schema altogether. I've looked at the xsd:key and xsd:keyref and it…
Marcus Stade
  • 4,724
  • 3
  • 33
  • 54
1
2
3
21 22