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
3
votes
0 answers

store user connections in database (social network like) +add/find/change/delete

I'm working on some sort of social network these days, and I'm wondering how I can store the user connections in a database. The structure I've been thinking of looks like this, and it suits me pretty good. I guess it's against the third rule of…
maxischl
  • 579
  • 1
  • 11
  • 29
3
votes
3 answers

mysql many to many relationship

Been reading the tutorial How to handle a Many-to-Many relationship with PHP and MySQL . In this question I refer to the "Database schema" section which states the following rules: This new table must be constructed to allow the following: * It…
Poni
  • 11,061
  • 25
  • 80
  • 121
3
votes
2 answers

How can I update hasandbelongstomany relations for multiple models at once in strongloop loopback

I have 2 models in a Strongloop Loopback API Products Tags Between those 2 models I have defined a hasAndBelongsToMany-relation. In my CMS I want a bulk-update functionality for my products, in which I can select many Products, and assign many…
3
votes
6 answers

Database structure - To join or not to join

We're drawing up the database structure with the help of mySQL Workbench for a new app and the number of joins required to make a listing of the data is increasing drastically as the many-to-many relationships increases. The application will be…
3
votes
2 answers

rails ordering by has many relation

I'm trying to order my concerts by the number of reviews each has. Concert has_many reviews. Tried doing this <% @concerts = Concert.all %> <% @concerts.order(reviews.size).each do |concert| %> - - - <% end %> but I get this error…
parameter
  • 894
  • 2
  • 18
  • 35
3
votes
0 answers

Laravel 4 Relations belongsTo on multiple tables

I'm trying to do a stystem of comments and posts with laravel 4 where 2 type of "user" can comments. For 2 type of "user" means that i have a table User and a table Teams and my expectations are that both can let comment on the posts of the…
Fabrizio Fenoglio
  • 5,767
  • 14
  • 38
  • 75
3
votes
2 answers

In Rails, what do keywords belongs_to, has_many, etc, actually do?

I understand the concept of relational databases, primary/foreign keys, etc, however, I'm having trouble seeing the actual result of setting these properties up in my models. Do they generate helper functions or something similar? or do they simply…
flyingtoaster0
  • 159
  • 1
  • 7
3
votes
1 answer

CakePHP: One to One relationship

I'm a bit confused in how CakePHP does it's database relationship. For a hasOne relationship, according to the documentation: "User hasOne Profile" User hasOne Profile -> profiles.user_id Array ( [User] => Array ( [id] =>…
Timber
  • 859
  • 9
  • 25
3
votes
2 answers

Meteor + MongoDB - display list of posts with their comments count

I'm very new to Meteor, so this question might sound awkward. I'm trying to display a list of all posts Posts = new Meteor.Collection('posts'); and then in Meteor.publish('posts', ...) return Posts.find(); and show a number of comments related to…
3
votes
2 answers

database model for products and product package with different combinations

How would you design your database to achieve this functionality? Consider a scenario where we want to create a product relation (package)... Say that we create a ProductTbl prod_id prod_name prod_fee 1 prepaid-A 19 usd 2 …
MrSimpleMind
  • 7,890
  • 3
  • 40
  • 45
3
votes
2 answers

cake php contain in contain

I'm using CakePHP for my project... To speed up my code I only want to get some types of models which are related to my actual object: $result = $this->Category->find( 'first', array( 'conditions'…
Marcel C
  • 55
  • 2
  • 8
3
votes
2 answers

Multiple relations in CakePHP

I'm creating a tournament-platform with CakePHP. Currently I've created the following tables, models and controller which work perfectly: Tournaments, Users, and Teams. I've created a "Tournamentuser" table, controller & model as well, where the…
2mas
  • 127
  • 2
  • 14
2
votes
2 answers

Problems with MongoID and one to many relations

I encountered the following problem with MongoID. I've created two models which related by one to many. require 'mongoid' class User include Mongoid::Document has_many :configs field :login, :type => String, unique: true field :password,…
2
votes
1 answer

Looking for foreign keys in a DataSet

Is there a way to look for all of the foreign keys in a data set? I know there's a way to look for all of the relations: new DataSet().Relations Is there a similar proptery for just foreign keys?
poy
  • 10,063
  • 9
  • 49
  • 74
2
votes
1 answer

Complex Database Relations (Junction Tables)

My Question is about the idea of combining two junction tables into one, for similarly related tables. Please read to see what I mean. Also note that this is indeed a problem I am faced with and therefore relevant to this forum. It is just a topic…
Chiramisu
  • 4,687
  • 7
  • 47
  • 77
1 2
3
21 22