I need to get the following information for each table in the database:
- All column names
- For each column, its type
- Type of maximum length
A possible way to do this is to run the request (even execute it using await, i.e. async):
select object_NAME(c.object_id), c.name, t.name, c.max_length
from sys.columns c
INNER JOIN sys.types t
ON t.system_type_id = c.system_type_id
On the other hand, there is a GetSchema method on connection that does the same:
DataTable columns = connection.GetSchema(SqlClientMetaDataCollectionNames.Columns, restrictions);
foreach (DataRow row in columns.Rows)
{
string columnName = row[3].ToString();
string columnDataType = row[7].ToString();
string columnDataTypeLen = row[8].ToString();
}
Which method is better to use? It looks like the second should be faster - am I right? What about performance?
Yakov source
share