如何在PostgreSQL中向列添加注释?
create table session_log (
UserId int index not null,
PhoneNumber int index);
如何在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