sql >> Base de Datos >  >> RDS >> Oracle

Vistas materializadas de Oracle con clave principal

es porque su vista materializada se basa en dos tablas, si crea su vista basada en una sola tabla con una clave principal, entonces la clave principal se crea en su vista Materializada. Todavía puede crear el índice después si lo necesita:

SQL> create table t1(id number);

Table created.

SQL> create table t2(id number);

Table created.

SQL> alter table t1 add primary key (id);

Table altered.

SQL> alter table t2 add primary key (id);

Table altered.

SQL> CREATE MATERIALIZED VIEW MyMV
REFRESH COMPLETE ON DEMAND
AS
SELECT t1.*
  FROM t1, t2 where t1.id=t2.id;  2    3    4    5

Materialized view created.

SQL> create unique index myindex on MyMV(id);

Index created.

EDITAR

cree una clave principal en lugar del índice único:

SQL> alter materialized view MyMV add constraint PK_ID primary key (id);

Materialized view altered.

SQL> alter table t3 add constraint FK_TABLE3_MyMV foreign key (id) references MyMV (id);

Table altered.