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

Get details about pivot column [Laravel 5]

I have 3 tables: Project, Group, User and one relation pivot table: project_group with colmuns: id project_id group_id and pivot field user_id I know how to take all Groups and Projects: Project::find(1)->groups()->get(); groups() is belongToMany…
Vladimir Djukic
  • 2,042
  • 7
  • 29
  • 60
0
votes
1 answer

Symfony2/Doctrine2 database relationship between a group, a message and a location

I'm trying to come up with the right model for the relationship between a Group of users, a short displayed alert Message, and a named Location. For example: Students and Interns (Groups) might need a special instruction (Message) to be displayed…
okdewit
  • 2,406
  • 1
  • 27
  • 32
0
votes
1 answer

How to implement multiplicity of zero-or-one in one-to-many relationship?

Assume Teacher-Student common scenario with two limitations: All the teachers should have at least one student (You teach or you are fired!) All the students should have zero or one teacher (Students are free to chose a teacher!) The hard part is…
Hans
  • 2,674
  • 4
  • 25
  • 48
0
votes
1 answer

How can I see all the relations betwen tables in phpmyadimn

I have a db that has around 280 tables, is there a way in phpmyadmin to see all the relations between all the tables? I need to export some data an I need to export 1st the tables that have no dependencies and after the ones that depend on them.
1x2x3x4x
  • 592
  • 8
  • 26
0
votes
1 answer

Maniging relations in rails

I am working on an application and I have to create a model product which has many pictures and also a main picture. I want to model this situation through relations and not using an additional boolean field which can tell if one picture is the main…
Madalina
  • 457
  • 1
  • 5
  • 14
0
votes
1 answer

Yii2. "With" in ManyToMany

I have 3 models: Image, Company and File. So if we look through Company model, we have: /** * @return \yii\db\ActiveQuery */ public function getImages() { return $this->hasMany('galleries\models\Image', ['id' => 'image_id']) …
rkalita
  • 575
  • 4
  • 16
0
votes
1 answer

django model relation definition

Let say I have 3 models: A, B and C with the following relations. A can have many B and many C. B can have many C Is the following correct: class A(models.Model): ... class B(models.Model): ... a = models.ForeignKey(A) class…
Laurent Luce
  • 929
  • 2
  • 14
  • 28
0
votes
2 answers

Database organization for separating two different types of the same model

So I want my User model to have_many Skills. I want there to be two different categories for the skills: a wanted skill, and a possessed skill. For example, a user can add a skill to their profile that they possess, such as HTML. They can also add…
parameter
  • 894
  • 2
  • 18
  • 35
0
votes
2 answers

Yii2 Relational databases confusion

So i am working with Yii2 and i'm trying to get what i think is relation databases in order. What im trying to do is have multiple tables return one set of data with the Yii2 rest api. Ive been trying to find exactly what i need to do but im a bit…
user616
  • 783
  • 4
  • 18
  • 44
0
votes
2 answers

JPA joined column allow every value

I'm testing JPA, in a simple case File/FileVersions tables (Master/Details), with OneToMany relation, I have this problem: in FileVersions table, the field "file_id" (responsable for the relation with File table) accepts every values, not only…
Fabio B.
  • 970
  • 2
  • 14
  • 29
0
votes
3 answers

Is my relation a one-to-many or a many-to-many?

I have a model called Addresss which as the name sounds, is a list of addresses. These addresses can belong to a Client and a client can have many of these addresses. To link these addresses to the client, I will simply have a table called…
Lock
  • 5,422
  • 14
  • 66
  • 113
0
votes
1 answer

Eloquent relationships laravel

I have 3 tables categories id name categories_product id category_id product_id and a product table products id name I want products based on catergori_id, how kan i do that with laravel Eloquent?
0
votes
1 answer

Rails deleting a returned relation from subtraction of two queries

I have three models class Account has_many :link_requests, :through => :suppliers end class Supplier has_many :link_requests, :dependent => :destroy end class LinkRequest belongs_to :supplier belongs_to :account end I have it so that…
legendary_rob
  • 12,792
  • 11
  • 56
  • 102
0
votes
2 answers

Non Working Relationship

I got a problem with cake's model architecture. I got a Users-Model and a Metas-Model. Here are the model codes: Users: array('notempty'), 'email'…
Dominik Kukacka
  • 569
  • 1
  • 5
  • 15
0
votes
2 answers

Creating multiple relationships in rails with same datatypes

What I am trying to do is kind of like this: I have datatypes "user" and "article" for instance. I want to have relationships between these two, but in more than one way. So for instance, I'd like to let a user "like" or "bookmark" an article. So I…
Lowgain
  • 3,254
  • 5
  • 27
  • 30