C # - programmatically identify the type of relationship between two tables

GetOleDbSchemaTable is currently being used to tell me a lot of information about my database tables. While the OleDbSchemaGuid.Foreign_Keys argument tells me about the foreign key data in the table, I cannot conclude that there is something 1: N, N: 1, N: M, etc. from this data. Is there any way to get this type of information?

+4
source share
1 answer

As Jack noted, you can find out if a schema returns a unique column property.

if the foreign key from table A is unique in table B, then its ratio is from 1 to 1.

if it has a unique constraint in table B with a primary key in table B, then its 1 for many.

if there is a table C between A and B, where both primary elements A \ B are foreign keys in C, then this relationship is many, many.

+1
source

All Articles