2021年1月9日 星期六

[研究][C#]取回DB Schema

[研究][C#]取回DB Schema 

2021-01-09

SqlConnection.GetSchema 方法

https://docs.microsoft.com/zh-tw/dotnet/api/system.data.sqlclient.sqlconnection.getschema?view=dotnet-plat-ext-5.0

執行結果

Schema Information of All Tables:
TABLE_CATALOG       TABLE_SCHEMA        TABLE_NAME          TABLE_TYPE
MySchool            dbo                 Course              BASE TABLE
MySchool            dbo                 Department          BASE TABLE

Schema Information of Course Tables:
TABLE_CATALOG       TABLE_SCHEMA        TABLE_NAME          TABLE_TYPE
MySchool            dbo                 Course              BASE TABLE

Schema Information of All Columns:
TableCatalog   TABLE_SCHEMA   TABLE_NAME     COLUMN_NAME    DATA_TYPE
MySchool       dbo            Course         CourseID       nvarchar
MySchool       dbo            Course         Year           smallint
MySchool       dbo            Course         Title          nvarchar
MySchool       dbo            Course         Credits        int
MySchool       dbo            Course         DepartmentID   int
MySchool       dbo            Department     DepartmentID   int
MySchool       dbo            Department     Name           nvarchar
MySchool       dbo            Department     Budget         money
MySchool       dbo            Department     StartDate      datetime
MySchool       dbo            Department     Administrator  int

Schema Information of DepartmentID Column in Course Table:
TableCatalog   TABLE_SCHEMA   TABLE_NAME     COLUMN_NAME    DATA_TYPE
MySchool       dbo            Course         DepartmentID   int

Schema Information of All IndexColumns:
table_schema  table_name column_name   constraint_schema constraint_name KeyType
dbo           Course     CourseID      dbo               PK_Course       231
dbo           Course     Year          dbo               PK_Course       52
dbo           Department DepartmentID  dbo               PK_Department   56

Index Schema Information of CourseID Column in Course Table:
table_schema  table_name column_name   constraint_schema constraint_name KeyType
dbo           Course     CourseID      dbo               PK_Course       231

Please press any key to exit...

(完)

相關

[研究] 用SQL指令找出資料庫的資料表、欄位名、PK欄位、資料筆數

http://shaurong.blogspot.com/2016/02/sqlpk.html


沒有留言:

張貼留言