Adding comment to column when I create table in PostgreSQL?

好久不见. 提交于 2019-12-03 00:54:37

Comments are attached to a column using 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';

You can also add a comment to the table:

comment on table session_log is 'Our session logs';

Additionally: int index is invalid.

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

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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!