简体   繁体   中英

How to get cardinality of relations between two tables in SQL Server using TSQL?

I am using following code to get all tables that have a foreign key of the table in where clause which in this example is SolutionUser :

select 
    (select name from sys.tables 
     where object_id = fk.parent_object_id) Name 
from 
    sys.foreign_keys fk 
left outer join 
    sys.tables st on fk.referenced_object_id = st.object_id   
where 
    st.name='SolutionUser'

What I can't achieve is to get the cardinality of these relationships (one-to-one, one-to-many)

Is it possible to get these cardinalities using T-SQL ?

This is a conceptual subject. You can't find out using schema or even data.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM