oracle在建表时如何指定主键的索引名和主键的表空间

来源:百度知道 编辑:UC知道 时间:2024/05/13 01:22:09
例如建1个表:
create table tmp(
MON VARCHAR2(6) ,
IDNO VARCHAR2(10) ,
primary key ( MON, IDNO )
) ;
oracle会自动给主键起个索引名,但我想自己指定主键的索引名,
而且我想指定主键所在的表空间为index_stat
那么上面的语句应该怎么改?
下面这种语句也想这样,应该怎么改?
create table tmp(
MON VARCHAR2(6) primary key ,
IDNO VARCHAR2(10) primary key
) ;

在创建表时,只能指定主键与唯一键的索引表空间,其它类型的索引,只能通过CREATE INDEX/ALTER INDEX来指定。
  参考如下:
create table test1
(id number(10),
name varchar2(20),
age number(3),
constraint pk_test1 primary key(id) using index tablespace tbs_ind
)
tablespace tbs_cur;

假设你的表空间index_stat 用户名称为scott
create table scott.tmp(
MON VARCHAR2(6) ,
IDNO VARCHAR2(10) ,
primary key ( MON, IDNO )
) ;
自动生成的那个索引好像是不能改的,不过你可以给主键指定新的索引,语法如下:
alter table 表名 add constraints 索引名 primary key using index ...

或者直接使用create语句,例子如下:
create unique index tmp_PK on scott.tmp (
MON ASC,
IDNO ASC
);

我想不用那么麻烦吧!

两个都一样:

create table tmp(

MON VARCHAR2(6) ,

IDNO VARCHAR2(10) ,

constraint pk_tmp primary key ( MON, IDNO )

using index tablespace index_stat

) ;

create table tmp(
MON VARCHAR2(6) ,
ID