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

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

推荐答案

使用the comment statement将注释附加到一列:

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';

您还可以向表中添加注释:

comment on table session_log is 'Our session logs';

另外:int index无效.

如果要在列上创建索引,请执行以下操作:

create index on session_log(phonenumber);

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

create index on session_log(userid, phonenumber);

您可能希望将userid定义为主键.这是使用以下语法完成的(而不是使用int index):

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

将列定义为主键会使其隐式为not null

Postgresql相关问答推荐

使用RANGE窗口框架条款将SUM分析函数从PostgreSQL移至Redwitch

如何在Common Lisp中使用Postmodern在表更改时获得通知?

为MCV扩展统计设置统计目标

Postgres 使用不同元素数据类型的订单数据

正在加载 pgAdmin 4 v7.4...同时打开 pgAdmin

Npgsql中准备好的语句和参数化查询有什么区别?

如何包装 record_out() 函数?

从 Postgres 字段中的多个值中进行 Select

当脚本工作时,Postgres now() 时间戳不会改变

PostgreSQL 在 mySQL 中的 date_trunc

SQL数据库表中的多态性?

Postgres 在 WHERE id != int 查询中排除 NULL

PostgreSQL CASE 在函数中的使用

在 PostgreSQL 中的表上禁用 DELETE?

如何将表的一列复制到PostgreSQL中比较相同ID的另一表的列

FOR EACH STATEMENT 触发器示例

PostgreSQL:如果不存在则创建表 AS

Android 的 JDBC 与 Web 服务

PostgreSQL - 如何在不同时区呈现日期?

pg_restore 目录错误