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
1 answer

How to avoid dependency with entities from different bundles

I have several bundles in my app and I would like to have relations between tables. One is my User(StoreOwner) which is in UserBundle, and the second is Store in StoreBundle. The relation between them is OneToMany (User -> is owner of ->…
2
votes
1 answer

mysql collect 1:n relation into one record

I have a 1:n relation: Rule 1:n Examples For simplification you can assume that Rule and the Examples only consists one string attribute. I'm looking for a sql statement where I get a table with the following columns: rule; example_1; example_2;…
Markus
  • 3,948
  • 8
  • 48
  • 64
2
votes
1 answer

How to set up relations between these two rails models

I have 2 models: User and PrivateMessage which must be associated (as user has many private messages as reciever and sender, private messages belongs to user) It's my private_messages table structure: private_messages: sender_id:integer …
user973254
1
vote
3 answers

Concept: Is mongo right for applying schemas?

I am currently in charge of checking wether it is valuable for one of our upcoming products to be developed on mongo. Without going too much into detail, I'll try to explain, what the app does. The app simply has "entities". These entities are…
Jannick
  • 2,094
  • 3
  • 17
  • 21
1
vote
2 answers

Selectors where there are relationships

Is there a special way that you should call an object when you want to add a where clause that relates to a relationship that has been defined in the model. An example would be that I have an image, the image belongs_to or has_many (whatever rocks…
Rumpleteaser
  • 4,142
  • 6
  • 39
  • 52
1
vote
1 answer

SQLite database with Squirrel: No relations

What I have: I have an SQLite database with connections. Here is a little part of the sql create code (A many-to-many connection between destinations and log_entries table): DROP TABLE IF EXISTS "destinations"; CREATE TABLE "destinations"…
ald mike
  • 95
  • 1
  • 9
1
vote
1 answer

Associations in CakePHP with non-conventional database

We are converting an application for use with CakePHP 2.0.3. For some reason, I cannot seem to set proper relations between my models. Here's an example: User (id, petid, country, picid, ...) Pet (id, userid, picid, ...) Picture (id, albumid,…
Kukiwon
  • 1,222
  • 12
  • 20
1
vote
1 answer

Why can I only see postgreSQL relations or tables when I'm logged in as the postgres user?

Possible Duplicate: postgresql database owner can't access database - “No relations found.” The core problem: I have a Django website that's complaining about relations (tables) not existing when I connect to it after attempting to run a SQL…
mkelley33
  • 5,323
  • 10
  • 47
  • 71
1
vote
1 answer

How to relate two tables in power bi with no common fields

I have two data tables that I want to import into power bi and create a summary dashboard for it. One table is called 'Fuel Consumption Table' and it has the following fields: Name of the person dispensing fuel, Date Fuel was dispensed, Asset Type,…
1
vote
3 answers

Mongoid: undefined method `name' for nil:NilClass, even when it exists

When working with one-to-many relations in with Rails 3.1 and Mongoid, I keep bumping my head on undefined method `name' for nil:NilClass even when I'm positive it exists. Either it's a stupid mistake or then there's something wrong with Mongoid.…
1
vote
3 answers

Restructure tables on an existing website, to store historical data?

I've been trying to find a match for my issue in existing questions, and I'll accept links as an answer and close my question if you have them. What I'm trying to find is a way to restructure my existing tables. I have a website, and I spent kind…
1
vote
1 answer

API routes design for One to One Relationship

I'm building an API using Laravel where I need to use multiple One To One relationships. For nested resource where I use One to Many I defined the routes like this: /api/scenarios/1/users --> return all users from a…
NicuVlad
  • 2,491
  • 3
  • 28
  • 47
1
vote
1 answer

How to work this nested relationship in Room?

I could use a little help. I have created all the tables, and I can create a relationship to retrieve the application, but I do not know how I can retrieve the list of vehicle brands with the models. @Entity(tableName = "application_table", indices…
1
vote
1 answer

db relations vs software solutions to keep consistancy (performance)

From my point of view the database is always the bottleneck. Since i can scale the cpu power to any needed value. The db ressources are limited even with clustering or replication. I might be wrong here but these are my expierences so far with cloud…
risutoru
  • 455
  • 5
  • 13
1
vote
1 answer

Why should I use JOIN if I only need info from the table with foreign key?

I have a table Customer with Primary key customerNumber. I also have a table table customerOrder that has a foreign key FK_customerNumber to customerNumber in the Customer table. I know the customerNumber and need to select only order information…
Xtreme
  • 1,601
  • 7
  • 27
  • 59