- 要查询数据库 "mammothcode" 下所有表名以及表注释
/* 查询数据库 ‘mammothcode’ 所有表注释 */
SELECT TABLE_NAME,TABLE_COMMENT FROM information_schema.TABLES WHERE table_schema='mammothcode';
- 要查询表字段的注释
/* 查询数据库 ‘mammothcode’ 下表 ‘t_adminuser’ 所有字段注释 */
SELECT COLUMN_NAME,column_comment FROM INFORMATION_SCHEMA.Columns WHERE table_name='t_adminuser' AND table_schema='mammothcode'
select
COLUMN_NAME '列名',
DATA_TYPE '字段类型',
CHARACTER_MAXIMUM_LENGTH '长度',
IS_NULLABLE '是否为空',
COLUMN_COMMENT '备注' FROM INFORMATION_SCHEMA.COLUMNS where table_name = 'channel_config' AND table_schema='oncopdev'
into outfile 'C:/Users/Windows/Desktop/test.xlsx'
- 一次性查询数据库 "mammothcode" 下表注释以及对应表字段注释
SELECT t.TABLE_NAME,t.TABLE_COMMENT,c.COLUMN_NAME,c.COLUMN_TYPE,c.COLUMN_COMMENT FROM
information_schema.TABLES t,INFORMATION_SCHEMA.Columns c WHERE c.TABLE_NAME=t.TABLE_NAME
AND t.`TABLE_SCHEMA`='mammothcode'
4.添加自增
alter table table_Name modify id int(11) auto_increment;
alter table table_Name auto_increment=1000; --指定自增起始位置
5.查询表列名,并用“,”号隔开
SELECT GROUP_CONCAT(COLUMN_NAME SEPARATOR ",") FROM information_schema.COLUMNS
WHERE TABLE_SCHEMA = 'db_name' AND TABLE_NAME = 'table_name'
- 显示数据库
show databases;
- 使用test数据库
use test;
- 创建表如果存在先删除
drop table if exists table recent_news;
-- 创建表
create table user(
id int primary key auto_increment,
name varchar(100) comment '昵称',
email varchar(100) comment '邮箱',
password varchar(100) default '123456' comment '密码'
);
- 添加表注释
alter table user comment '用户表';
- 添加列注释
alter table user modify column name varchar(100) comment '用户名';
- 设置自增
alter table test AUTO_INCREMENT = 1000;
- 显示所有表
show tables ;
- 查询表结构
show columns from user;
desc user;
describe user;
- 查看字段注释方法
show full columns from td_user;
- 查询指定数据库中指定表的各字段
select * from information_schema.columns where table_name='user' and table_schema='test';
- 查询表列数据
select column_name,column_type,is_nullable,column_default,column_comment from information_schema.columns where table_schema='test' and table_name='user';
网友评论