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

How to post to a join table in a rails controller

I am trying to add to a many to many relationship with the following models: class Account < ApplicationRecord belongs_to :user has_many :issues, through: :interests end class Issue < ApplicationRecord has_many :accounts, through:…
d00medman
  • 191
  • 3
  • 15
1
vote
1 answer

Laravel insert data to one to one relation table

How can I insert data (that linking each other) to the table 'PEMBATALAN' that has one to one relation (have foreign key in both table) to the other table 'PERMINTAAN'. here is the 'pembatalan' model code: class Pembatalan extends Model { public…
1
vote
1 answer

How to relate two tables in Laravel 5.0

In a little example, I have 3 tables (2 of them are important). My tables are PRODUCT, TRANSFER, WAREHOUSE I want to transfer the PRODUCT from 1 WAREHOUSE to another and obviously this transfer has to be in the TRANSFER TABLE, My example model could…
JORGE GARNICA
  • 1,016
  • 2
  • 9
  • 13
1
vote
1 answer

SQL database schema design tags

Here is the database schema I just drew up. A beer belongs in a single category. A category is composed of multiple tags. A beer is tagged by multiple tags. A tag can be used with multiple beers (many to many). Constraint: You cannot add tags to…
1
vote
1 answer

ASP MVC Delete only the relation between 2 tables (many-to-many relation)

Using ASP MVC with active record. Ive got 2 tables with records that sometimes are related and sometimes aren't. The relation is defined by the user. 1 table has projects, the other has devices. Projects can be created and deleted, devices cannot.…
Prd
  • 247
  • 1
  • 2
  • 12
1
vote
1 answer

SQL schema, three relations only between two tables, can I do that?

I have two tables, login_inf (information about login) and history (history of changes in database, for example which user edited specified row) - picture below: I want to know which user did a specified action, which user added a row (created_by),…
mpj
  • 327
  • 1
  • 2
  • 12
1
vote
2 answers

Create T-SQL Constraint to prevent x amount of duplicate records in table?

In table A I have 2 columns: ID (int, PK) MaxUsers (int) In table B I have 2 columns: ItemID (int) UserID (int) The number of records in table A with matching ItemID's cannot exceed the MaxUsers value. Is it possible to write a T-SQL Table…
Curtis
  • 101,612
  • 66
  • 270
  • 352
1
vote
1 answer

Difference between SELECT and RESTRICT in Relational Algebra

I was going through some text on operations on relations and relational algebra. It stated: Some people use term “RESTRICT” for SELECT – possibly to avoid conflict with SELECT in SQL - both are different. What is the difference?
Rip Hunter
  • 97
  • 1
  • 11
1
vote
0 answers

Laravel 5.2: Inserting related models, not sure how to tackle my scenario

In my web application I want to add support for messaging eachother. There can be two or more people in one chat, and I have set up my tables as follows: +------------------------+ | Messages | +------------------------+ | id …
rebellion
  • 6,628
  • 11
  • 48
  • 79
1
vote
1 answer

Rails 4 - Creating bills about products I have listed

I have a model Product about all the products I offer in my shop This is basically just name:string and price:decimal. On the other side I have a model Bill where I list an amount of Products sold. I thought of making a relation M:N between Bills…
Enrique Moreno Tent
  • 24,127
  • 34
  • 104
  • 189
1
vote
1 answer

Django: DB relations - one user many other objects

Is there a way to tie many objects one user from native User model? I've been reading around it, but I still don't quite understand whether I need to extend User model(I wouldn't, if not necessary), and whether that would be onetomany or manytoone.
Milos
  • 981
  • 3
  • 16
  • 41
1
vote
1 answer

Laravel 5 - Elequent GROUP BY is failing

I am trying to do the following: I have two tables: 1) Content id, section_id parent_id, sequence, 2) Sections id, title, description, date_entered Each Content has to have a section, which is defined by a foreign key,…
Phorce
  • 4,424
  • 13
  • 57
  • 107
1
vote
1 answer

Django one-to many

I'm really really confused about how django handles database relationships. Originally I had an article model that contained a simple IntegerField for article_views, recently I'm trying to expand the definition of a article_view to contain it's own…
davegri
  • 2,206
  • 2
  • 26
  • 45
1
vote
1 answer

how to define a relationship in Yii2 with orOnCondition

I am logging changes in my database to a table called audit_field. For a given model I would like to retrieve all the audit_fields for this model as well as some of the related models. For example:
cornernote
  • 1,055
  • 1
  • 12
  • 20
1
vote
1 answer

Stock management of assemblies and its sub parts (relationships)

I have to track the stock of individual parts and kits (assemblies) and can't find a satisfactory way of doing this. Sample bogus and hyper simplified database: Table prod: prodID 1 prodName Flux capacitor prodCost 900 prodPrice 1350…
The Disintegrator
  • 4,147
  • 9
  • 35
  • 43