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

Mapping an relationship without knowledge of concrete class in Hibernate

There are many topics on abstract mapping in Hibernate, but I couldn't find something that matches my case. Problem: My domain model consists of several entities, which don't inherit from each other. For example: Employee…
1
vote
1 answer

has_many children and has_many parents

I'm trying to figure out a complex relation between a Model. I have a model called "Concept", which has two inheriting types called "Skill" and "Occupation". Basicly this means that each concept represents a category, but a concept can also be a…
codingbunny
  • 3,989
  • 6
  • 29
  • 54
1
vote
2 answers

Return data using relation in adonisjs is null

I want to fetching data from two table that have one to one relation in database using adonisjs. When i'm try to fetch all data from one of table, that result is null. This is my relation code in model: class Cart extends Model { product () { …
chiper4
  • 303
  • 5
  • 18
1
vote
2 answers

Yii2 relation based on attribute values instead of keys

I have 2 tables in the db (mysql), and between the 2 there is no classic relationship through keys or ids. The only way I could define relationship would be through attribute values. E.g. table wheel and car and certain wheels would match certain…
user2511599
  • 796
  • 1
  • 13
  • 38
1
vote
3 answers

Counting how many time a relation is pointing at the same key

SELECT t.tag_name FROM tags t JOIN resource_tags rt ON rt.tag_id = t.tag_id JOIN resource r ON r.resource_id = rt.resource_id JOIN visitor_resource vr ON vr.resource_id = rt.resource_id JOIN visitor v ON v.visitor_id = vr.visitor_id WHERE…
1
vote
1 answer

How to write select query in django in chain of one-to-many relationship?

How to write select query in django? I have 2 one-to-may relationship At the beginning, i am not very good at english. i am so sorry :). I have 3 tables. Driver, Car and Ride. The relationship between Driver and Car is (one-to-many: a Driver can…
1
vote
1 answer

Show results of joined tables even if some values don't match

Access Database table contacts -------------- id surname name table relations --------------- contact_id relation_id Both contact_id and relation_id are foreign keys referenced to table contacts' id I want to execute a query to get both the…
Stefanos Kargas
  • 10,547
  • 22
  • 76
  • 101
1
vote
1 answer

How to magically supply Active Record scopes with arguments?

I'm not sure this is even possible, but let's see if one of you comes up with a solution. This is more or less about code quality in terms of readability and not an actual problem because I already have a solution. I have a friendship model and a…
t6d
  • 2,595
  • 3
  • 26
  • 42
1
vote
2 answers

How can I remove dataset relation?

How can I do that? I have tried DataSet.Relations.Clear(), but it doesn't work. any ideas?
Brezhnews
  • 365
  • 2
  • 6
  • 13
1
vote
1 answer

laravel access level management (user permission array base on relations)

This is my idea not just to have groups of users, but also groups of permissions. Here is how the database schema looks: database schema I define my database relations as these : userModel.php public function roles() { return…
movAhed
  • 73
  • 1
  • 2
  • 14
1
vote
1 answer

How to save data in a "has_many trough" relation from API?

I'm doing a Ruby on Rails API. I have two models plans and categories, which has a relation "many to many" so I use an intermediate table with a model called category_plans. What I want is to create a plan with many categories, and each one of them…
1
vote
1 answer

Can a foreign key be created to point into a non unique column in a date range versioned table in PostgreSQL?

I would like to do two things in PostgresSQL: version rows in a table by a date range ensure the integrity of the table by setting up single column foreign keys For me, it seems I can do only one of the above at the same time. Detailed example: I…
NoNameProvided
  • 8,608
  • 9
  • 40
  • 68
1
vote
0 answers

How to insert data and retrieve data in nested relationships in Room Database Android

I have entities @Entity public class A { @PrimaryKey(autoGenerate = true) public long id; public String bFId; public List bList; } @Entity() public class B { @PrimaryKey @NonNull …
1
vote
1 answer

Get table multiple relations

I have the following eloquent call: \App\Models\AwardRecommendation::with('entities', 'countries')->get(); When I ask for with 'countries' is because the 'entities' table has the country_id and not the 'awards' table. The models I have are:…
McRui
  • 1,879
  • 3
  • 20
  • 31
1
vote
0 answers

How to display related tables in Laravel 5?

I've got two different tables, one is called articles, the other one images I Want to create an article that contains multiple images, How can I create with Laravel 5.5 a many-to-many relation? I've followed this post on laracast: …