Questions tagged [table-relationships]
220 questions
13
votes
3 answers
How to replicate foreign key of another table in one to many relationship
I have a three table structure: tournament, group and team. The tournament and group tables have a one-to-many relation, and group and team have a one-to-many relation as shown below.
How do i replicate the value of the tournament_id from group…

pinch boi triggered af
- 543
- 2
- 7
- 26
10
votes
1 answer
PgSQL default action on UPDATE | DELETE of foreign keys
In PostgreSQL what is the default action over a child table referencing with foreign keys a parent table, on the UPDATE / DELETE events?
The possible ones listed are the following:
NO ACTION | RESTRICT | CASCADE | SET NULL | SET DEFAULT
I imagine…

yodabar
- 4,651
- 2
- 33
- 38
10
votes
2 answers
How to avoid inserting duplicate entries when adding values via a sqlalchemy relationship?
Let's assume we have two tables in a many to many relationship as shown below:
class User(db.Model):
__tablename__ = 'user'
uid = db.Column(db.String(80), primary_key=True)
languages = db.relationship('Language', lazy='dynamic',
…

Paul Baltescu
- 2,095
- 4
- 25
- 30
6
votes
1 answer
Access replacing local table with ODBC linked table preserving original name references
I am trying to replace all the local tables in my Access DB with linked tables from an ODBC data source. I am able to import the new table which comes in as "xyz_table". I want to replace the old local "table" with "xyz_table". However when I…

Baxter
- 5,633
- 24
- 69
- 105
6
votes
3 answers
Create a One-to-Optional-One constraint in SQL Server
i have a "main table", call it Customers:
CREATE TABLE Customers (
CustomerID int PRIMARY KEY NOT NULL,
FirstName nvarchar(50),
LastName nvarchar(50)
)
And i have a "satellite table", call it…

Ian Boyd
- 246,734
- 253
- 869
- 1,219
5
votes
3 answers
Laravel relationships - accessing related value in view
I can't find a solution to a seemingly simple problem with passing related data to a view. I have a model 'Companies' that belongs to 'Regions'.
I've created the belongsTo relationship in my Companies model
namespace App\Models;
use…

PDevH
- 63
- 1
- 10
5
votes
1 answer
Yii2 relational data from 3rd level
A little bit connecting to my previous question:
I have following tables/models:
I've managed to join all tables for actionIndex, but I would like to implement now the same thing for actionView, but it seems find() and findOne() doesn't work the…

user2511599
- 796
- 1
- 13
- 38
5
votes
1 answer
How to create a relation between two tables with Visual Studio 2013 in SQL Server Express LocalDB without SQL Server Management Studio?
I can create a table relation very easily with SQL Server Express in Visual Studio 2010 by right clicking and selecting the relationships in the table designer.
How do I create a relation between two tables with Visual Studio 2013 in SQL Server…

Denis
- 141
- 3
- 14
4
votes
2 answers
How to see the table relationships in ORACLE
I had an Access database.
Now I have created a connection with this Access DB and copied it to ORACLE.
I hope the keys and constraints must be recreated in Oracle.
I couldn't find out how to create the relationships between the tables.
And also…

Arjun Babu
- 219
- 4
- 10
- 19
4
votes
4 answers
Importing/Exporting Relationships
I have a couple of mdb files with the exact table structure. I have to change the primary key of the main table from autonumber to number in all of them, which means I have to:
Drop the all the relationships the main table has
Change the main…

lamcro
- 6,069
- 18
- 57
- 70
4
votes
1 answer
Optional relationship in SQL Server -- How to implement in SSMS Schema Designer
I have two cases where I would like to set 'optional' relationship inside one table or between two tables.
First:
I want to set this relation as optional, in other words: there will be categories and subcategories in one table, so subcategory…

Gregy
- 340
- 1
- 6
- 16
4
votes
3 answers
Rails ActiveRecord relationships - has many and belongs to associations
I've created 3 models:
Article: contains an article
Tag: contains tags
ArticleTag: meant for associating a many-to-one tags to article relationship. It contains a tag_id and an article_id.
The problem I'm having is I'm fairly new to the active…

somejkuser
- 8,856
- 20
- 64
- 130
4
votes
4 answers
Code Igniter Model To Model Relationship
In CI, how do you relate each other the models?I have four models right now Users, UsersDepartment, UsersToDepartment, UserStatus and I need to join those four models to be able to pick up all the data.
I have this code in my controller to pick all…

user1149244
- 711
- 4
- 10
- 27
3
votes
1 answer
Synopse SQLite select rows for 1:N relationship
I'm playing with the Synopse's SQLite implementation, but I'm stucked with the following piece of code. In the form constructor I create a database model where there are two tables Task and Comment and one table TaskComments with relationship 1:N…

Martin Reiner
- 2,167
- 2
- 20
- 34
3
votes
2 answers
Database table structure for user albums and photos
Okay i'm creating a little community website. A user joins my site and he has the option to
enter his informations upload photos add friends and post to his wall. By now i want to know how to implement the album table.
The album has the following…

aygeta
- 429
- 3
- 7
- 17