MYSQL ORACLE 查询表名及字段--封装代码自动生成时用

1. mysql查询所有表、视图
SELECT
table_name as tablename,
table_comment as tablecomment
FROM
information_schema.TABLES

2. mysql查询列信息
SELECT
mysql' dialect,
TABLE_NAME AS tablename,
COLUMN_NAME AS columnname,
DATA_TYPE AS datatype,
CHARACTER_MAXIMUM_LENGTH AS cml,
COLUMN_COMMENT AS columncomment,
CASE COLUMN_KEY WHEN 'PRI' THEN 1 WHEN 'MUL' THEN 2 END AScolumnkey
FROM
information_schema.COLUMNS

3. ORACLE查询所有表、视图 
select 
table_name as "tablename",
table_type as "tabletype",
comments as "tablecomment" 
from user_tab_comments

4. ORACLE查询表的列信息
SELECT
    'oracle' dialect,
    utc.table_name AS tablename,
    utc.column_name AS columnname,
    utc.data_type AS datatype,
    utc.data_length AS cml,
    ucc.comments AS columncomment,
        CASE ucon.constraint_type
            WHEN 'P'   THEN '1'
            WHEN 'R'   THEN '2'
            ELSE ''
        END
    AS columnkey
FROM
    user_tab_columns utc
    LEFT JOIN user_col_comments ucc ON
        ucc.column_name = utc.column_name
    AND
        ucc.table_name = utc.table_name
    LEFT JOIN (
        SELECT
            cu.*,
            au.constraint_type
        FROM
            user_cons_columns cu,
            user_constraints au
        WHERE
                cu.constraint_name = au.constraint_name
            AND
                au.constraint_type IN (
                    'P','R'
                )
    ) ucon ON
        ucon.table_name = utc.table_name
    AND
        ucon.column_name = utc.column_name
WHERE
    utc.table_name = 'TABLENAME'
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值