在PostgreSQL中创建表时在列中添加注释? [英] Adding comment to column when I create table in PostgreSQL?

查看:3782
本文介绍了在PostgreSQL中创建表时在列中添加注释?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在PostgreSQL的列中添加注释?

How can I add comment to column in PostgreSQL?

create table session_log (
                UserId int index not null,
                PhoneNumber int index); 


推荐答案

使用 评论语句

create table session_log 
( 
   userid int not null, 
   phonenumber int
); 

comment on column session_log.userid is 'The user ID';
comment on column session_log.phonenumber is 'The phone number including the area code';

您还可以在表格中添加评论:

You can also add a comment to the table:

comment on table session_log is 'Our session logs';

另外: int索引无效。

如果要在列上创建索引,请执行使用 create index 语句

If you want to create an index on a column, you do that using the create index statement:

create index on session_log(phonenumber);

如果要在两个列上都使用索引,请使用:

If you want an index over both columns use:

create index on session_log(userid, phonenumber);

您可能想将userid定义为主键。这是使用以下语法(而不是使用 int索引)完成的:

You probably want to define the userid as the primary key. This is done using the following syntax (and not using int index):

create table session_log 
( 
   UserId int primary key, 
   PhoneNumber int
); 

将列定义为主键会隐式地使其变为不为空

Defining a column as the primary key implicitly makes it not null

这篇关于在PostgreSQL中创建表时在列中添加注释?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆