在SQL中字段或列的注释是用属性comment来添加
1. 创建表的时候写注释
create table test1
(
field_name int comment '字段的注释'
)comment='表的注释';
2. 修改表的注释
alter table test1 comment '修改后的表的注释';
3. 修改字段的注释
alter table test1 modify column field_name int comment '修改后的字段注释';
--注意:字段名和字段类型照写就行
4. 查看表注释的方法
--在生成的SQL语句中看
show create table test1;
--在元数据的表里面看
use information_schema;
select * from TABLES where TABLE_SCHEMA='my_db' and TABLE_NAME='test1' \G
5. 查看字段注释的方法
--show
show full columns from test1;
--在元数据的表里面看
select * from COLUMNS where TABLE_SCHEMA='my_db' and TABLE_NAME='test1' \G
例如:hive数据仓库创建表
create EXTERNAL table test_kwu (
dateday string comment "日期:如2015-01-01",
datetime string comment "时间 : 如 11:30:01:123",
ip string comment "IP:用户本机IP或用户所在网段对外路由IP",
cookieid string comment "用户cookie:统一在用户端生成的唯一标志",
userid string comment "用户和讯注册ID :用户在和讯网的注册ID",
logserverip string comment "记录日志服务器IP :日志收集服务器IP",
referer string comment "来源 :用户浏览网页的REFER",
requesturl string comment "访问网址 : 当前访问网址",
remark1 string comment "【暂时没用】 :该数据无意义,由于早期加入目前不能去除",
remark2 string comment "【暂时没用】 : 该数据无意义,由于早期加入目前不能去除",
alexaflag string comment "ALEXA标志 :这个字段也是早期加入,当用户安装alexa工具时值为1,否则为0.早期加入,目前来看应该没有任何意义了。",
ua string comment "UA :用户浏览器UA",
wirelessflag string comment "无线频道标志:给无线频道专用的,一个单词,表示该文章对应和讯哪一个频道"
)
comment "浏览轨迹日志"
partitioned by(day string comment "按天的分区表字段")
ROW FORMAT DELIMITED FIELDS TERMINATED BY ' '
STORED AS TEXTFILE
location '/hive/default/test_kwu'; --注意:此处的路径对应到数据库的路径(去掉 "/hdfs"),后缀加上table的名称。