Jun 16, 2014

MySQL script to generate a ASCII-table of a database schema

Run this in the command line client (interactive mysql program):
-- References: http://dev.mysql.com/doc/refman/5.0/en/columns-table.html
use information_schema;
select table_name 'Table', column_name 'Column', column_key 'Index', column_type 'Type',
if (IS_NULLABLE = 'NO', if(column_default IS NULL, '', column_default), 'NULL') 'Default', column_comment 'Comment'
from columns where table_schema = '$DB_NAME';
Replace $DB_NAME by your own name. Japanese version:
-- References: http://dev.mysql.com/doc/refman/5.0/en/columns-table.html
use information_schema;
select table_name 'フィール', column_name '論理名', column_key 'インデックス', column_type '型',
if (IS_NULLABLE = 'NO', if(column_default IS NULL, '', column_default), 'NULL') 'デフォルト', column_comment '備考'
from columns where table_schema = '$DB_NAME';

No comments:

Post a Comment

New comment