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
6 answers

SQL database problems with addressbook table design

I am writing a addressbook module for my software right now. I have the database set up so far that it supports a very flexible address-book configuration. I can create n-entries for every type I want. Type means here data like 'email', 'address',…
2
votes
1 answer

One-to-one relations that only go one way in Laravel

Is it possible/right to have a a relation between tables that only goes one way? I have an invoices table that I need to reference in other tables likes commission_payments and membership_payments but the invoices table does not need a…
Vic
  • 2,655
  • 3
  • 18
  • 28
2
votes
5 answers

C# (WPF): Database Relationship Viewer

I would like to create a WPF application in C# that can show visually, in a user interface friendly way, the relationships between tables from a database chosen from the application user (MS SQL Server, MS Access, Oracle, MySQL, etc.) and allow the…
Alerty
  • 5,945
  • 7
  • 38
  • 62
2
votes
1 answer

Database structure to handle similar/same object at varying business levels

Scenario A well-known taco establishment wants to build a Django app with models Combo, ComboItem, Ingredient, and Order. Headquarters wants to create various combos with included items and layout the original item ingredients and price. Each…
2
votes
1 answer

Laravel - Database relationships

Let's consider a simple scenario of 'Company' and 'Employee' models. A company has many employees. Now, when I map this relationship in Laravel, what is the correct approach from the following? Approach 1: Employee belongsTo() Company and Company…
aBhijit
  • 5,261
  • 10
  • 36
  • 56
2
votes
1 answer

Cakephp Polymorphic relationship

I am developing an user system, this system has 3 types of users: Company employers Clients Providers All users has many properties so i distribuite in users tables with login information and profiles tables with users details My schema is…
2
votes
3 answers

Sort field in relations table (one to many), how to insert the sort number?

I have two tables, content and images (and a ContentImages table for the one to many relation, so that's actually 3 tables). The following code saves the relation (in the action > updateContentFromRequest() ): $ids =…
Marc
  • 65
  • 7
2
votes
1 answer

Should I create one big pivot or multiple small pivots in a great many to many connection?

I have the following tables: Users, Regions and Teams. Every tables are in many-to-many connection with eachother and I need every connection from every direction. In other words: Users can be in multiple Regions and Teams. Regions can have…
totymedli
  • 29,531
  • 22
  • 131
  • 165
2
votes
2 answers

Mongoid Create Embedded Document Inside Parent

I have two models User and Status. Status is embedded in User: User.rb class User include Mongoid::Document include Mongoid::Timestamps embeds_one :status, as: :statusable Status.rb class Status include Mongoid::Document include…
user2503775
  • 4,267
  • 1
  • 23
  • 41
2
votes
1 answer

CakePHP remove unwanted relationship

I create some relations Model_One hasMany Model_Two. I create some form with Model_One fields and a three fields likes Model_Two.0.name, Model_Two.1.name, Model_Two.2.name. In beforeSave or beforeValidate (no matter) of Model_2 I would like remove…
kicaj
  • 2,881
  • 5
  • 42
  • 68
2
votes
3 answers

Azure Storage Table with relations stored in Azure SQL

Is it a correct approach to store needed Azure Storage Table relations in Azure SQL database? For example, I may have a system that keeps track of Users and Books that they own. I would keep Users entities and Books entities in Azure Storage Table…
2
votes
2 answers

What's the best way to orgaize relations in django? Flat or tree -like?

I got 3 models client loan installment - one part of loan shold i do: loan-foreignKey(client) installment-foreignKey(loan) and to get the client installments something like that: loans = client.loan.all() result = array() foreach(loans as loan): …
Lord_JABA
  • 2,545
  • 7
  • 31
  • 58
2
votes
3 answers

How to control sql join order in Yii CDbCriteria "with"

I have the following criteria for a findAll statement $with=array( 'tumor'=>array( 'select'=>false, 'joinType'=>'INNER JOIN', ), 'tumorLibraryType'=>array( 'select'=>false, 'joinType'=>'INNER JOIN', …
111
  • 1,788
  • 1
  • 23
  • 38
2
votes
4 answers

PHP / Doctrine ORM multiple 'one-to-one' relations to the same class

Just working on a project where I have a class called 'Product' and a class called 'Image'. Each product has two types of images, one 'front' image and one 'back' image, so I defined two fields, one called image_front_id and one called…
user212251
2
votes
2 answers

Return false then an item can't be added to a has_many with :through

I have this models relations class User < ActiveRecord::Base has_many :trip_memberships, dependent: :destroy has_many :trips, through: :trip_memberships, uniq: true end class Trip < ActiveRecord::Base has_many :trip_memberships, dependent:…
miguel.camba
  • 1,777
  • 1
  • 14
  • 19