温馨提示×

怎么在postgresql中创建索引

养鱼的猫咪
1795
2021-04-27 09:25:58
栏目: 云计算

在postgresql中创建索引的方法:1.启动postgresql服务;2.登录postgresql数据库;3.使用数据库;4.在数据库新建表;5.使用CREATE INDEX命令创建索引;

怎么在postgresql中创建索引

具体步骤如下:

1.首先,在命令行中启动postgresql服务;

net start postgresql

2.postgresql服务启动后,在命令行中登录到postgresql数据库;

psql -h -U

3.登录到postgresql数据库后,在postgresql选择一个数据库并使用;

\c text

4.进入到数据库后,在数据库中新建一个数据表;

create table prefer;

5.最后,数据表创建好后,执行以下命令即可在表中创建索引;

1)创建单列索引

CREATE INDEX index_name on prefer (column_name);

2)创建组合索引

CREATE INDEX index_name on prefer (column1_name, column2_name);

3)创建唯一索引

CREATE UNIQUE INDEX index_name on prefer (column_name);

4)创建局部索引

CREATE INDEX index_name on prefer (conditional_expression);

0