Last active
May 23, 2023 22:02
-
-
Save Hugoberry/cb2687e1ca49d0d2305fbb59fd0b9ebb to your computer and use it in GitHub Desktop.
sqlite query to surface the relationships from metadata.sqlite in PowerBI
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
with cte as (SELECT | |
ta.name as ta , tb.name as tb | |
FROM | |
'relationship' rel | |
join 'table' ta on rel.Fromtableid = ta.id | |
join column ca on rel.fromcolumnid = ca.id | |
join 'table' tb on rel.totableid = tb.id and tb.systemflags =0 | |
join column cb on rel.tocolumnid = cb.id) | |
select ta from cte | |
union select tb from cte | |
order by 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SELECT | |
ta.name ||'.'|| ca.ExplicitName as ca,'<-', tb.name ||'.'|| cb.ExplicitName as cb--, rel.fromCardinality, rel.toCardinality | |
FROM | |
'relationship' rel | |
join 'table' ta on rel.Fromtableid = ta.id | |
join column ca on rel.fromcolumnid = ca.id | |
join 'table' tb on rel.totableid = tb.id and tb.systemflags =0 | |
join column cb on rel.tocolumnid = cb.id | |
order by 2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SELECT ta.NAME AS ta, | |
ca.explicitname AS ca, | |
tb.NAME AS tb, | |
cb.explicitname AS cb, | |
rel.fromcardinality, | |
rel.tocardinality | |
FROM 'relationship' rel | |
JOIN 'table' ta | |
ON rel.fromtableid = ta.id | |
JOIN COLUMN ca | |
ON rel.fromcolumnid = ca.id | |
JOIN 'table' tb | |
ON rel.totableid = tb.id | |
AND tb.systemflags =0 | |
JOIN COLUMN cb | |
ON rel.tocolumnid = cb.id |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment