查询服务器中所有数据库表的列和大小

时间:2019-05-04 21:44:54

标签: sql sql-server

我需要从服务器查询所有数据库,表,列和每个表的行数。

下面的代码几乎可以满足我的需要,只对单个数据库有效。我需要此输出并为数据库名称添加一列。而且它可以在所有数据库上运行,而不仅仅是一个命名数据库。还需要每个表的记录数

protected override void OnCreate(Bundle savedInstanceState) {
    base.OnCreate(savedInstanceState);

    var rl = new RelativeLayout(this);
    var iv = new ImageView[5];

    for (int i = 0; i < iv.Length; i++) {
        iv[i] = new ImageView(this);
        iv[i].SetImageResource(Resource.Drawable.Icon);
        iv[i].Id = View.GenerateViewId();
        var ivParms = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.WrapContent, ViewGroup.LayoutParams.WrapContent);
        if (i == 0)
            ivParms.AddRule(LayoutRules.AlignTop);      // Apply to 1st image only
        else
            ivParms.AddRule(LayoutRules.Below, iv[i-1].Id);  // This is only to be applied to the 2nd and subsequent images
        iv[i].LayoutParameters = ivParms;
        rl.AddView(iv[i]);
    }

    SetContentView(rl);
}

当前输出:

USE [temp_db]; 

SELECT 
    OBJECT_SCHEMA_NAME(T.[object_id],DB_ID()) AS [Schema],   
    T.[name] AS [table_name], AC.[name] AS [column_name],   
    TY.[name] AS system_data_type, AC.[max_length],  
    AC.[precision], AC.[scale], AC.[is_nullable], AC.[is_ansi_padded]  
FROM
    sys.[tables] AS T   
INNER JOIN 
    sys.[all_columns] AC ON T.[object_id] = AC.[object_id]  
INNER JOIN 
    sys.[types] TY ON AC.[system_type_id] = TY.[system_type_id] 
                   AND AC.[user_type_id] = TY.[user_type_id]   
WHERE 
    T.[is_ms_shipped] = 0  
ORDER BY 
    T.[name], AC.[column_id]

我需要的输出是:

Schema|table_name|column_name|system_data_type|max_length|precision|scale|is_nullable|is_ansi_padded

0 个答案:

没有答案