MCPcopy Create free account
hub / github.com/bytebase/dbhub / getTableComment

Method getTableComment

src/connectors/sqlserver/index.ts:442–475  ·  view source on GitHub ↗
(tableName: string, schema?: string)

Source from the content-addressed store, hash-verified

440 }
441
442 async getTableComment(tableName: string, schema?: string): Promise<string | null> {
443 if (!this.connection) {
444 throw new Error("Not connected to SQL Server database");
445 }
446
447 try {
448 const schemaToUse = schema || "dbo";
449
450 const request = this.connection
451 .request()
452 .input("tableName", sql.VarChar, tableName)
453 .input("schema", sql.VarChar, schemaToUse);
454
455 const query = `
456 SELECT ep.value as table_comment
457 FROM sys.extended_properties ep
458 JOIN sys.tables t ON ep.major_id = t.object_id
459 JOIN sys.schemas s ON t.schema_id = s.schema_id
460 WHERE ep.minor_id = 0
461 AND ep.name = 'MS_Description'
462 AND t.name = @tableName
463 AND s.name = @schema
464 `;
465
466 const result = await request.query(query);
467
468 if (result.recordset.length > 0) {
469 return result.recordset[0].table_comment || null;
470 }
471 return null;
472 } catch (error) {
473 return null;
474 }
475 }
476
477 async getStoredProcedures(schema?: string, routineType?: "procedure" | "function"): Promise<string[]> {
478 if (!this.connection) {

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected