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

Database Relation source depending on field

I have a database of projects and their parent companies that manage them, each project and company has lists of departaments and countries. However if project has field DEFAULT set to true, the list of dep/ countries should be loaded from its…
n00b
  • 5,642
  • 2
  • 30
  • 48
0
votes
0 answers

One-to-one vs one-to-zero Relationship

So we have like two relationships one is one-to-one and the other is one-to-zero. And let me explain what I mean by that. By one-to-one I mean that there is no parent, one row cannot be identified without the other. By one-to-zero I mean that parent…
sudo
  • 343
  • 1
  • 11
0
votes
1 answer

How to create a query based on condition with 3 joined tables in MySQL

I'm a bit confused when trying to create a specific query with the following data tables: **table 1 - referral_data:** ID attribution_name ------------------------ 1 Category 2 Brand 3 Size 4 Color 5 Processor 6 …
0
votes
2 answers

Sql Data Modelling

Im attempting to build a database (pictured) One of the criteria is that any instrument that is used can only be used by 1 musician at a time. I was wondering how I would implement that it such a schema? Another criteria is that 1 of the musicians…
user3075549
  • 55
  • 1
  • 7
0
votes
2 answers

CakePHP conditions in associated Models

I have a database with Classes, Semesters, Users, and Visits(Visits is a join table for Users and Classes) The relations are: User hasAndBelongsToMany Class (through Visits Class belongsTo Semester Now I want to view all Visits with Classes in an…
0
votes
0 answers

Usage of $data in php/yii where clause

In a category view file, in Yii, ID I'm trying to post the items related to that category. As I need to customize it quite a bit I'm using my own setup instead of e.g. ListView. What I need in short is that the query extracts items that has the…
0
votes
0 answers

Laravel 4 - Reverse Morpth - Relation

I need some help with my models. I have "Nodes" and "Categories". And i want to create "Menus" that have Nodes and Categories. In morpth relation we had nodes and categories that had menus and NOT the reverse. Can anyone help me with the models?
Michalis
  • 6,686
  • 13
  • 52
  • 78
0
votes
1 answer

What signal should i use to make changes to Django-related objects

I got 3 models (simplifying): class User(models.Model): ... class PersonalAccount(models.Model): user = models.OneToOneField(user) balance = MoneyField() (like float) class Withdrawal(models.Model): date = models.DateField() amount…
Lord_JABA
  • 2,545
  • 7
  • 31
  • 58
0
votes
1 answer

The Rails Way (4.0) to create multiple levels of CRUD with relations?

I have three models: Page, Section, and Block. A Page has many Sections, and a Section has many Blocks. I'm trying to write it in such a way where the Page view has a form for creating new Sections, and the Section view has one for creating…
Duncan Malashock
  • 776
  • 10
  • 32
0
votes
5 answers

LazyInitializationException

I have the entity Profile with a set of ProfileConstraintSetEntity @Entity @Table(name = "tbl_group_profile") public class ProfileEntity { @Id @GeneratedValue @Column(name = "group_profile_id") private long id; …
EvilKarter
  • 267
  • 7
  • 22
0
votes
2 answers

Why am I getting an "undefined method" error with my has_one relationship in rails?

I have a page that outputs all of the user profiles that exist in the system. It was working before, I haven't changed anything, and now it is not working. It is telling me that I have "an undefined method `profile_name' for nil:NilClass", but I…
Philip7899
  • 4,599
  • 4
  • 55
  • 114
0
votes
2 answers

How to retrieve data from related documents by ID?

I'm trying to understand how to set up basic relations in mongoDB. I've read a bit about it in the documentation but it's a little terse. This should be pretty simple: I'm trying to log a list of impressions and the users who are responsible for the…
dsp_099
  • 5,801
  • 17
  • 72
  • 128
0
votes
2 answers

Relations between tables

I have 3 tables: A, B and C. Table A is in relation (n:1) with B and with C. Typically I store in A the B.Id (or the C.Id) and the table name. e.g. A.ParentId = 1 A.TableName = "B" A.ParentId = 1 A.TableName = "C" A.ParentId = 2 A.TableName =…
user232028
  • 113
  • 8
0
votes
3 answers

Simple Rails user messaging system

I need to implement very simple messaging system between 2 users, and the only requirement is to keep every conversation between 2 users separate. I wonder whether it's possible and reasonable to use only one model Message(sender_id, recipient_id )…
user1756971
  • 155
  • 1
  • 8
0
votes
2 answers

yii cgridview relation multiple level

I have 4 tables of order payments user and profiles. Payments has a belongs_to relation with order. Order has a belongs_to relation with user, and user has_many profiles. While displaying payments in cgridview I need to display the firstname and…
friedFingers
  • 245
  • 6
  • 18