【问题标题】:Is there a SQL equivalent of pandas df.info()?是否有与 pandas df.info() 等效的 SQL?
【发布时间】:2022-01-21 09:58:34
【问题描述】:

我只是想知道是否有一个简短的 SQL 查询与 Python 中的 pandas df.info() 函数的工作方式相同?快速返回表元数据的东西。

【问题讨论】:

  • 在哪个数据库管理器中?它们中的大多数都有某种可以收集此类信息的系统表,但它们的名称和布局并不标准化。此外,如果您的数据库接口实现了 DB-API(大多数都实现了),那么游标上的 .description 属性可能会很有趣。

标签: python sql pandas


【解决方案1】:

以下应该可以工作:

select schema_name(tab.schema_id) as schema_name,
    tab.name as table_name, 
    col.column_id,
    col.name as column_name, 
    t.name as data_type,    
    col.max_length,
    col.precision
from sys.tables as tab
    inner join sys.columns as col
        on tab.object_id = col.object_id
    left join sys.types as t
    on col.user_type_id = t.user_type_id
order by schema_name,
    table_name, 
    column_id;

【讨论】:

    【解决方案2】:

    如果您想从 sql server 中提取详细信息,那么 information_schema 对象会有所帮助

    select * from information_schema.tables t
    join information_schema.columns c on t.table_name = c.table_name
    where t.table_name = '<your table name>'
    

    【讨论】:

      猜你喜欢
      • 2017-11-09
      • 2016-02-17
      • 2010-12-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-08-18
      相关资源
      最近更新 更多