What's the correct name for an association table (a many-to-many relationship)
Cross reference table. CustomerProductXRef.
What should I name a table that maps two tables together?
There are only two hard things in
Computer Science: cache invalidation
and naming things
-- Phil Karlton
Coming up with a good name for a table that represents a many-to-many
relationship makes the relationship easier to read and understand. Sometimes finding a great name is not trivial but usually it is worth to spend some time thinking about.
An example: Reader
and Newspaper
.
A Newspaper
has many Readers
and a Reader
has many Newspapers
You could call the relationship NewspaperReader
but a name like Subscription
might convey better what the table is about.
The name Subscription
also is more idiomatic in case you want to map the table to objects later on.
The convention for naming many-to-many
tables is a concatenation of the names of both tables that are involved in the relation. ColourShape
would be a sensible default in your case. That said, I think Nick D came up with two great suggestions: Style
and Texture
.
Is there a specific name for this kind of table?
It is generrally called an associative entity, but also goes by these names (listed alphabetically):
- association table
- bridge table
- cross-reference table
- crosswalk
- intermediary table
- intersection table
- join table
- junction table
- link table
- linking table
- many-to-many resolver
- map table
- mapping table
- pairing table
- pivot table
- transition table
Non-key data stored in these tables (if any) is usually described as associative data.
Proper Table naming convention for a many-to-many intersect table
I usually use the names of both of the joining tables.
So, in your case, ClientBroker.
How to properly Name an association table (One to one relationship)
The best name to give a one-to-one association table is exactly the same as the best name to give any table: whatever is the most meaningful to you and your group.
If you feel that a 1-1 cross reference table needs to have a different name than a n-m cross reference table, then take a vote. Maybe Table1Table2YRef will win (many in today's society consider a Y to be half an X).
Whatever floats your boat. Just agree on something sensible, apply it consistently and get back to work.
Btw, how many of these tables do you have. In 20+ years, I don't remember ever coming across one. There are easier ways to establish a 1-1 relationship. About the only reason I can think of where one would be useful is if the relationships break up and reform on a regular basis (kinda like a lot of marriages).
Addendum: a typical 1-1 implementation. When breaking up a large table with many fields that are rarely used, normalizing those fields to a separate table.
MainTable:
PK: 1001, F1, F2, ..., F75
PK: 1002, F1, F2, ..., F75
PK: 1003, F1, F2, ..., F75
Result:
MainTable:
PK: 1001, F1, F2, ..., F15
PK: 1002, F1, F2, ..., F15
PK: 1003, F1, F2, ..., F15
SubTable:
PK: 1001, F16, F17, ..., F15
PK: 1002, F16, F17, ..., F15
PK: 1003, F16, F17, ..., F15
create table SubTable(
ID int not null,
..., -- F16 thru f75
constraint PK_SubTable primary key( ID ),
constraint FK_SubTable_MainTable foreign key( ID )
references Maintable( ID );
);
Is there an official name for the many-to-many relationship table in a database schema?
The most common name is "Join Table" in my opinion, but I have heard several others you have listed. So, I would say "no", there is no "official" name :-)
Many to many relation without association table
You're right there will only be many-to-one or one-to-many relationships. What you need is a joining table, for example:
create table A_B (
A_id bigint references A,
B_id bigint references B
)
Then you can have as many rows with the same A_id
or B_id
as you want. That results in a many-to-many relationship.
Association table between 2 association tables. Is this the correct approach?
I believe what you are looking for is what is often called "ternary relationship".
Please see these two SO questions and answers to give you implementation ideas:
- How to three-way many-to-many relationship in flask-sqlalchemy
- Inserting relationships into a table which connects 3 tables with many to many relationships with SQLALchemy - python
Related Topics
How to Call an Oracle Stored Procedure from an Excel Vba Script
SQL Server - Query Short-Circuiting
Ssis Best Practice to Load N Tables from Source to Target Server
How to Make an Average of Dates in MySQL
How to Get a List Column Names and Datatypes of a Table in Postgresql
Postgresql Query Between Date Ranges
Backup a Single Table with Its Data from a Database in SQL Server 2008
SQL Server for Xml Path Make Repeating Nodes
How to Transform Comma Separated Column into Multiples Rows in Db2
Function-Based Indexes in SQL Server
Is Id Column Position in Postgresql Important
How to See the Structure of Mulitple Table with a Single "Desc"
Postgresql: Give All Permissions to a User on a Postgresql Database
Checking If a String Is Found in One of Multiple Columns in MySQL
SQL Filter Criteria in Join Criteria or Where Clause Which Is More Efficient
How to Return Random Numbers as a Column in SQL Server 2005
SQL Query Joins Multiple Tables - Too Slow (8 Tables)
How to Quickly Edit Values in Table in SQL Server Management Studio