azure sql server check foreign key

Solutions on MaxInterview for azure sql server check foreign key by the best coders in the world

showing results for - "azure sql server check foreign key"
Tommaso
08 Jan 2018
1select schema_name(fk_tab.schema_id) + '.' + fk_tab.name as foreign_table,
2    '>-' as rel,
3    schema_name(pk_tab.schema_id) + '.' + pk_tab.name as primary_table,
4    substring(column_names, 1, len(column_names)-1) as [fk_columns],
5    fk.name as fk_constraint_name
6from sys.foreign_keys fk
7    inner join sys.tables fk_tab
8        on fk_tab.object_id = fk.parent_object_id
9    inner join sys.tables pk_tab
10        on pk_tab.object_id = fk.referenced_object_id
11    cross apply (select col.[name] + ', '
12                    from sys.foreign_key_columns fk_c
13                        inner join sys.columns col
14                            on fk_c.parent_object_id = col.object_id
15                            and fk_c.parent_column_id = col.column_id
16                    where fk_c.parent_object_id = fk_tab.object_id
17                      and fk_c.constraint_object_id = fk.object_id
18                            order by col.column_id
19                            for xml path ('') ) D (column_names)
20order by schema_name(fk_tab.schema_id) + '.' + fk_tab.name,
21    schema_name(pk_tab.schema_id) + '.' + pk_tab.name
22