创建索引 [英] Creation of index

查看:91
本文介绍了创建索引的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在sql中创建表后如何在主键上创建索引?

How to create index on primary key after creation of table in sql?

推荐答案

如果您使用主键约束创建了表,那么您在属于PK的字段上已经具有唯一索引;该索引是在添加PK约束时创建的,其名称不具有任何含义:

If you created the table with the primary key constraint, then you already have a unique index on the fields belonging to the PK; this index has been created when you added the PK constraint and has a not significative name:

SQL> create table TEST_PK_IDX(id number primary key, descr varchar2(100));

Table created.

SQL> select index_name, uniqueness, column_name
  2  from user_ind_columns c
  3         inner join user_indexes i
  4           using (index_name)
  5  where i.table_name = 'TEST_PK_IDX';

INDEX_NAME           UNIQUENESS           COLUMN_NAME
-------------------- -------------------- --------------------
SYS_C007838          UNIQUE               ID

但是,如果需要创建其他索引,则可以使用:

However, if you need to create a different index, you can use:

SQL> create index idx_test on test_pk_idx(descr);

Index created.

SQL> select index_name, uniqueness, column_name
  2  from user_ind_columns c
  3         inner join user_indexes i
  4           using (index_name)
  5  where i.table_name = 'TEST_PK_IDX';

INDEX_NAME           UNIQUENESS           COLUMN_NAME
-------------------- -------------------- --------------------
SYS_C007838          UNIQUE               ID
IDX_TEST             NONUNIQUE            DESCR

SQL>

这篇关于创建索引的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆