日期:2014-05-17 浏览次数:20932 次
create table t1(id int,name varchar2(20),age int);
create table t2(id int,name varchar2(20),age int);
insert into t1 values(1,'sms1',20);
insert into t1 values(2,'sms2',20);
insert into t2 values(1,'sms',20);
create or replace view v_t1t2
as
select t1.id t1_id,t1.name t1_name,t1.age t1_age, t2.id t2_id,t2.name t2_name,t2.age t2_age from t1,t2 where t1.id=t2.id;
select * from v_t1t2;
insert into v_t1t2 values(11,'sms11',20,11,'sms11',20) --多表连接的视图要做dml操作时,必须要有key-preserved table
ORA-01779: cannot modify a column which maps to a non key-preserved table
delete from v_t1t2
ORA-01752: cannot delete from view without exactly one key-preserved table
update v_t1t2 set t1_name='dba' where t1_id=1
ORA-01779: cannot modify a column which maps to a non key-preserved table
--添加一个主键
我在t1上添加了主键,oracle怎么把t2表上的数据删除了,update和insert的时候为什么又提示没有关联到key-preserved table?????
alter table t1 add constraint pk_t1_id primary key (id);
insert into v_t1t2 values(11,'sms11',20,11,'sms11',20)
ORA-01779: cannot modify a column which maps to a non key-preserved table
update v_t1t2 set t1_name='dba' where t1_id=1
ORA-01779: cannot modify a column which maps to a non key-preserved table
SQL> delete from v_t1t2 ;
1 row deleted
SQL> select * from t1;
ID NAME AGE
--------------------------------------- -------------------- ---------------------------------------
1 sms1 20
2 sms2