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

Doctrine2 - Saving custom join relation table

Basically, I have two tables (Article and Tag) and I want to make many-to-many (one article can have many tags, one tag can be assigned to many articles) relation with some extra attributes. I can write this in Doctrine2 by breaking it into two…
martin
  • 93,354
  • 25
  • 191
  • 226
0
votes
1 answer

upgrading tables with autoincrement fields and relations

I have got 2 tables. Headers with names and details with texts: create table Headers (_id integer primary key autoincrement, name string); create table Details (_id integer primary key autoincrement, id_headers integet, text string); id_headers is…
Foenix
  • 991
  • 3
  • 10
  • 23
0
votes
1 answer

FOSUserBundle - persisting related entities/documents

I have an app where each User has a "Home". I have overridden my FOSUserBundle registration FormType to embed the Home and capture some properties in the registration process. Unfortunately when I register, the new User is persisted but the new Home…
Phil Moorhouse
  • 850
  • 9
  • 22
0
votes
1 answer

Finding extra columns in a many to many relationship table

I wish to persist some extra data in a many-to-many relationship by having some extra fields in the association table. For instance, I would like to keep track of what role a user has in a network, such as 'member', 'moderator', 'admin' etc. I would…
PatrikAkerstrand
  • 45,315
  • 11
  • 79
  • 94
0
votes
1 answer

Rails Relations

I've 3 tables: profiles, users, payment_details Now, in models/user.rb I've the following: has_one :profile, :dependent => :destroy has_one :payment_detail, :dependent => :destroy In models/profile.rb I have: has_one :payment_detail, :through =>…
0
votes
8 answers

Database Design: Storing the primary key as a separate field in the same table

I have a table that must reference another record, but of the same table. Here's an example: Customer ******** ID ManagerID (the ID of another customer) ... I have a bad feeling about doing this. My other idea was to just have a separate table that…
James
  • 80,725
  • 18
  • 167
  • 237
0
votes
5 answers

Do I need to define a new primary key field for each table?

I have a few database tables that really only require a unique id that references another table e.g. Customer Holiday ******** ******* ID (PK) ---> CustomerID (PK) Forename From Surname To .... These tables such as Holiday,…
James
  • 80,725
  • 18
  • 167
  • 237
0
votes
1 answer

Update table with FK column values from related table

Hibernate entities used. There are Address and Room entities and apropriate tables in DB. Address can have multiple Rooms. Both tables have address_Id and customerEmailAddress These columns are FK in Room table,that references to Address…
sergionni
  • 13,290
  • 42
  • 132
  • 189
0
votes
1 answer

Are relations same as table?

I am taking database course and came across the term relation. Are relations same as tables and can be used interchangeably?
Fahd Uddin
  • 31
  • 6
0
votes
1 answer

Getting the Max Value of One-To-Many a relation in CoreData through NSPredicatae

I'm creating a timeclock application where there is a ClockPunch NSManagedObject model with properties representing a clockin and clockout punch. Each ClockPunch instance has a relationship with an Employee in the Employees model (which also has a…
tslater
  • 4,362
  • 3
  • 23
  • 27
0
votes
2 answers

Rails make a model require another model

If I have a has_and_belongs_to_many relationship between two models, let's say Users and Accounts, can I require that a User have at least one Account, and how? Also, using the has_and_belongs_to_many relationship, is it possible for an Account not…
0
votes
1 answer

Using Entity Framework with One to Many relationship defined with two Foreign keys

I am working with an existing database, so changing the schema is not an option. Here are the tables aI am working with ... Product ------------------------------------- ID - GUID [PK] Name - varchar(100) ModelId …
0
votes
1 answer

How to define checkboxlist-like database field

I've tried looking around the internet for an answer, but because I don't understand databases very well I'm having trouble phrasing my question to work as a Google search. I apologize if this has been answered somewhere, but I can't seem to find…
0
votes
3 answers

MySQL joins, how to output relation "the proper way"

First of all, excuse my poor topic title. I simply have no idea how to formulate this question or what to Google after, so don't shoot me if this is something easy answerable. Assume I have the following tables: [AUTHORS] id, name [NEWS] id, item,…
subZero
  • 5,056
  • 6
  • 31
  • 51
0
votes
0 answers

MySQL/PHP checking active relations

I have 2 big tables and i need to check how many relations between them are still active. The first table is a relations table with around 100k rows in it (ID, ID_something1, ID_something2 ). The second table is a bit larger, with around 6 mil…