You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: MssqlMcp/dotnet/MssqlMcp/Tools/DescribeTable.cs
+52-1Lines changed: 52 additions & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -19,7 +19,7 @@ public partial class Tools
19
19
publicasyncTask<DbOperationResult>DescribeTable(
20
20
[Description("Name of table")]stringname)
21
21
{
22
-
stringschema=null;
22
+
string?schema=null;
23
23
if(name.Contains('.'))
24
24
{
25
25
// If the table name contains a schema, split it into schema and table name
@@ -62,6 +62,33 @@ FROM sys.indexes i
62
62
FROM sys.key_constraints kc
63
63
WHERE kc.parent_object_id = (SELECT object_id FROM sys.tables t INNER JOIN sys.schemas s ON t.schema_id = s.schema_id WHERE t.name = @TableName and (s.name = @TableSchema or @TableSchema IS NULL ) )";
64
64
65
+
66
+
conststringForeignKeyInformation=@"SELECT
67
+
fk.name AS name,
68
+
SCHEMA_NAME(tp.schema_id) AS [schema],
69
+
tp.name AS table_name,
70
+
STRING_AGG(cp.name, ', ') WITHIN GROUP (ORDER BY fkc.constraint_column_id) AS column_names,
71
+
SCHEMA_NAME(tr.schema_id) AS referenced_schema,
72
+
tr.name AS referenced_table,
73
+
STRING_AGG(cr.name, ', ') WITHIN GROUP (ORDER BY fkc.constraint_column_id) AS referenced_column_names
74
+
FROM
75
+
sys.foreign_keys AS fk
76
+
JOIN
77
+
sys.foreign_key_columns AS fkc ON fk.object_id = fkc.constraint_object_id
78
+
JOIN
79
+
sys.tables AS tp ON fkc.parent_object_id = tp.object_id
80
+
JOIN
81
+
sys.columns AS cp ON fkc.parent_object_id = cp.object_id AND fkc.parent_column_id = cp.column_id
82
+
JOIN
83
+
sys.tables AS tr ON fkc.referenced_object_id = tr.object_id
84
+
JOIN
85
+
sys.columns AS cr ON fkc.referenced_object_id = cr.object_id AND fkc.referenced_column_id = cr.column_id
86
+
WHERE
87
+
( SCHEMA_NAME(tp.schema_id) = @TableSchema OR @TableSchema IS NULL )
0 commit comments