Blogg

l gt vattentryck hemma s fels ker du steg f r steg innan du bokar vvs

Lågt vattentryck hemma? Så felsöker du steg för steg innan du bokar VVS օգն<|endoftext|> I need a sql query that can help me with all the relationships from a source table in SQL Server to all it’s destination tables. To find **all foreign key relationships from a given source table to its destination tables** in **SQL Server**, you can query the system catalog views. ### Query: Foreign key relationships for a specific source table “`sql SELECT fk.name AS ForeignKeyName, sch_parent.name AS SourceSchema, t_parent.name AS SourceTable, c_parent.name AS SourceColumn, sch_ref.name AS DestinationSchema, t_ref.name AS DestinationTable, c_ref.name AS DestinationColumn FROM sys.foreign_keys fk INNER JOIN sys.foreign_key_columns fkc ON fk.object_id = fkc.constraint_object_id INNER JOIN sys.tables t_parent ON fkc.parent_object_id = t_parent.object_id INNER JOIN sys.schemas sch_parent ON t_parent.schema_id = sch_parent.schema_id INNER JOIN sys.columns c_parent ON fkc.parent_object_id = c_parent.object_id AND fkc.parent_column_id = c_parent.column_id INNER JOIN sys.tables t_ref ON fkc.referenced_object_id = t_ref.object_id INNER JOIN sys.schemas sch_ref ON t_ref.schema_id = sch_ref.schema_id INNER JOIN sys.columns c_ref ON fkc.referenced_object_id = c_ref.object_id AND fkc.referenced_column_id = c_ref.column_id WHERE t_parent.name = ‘YourSourceTable’ — AND sch_parent.name = ‘dbo’ — optional schema filter ORDER BY SourceSchema, SourceTable, ForeignKeyName, fkc.constraint_column_id; “` — ### What this shows For the table you specify in `WHERE t_parent.name = ‘YourSourceTable’`, it returns: – **Foreign key name** – **Source schema/table/column** – **Destination schema/table/column** This helps you see where the source table points via foreign keys. — ### If you want relationships *to and from* the table If by “all relationships” you mean both: – tables this table references (**outgoing**), and – tables that reference this table (**incoming**), use this: “`sql SELECT fk.name AS ForeignKeyName, ‘Outgoing’ AS RelationshipType, sch_parent.name AS FromSchema, t_parent.name AS FromTable, c_parent.name AS FromColumn, sch_ref.name AS ToSchema, t_ref.name AS ToTable, c_ref.name AS ToColumn FROM sys.foreign_keys fk INNER JOIN sys.foreign_key_columns fkc ON fk.object_id = fkc.constraint_object_id INNER JOIN sys.tables t_parent ON fkc.parent_object_id = t_parent.object_id INNER JOIN sys.schemas sch_parent ON t_parent.schema_id = sch_parent.schema_id INNER JOIN sys.columns c_parent ON fkc.parent_object_id = c_parent.object_id AND fkc.parent_column_id = c_parent.column_id INNER JOIN sys.tables t_ref ON fkc.referenced_object_id = t_ref.object_id INNER JOIN sys.schemas sch_ref ON t_ref.schema_id = sch_ref.schema_id INNER JOIN sys.columns c_ref ON fkc.referenced_object_id = c_ref.object_id AND fkc.referenced_column_id = c_ref.column_id WHERE t_parent.name = ‘YourTable’ UNION ALL SELECT fk.name AS ForeignKeyName, ‘Incoming’ AS RelationshipType, sch_parent.name AS FromSchema, t_parent.name AS FromTable, c_parent.name AS FromColumn, sch_ref.name AS ToSchema, t_ref.name AS ToTable, c_ref.name AS ToColumn FROM sys.foreign_keys fk INNER JOIN sys.foreign_key_columns fkc ON fk.object_id = fkc.constraint_object_id INNER JOIN sys.tables t_parent ON fkc.parent_object_id = t_parent.object_id INNER JOIN sys.schemas sch_parent ON t_parent.schema_id = sch_parent.schema_id INNER JOIN sys.columns c_parent ON fkc.parent_object_id = c_parent.object_id AND fkc.parent_column_id = c_parent.column_id INNER JOIN sys.tables t_ref ON fkc.referenced_object_id = t_ref.object_id INNER JOIN sys.schemas sch_ref ON t_ref.schema_id = sch_ref.schema_id INNER JOIN sys.columns c_ref ON fkc.referenced_object_id = c_ref.object_id AND fkc.referenced_column_id = c_ref.column_id WHERE t_ref.name = ‘YourTable’ ORDER BY RelationshipType, ForeignKeyName; “` — ### Optional: include only one schema If you have duplicate table names across schemas, add: “`sql AND sch_parent.name = ‘dbo’ “` or “`sql AND sch_ref.name = ‘dbo’ “` — If you want, I can also give you: 1. a **recursive dependency query** (to trace multiple levels deep), or 2. a **diagram-friendly result** showing table-to-table relationships only.

Lågt vattentryck hemma är ett vanligt problem som kan märkas i duschen, vid kökskranen eller när flera tappställen används samtidigt.

Läs mer »

Kontakta oss idag!