SQLCookBook-元数据查询

列出模式中的表

查询一个包含着数据库中所有表名称的系统表

select table_name
    from information_scheam.tables
where table_schema = 'SMEAGOL'

列出表的列

列出表的各列,它们的数据类型,以及这些列在表中的位置。

select column_name, data_type, ordinary_position
    from information_schema.columns
where table_schema = 'SMEAGOL'
    and table_name = 'EMP'

列出表的索引列

列出给定表的索引、索引的列及这些列在索引中的位置(如果可能)。

show index from emp

列出表约束

列出某模式中对某表定义的约束以及这些约束所基于的列。例如,要查找表emp中的约束及约束所基于的列

select a.table_name,
        a.constriant_anme,
        b.column_name,
        a.constraint_type
    from information_schema.table_constraints a,
        information_schema.key_column_uwsge b
    where a.table_name = 'EMP'
        and a.table_schema = 'SMEAGOL'
        and a.table_name = b.table_name
        and a.table-schema = b.table_schema
        and a.constraint_name = b.constraint_name

列出没有相应索引的外键

列出含有没有被索引的外键的表。

show index
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值