在 PostgreSQL 中创建 table 时向列添加注释?
Adding comment to column when I create table in PostgreSQL?
如何向 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';
您还可以在 table 中添加评论:
comment on table session_log is 'Our session logs';
另外:int index
无效。
如果你想在列上创建索引,你这样做 using the create index
statement:
create index on session_log(phonenumber);
如果你想在两列上建立索引,请使用:
create index on session_log(userid, phonenumber);
您可能想将用户标识定义为主键。这是使用以下语法完成的(而不是使用 int index
):
create table session_log
(
UserId int primary key,
PhoneNumber int
);
将列定义为主键隐式使其成为 not null
如何向 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';
您还可以在 table 中添加评论:
comment on table session_log is 'Our session logs';
另外:int index
无效。
如果你想在列上创建索引,你这样做 using the create index
statement:
create index on session_log(phonenumber);
如果你想在两列上建立索引,请使用:
create index on session_log(userid, phonenumber);
您可能想将用户标识定义为主键。这是使用以下语法完成的(而不是使用 int index
):
create table session_log
(
UserId int primary key,
PhoneNumber int
);
将列定义为主键隐式使其成为 not null