mysql-View table structure, create table statement and compare with oracle (transfer)

Original address: http://my.oschina.net/zimingforever/blog/64145

 

1. View the table structure

desc tableName;
show columns from tableName;
describe tableName;

    The three displayed results are the same, showing filed, type, null, key, default and extra in the table.

 

--TABLE_SCHEMA indicates the database name
select * from information_schema.COLUMNS where TABLE_SCHEMA='gm' and TABLE_NAME='t_role';

    The displayed results are more complete.  

 

2. View the table creation statement

   show create table tableName;

 

3. Next, come to a more complete sql, this is all the sql used to synchronize the mysql and orac data dictionaries.

    mysql part:

## View all libraries
SELECT
    lower(schema_name) schema_name
FROM
    information_schema.schemata
WHERE
    schema_name NOT IN (
        'mysql',
        'information_schema',
        'test',
        'search',
        'tbsearch',
        'sbtest',
        'dev_ddl'
    )
 
## View all tables in a library
SELECT
    table_name,
    create_time updated_at,
    table_type,
    ENGINE,
    table_rows num_rows,
    table_comment,
    ceil(data_length / 1024 / 1024) store_capacity
FROM
    information_schema.TABLES
WHERE
    table_schema = 'employees'
AND table_name NOT LIKE 'tmp#_%' ESCAPE '#'
 
##View all fields of a table under a library
SELECT
    lower(column_name) column_name,
    ordinal_position position,
    column_default dafault_value,
    substring(is_nullable, 1, 1) nullable,
    column_type data_type,
    column_comment,
    character_maximum_length data_length,
    numeric_precision data_precision,
    numeric_scale data_scale
FROM
    information_schema.COLUMNS
WHERE
    table_schema = 'employees'
AND table_name = 'employees';
 
 
## View the index of a table under a library
 
SELECT DISTINCT
    lower(index_name) index_name,
    lower(index_type) type
FROM
    information_schema.statistics
WHERE
    table_schema = 'employees'
AND table_name = 'employees';
 
## View an index of a table under a library
 
SELECT
    lower(column_name) column_name,
    seq_in_index column_position
FROM
    information_schema.statistics
WHERE
    table_schema = 'employees'
AND table_name = 'employees'
AND index_name = 'primary';
 
## View the comments of a table under a library
SELECT
    table_comment comments
FROM
    information_schema.TABLES
WHERE
    table_schema = 'employees'
AND table_name = 'employees';
 
## View the comments of a column of a table under a library
SELECT
    lower(column_name) column_name,
    column_comment comments
FROM
    COLUMNS
WHERE
    table_schema = 'employees'
AND table_name = 'employees';

   oracle part:

#table structure:
SELECT
    lower(table_name) table_name,
    TEMPORARY,
    tablespace_name,
    num_rows,
    duration,
    'ORACLE' table_type,
    partitioned,
    (
        SELECT
            ceil(sum(bytes) / 1024 / 1024)
        FROM
            dba_segments b
        WHERE
            a. OWNER = b. OWNER
        AND a.table_name = b.segment_name
    ) AS store_capacity
FROM
    dba_tables a
WHERE
    OWNER = ?
AND table_name NOT LIKE 'TMP%';
 
SELECT
    lower(column_name) column_name,
    column_id position,
    data_type,
    data_length,
    data_precision,
    data_scale,
    nullable,
    data_default default_value,
    default_length
FROM
    dba_tab_columns
WHERE
    OWNER = ?
AND table_name = ?;
 
# index
SELECT
    lower(index_name) index_name,
    index_type type
FROM
    dba_indexes
WHERE
    OWNER = ?
AND table_name = ?
AND index_name NOT LIKE 'SYS_IL%';
 
SELECT
    lower(column_name) column_name,
    column_position,
    descend
FROM
    dba_ind_columns
WHERE
    table_owner = ?
AND table_name = ?
AND index_name = ?;
 
#collect description
SELECT
    comments
FROM
    dba_tab_comments
WHERE
    OWNER = ?
AND table_name = ?;
 
SELECT
    lower(column_name) column_name,
    comments
FROM
    dba_col_comments
WHERE
    OWNER = ?
AND table_name = ?;
 
#database
SELECT
    lower(username) username
FROM
    dba_users
WHERE
    username NOT IN (
        'STDBYPERF',
        'READONLY',
        'APPQOSSYS',
        'ANYSQL',
        'DBFLASH',
        'SYS',
        'SYSTEM',
        'MONITOR',
        'TBSEARCH',
        'MANAGER',
        'SYSMAN',
        'EXFSYS',
        'WMSYS',
        'DIP',
        'TSMSYS',
        'ORACLE_OCM',
        'OUTLN',
        'DBSNMP',
        'PERFSTAT',
        'SEARCH',
        'TOOLS',
        'TBDUMP',
        'DMSYS',
        'XDB',
        'ANONYMOUS',
        'DEV_DDL'
    );
 
#segsize
SELECT
    round(sum(bytes) / 1024 / 1024, 0) mbytes
FROM
    dba_segments
WHERE
    OWNER = ?
AND segment_name = ?;

 

 

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=327026342&siteId=291194637