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

How do handle relations in document stores

I do understand that relations are not really needed in document stores, but for some things they can still be useful. Or am I wrong (snowed in on RDBMS)? For instance: Let's say that I got a bunch of files and their revision history: File Name …
jgauffin
  • 99,844
  • 45
  • 235
  • 372
2
votes
1 answer

Adding a 1 to Many relationship android Room Database?

I am having a hard time trying to figure out how to add a one to many relationship in my database. The Book entity needs to hold many Counts. When I tried it, I got an error that says: E/AndroidRuntime: FATAL EXCEPTION: main Process:…
2
votes
1 answer

How to set a relation of an object of Core Data entity

I have an entity mainEntity with three one-to-many relations to three different entities entity1, entity2 and entity3 (relations are named after objects they're referring to). entity mainEntity attribute name relation entity1 relation…
2
votes
1 answer

C# Entity Framework Core: how do I get the relationship of the bill to the vendor without including the vendor's list of bills?

I am trying to exclude a relationship from a database query using linq in Entity Framework Core. I have a database where I have a table of Bills and a table of Vendors. Each Bill has 1 Vendor Each Vendor has many Bills I want to exclude the…
2
votes
3 answers

TypeORM: Load relations with only certain specified fields

Despite much research and trial and error, I unfortunately do not yet have an elegant solution for the following use case: A user has several posts, which is correctly implemented as a one-to-many relationship. I want to load the user with all his…
stoniemahonie
  • 321
  • 1
  • 5
  • 13
2
votes
1 answer

how to create laravel 6 pivot table with multi-word

I have Accounts table and Site_links table. When I use this code in Account Model: public function site_links(){ return $this->belongsToMany($SitelinkModel, 'account_site_link', 'account_id', 'site_link_id')->withTimestamps(); } The values ​​of…
2
votes
2 answers

Attributes of object with multiple types in one table

I have a situation like this: I have multiple objects in one table and generally my columns depend on the type of object like crane, excavator etc. My problem is that crane has other params than excavator so a few columns have null value. I thought…
2
votes
2 answers

Attach to all possible relations from many-to-many method on create?

I have two Model named Position and Event, they have many-to-many relationship with each other. Event:
sveti petar
  • 3,637
  • 13
  • 67
  • 144
2
votes
2 answers

Sequential numbering in database (MSACCESS)

Summary: I have a table that has a uique primary key identifying each record. I also have three more fields that can identify a record: Category CategoryNumber DuplicateNumber When I add a new record and choose the Category, how can I get…
Youssef Ismail
2
votes
1 answer

One-to-One-Relation in same table using TypeORM

For a better structure, I want to split a more complex table in two entitys which results in two classes. By specifying a One-to-One-Relation, I would expect from a ORM that both were provided in the same table - Cause Joins make no sense here in a…
Lion
  • 16,606
  • 23
  • 86
  • 148
2
votes
1 answer

Laravel Many to Many Relationship or One to Many Relationship

i'm creating a web application for my client and the concept of this application is two user register in system and they can have deal with each other, for example i register in system, then you register then we can have dealing with each other and…
2
votes
1 answer

Save parent and child model object together

I use Django 2.0 and mysql database and my project model is like: class Parent(models.Model): name = models.CharField() class Child(models.Model): number = models.IntegerField() parent = models.ForeignKey(Parent) what I want is to save…
2
votes
1 answer

Query varying multi-level relations in mongodb

Simulated example. Two mongodb collections, departments and employees: Departments { _id: '101' } { _id: '102', parent: '101' } { _id: '103', parent: '101' } { _id: '104', parent: '103' } Employees { _id: '201', department: '101' } { _id: '202',…
henit
  • 1,150
  • 1
  • 12
  • 28
2
votes
1 answer

Kohana 3 ORM: Saving relationships

array()); } ?>
thom
  • 21
  • 2
2
votes
2 answers

RAILS: Relations (Select all answers from all topics)

category.rb has_many :topics topic.rb belongs_to :category has_many :answers answer.rb belongs_to :topic Question: How can i preform queries like Category.first.topics.answers.count
Src
  • 5,252
  • 5
  • 28
  • 56