PostgreSQL:可以在CREATE TABLE定义中创建索引吗?

编程入门 行业动态 更新时间:2024-10-26 14:30:55
本文介绍了PostgreSQL:可以在CREATE TABLE定义中创建索引吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我想在创建时向表中的某些列添加索引。有没有办法将它们添加到CREATE TABLE定义中,还是我必须在之后再添加另一个查询?

I want to add indexes to some of the columns in a table on creation. Is there are way to add them to the CREATE TABLE definition or do I have to add them afterward with another query?

CREATE INDEX reply_user_id ON reply USING btree (user_id);

推荐答案

似乎没有任何指定方法 CREATE TABLE 语法的索引。但是,PostgreSQL确实会默认为唯一约束和主键创建索引,如此说明:

There doesn't seem to be any way of specifying an index in the CREATE TABLE syntax. PostgreSQL does however create an index for unique constraints and primary keys by default, as described in this note:

PostgreSQL会自动为每个唯一约束和主键约束创建索引

PostgreSQL automatically creates an index for each unique constraint and primary key constraint to enforce uniqueness.

除此之外,如果您要使用非唯一索引,则需要在单独的创建索引查询。

Other than that, if you want a non-unique index, you will need to create it yourself in a separate CREATE INDEX query.

更多推荐

PostgreSQL:可以在CREATE TABLE定义中创建索引吗?

本文发布于:2023-10-23 18:48:26,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1521707.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:索引   定义   PostgreSQL   CREATE   TABLE

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!