| 

.NET C# Java Javascript Exception

2
Servus,

hat jemand eine Idee wie ich per .NET aus einer SQL SVR 2008 DB alle Beziehungen zwischen den Tabellen auslesen kann? Vielleicht per SMO?

Gruß,
Thomas
14.04.2014
Thomas Sczyrba 1,4k 1 2 9
1 Antwort
0
Problem gelöst :D

SELECT f.name                                                     AS ForeignKey,
Schema_name(f.SCHEMA_ID) SchemaName,
Object_name(f.parent_object_id) AS TableName,
Col_name(fc.parent_object_id, fc.parent_column_id) AS ColumnName,
Schema_name(o.SCHEMA_ID) ReferenceSchemaName,
Object_name (f.referenced_object_id) AS ReferenceTableName,
Col_name(fc.referenced_object_id, fc.referenced_column_id) AS ReferenceColumnName
FROM sys.foreign_keys AS f
INNER JOIN sys.foreign_key_columns AS fc ON f.OBJECT_ID = fc.constraint_object_id
INNER JOIN sys.objects AS o ON o.OBJECT_ID = fc.referenced_object_id


Quelle:
http://blog.sqlauthority.com/2009/02/26/sql-server-2008-find-relationship-of-foreign-key-and-primary-key-using-t-sql-find-tables-with-foreign-key-constraint-in-database/
14.04.2014
Thomas Sczyrba 1,4k 1 2 9

Stelle deine Sql-Frage jetzt!