怎么将两表中将g_id为43…的数据的g_state同时改为'07'试了好多方法都都不行
SQL 语句:
update t_mc_type t,t_mc b set t.sname='耐用',b.sname='耐磨3100' where t.nid=4 and b.nminid=t.nid;
这个语句不行,请教各位高手。
SQL 语句:
update t_mc_type t,t_mc b set t.sname='耐用',b.sname='耐磨3100' where t.nid=4 and b.nminid=t.nid;
这个语句不行,请教各位高手。
你想,即使在同一个sql语句里更新,日后维护多麻烦
建议写成过程
除非你用事务去完成.
最不好的方法:
begin
update table1 set g_state='07' where g_id=43
commit;
update table2 set g_state='07' where g_id=43
commit;
end;
这个实验中:
update table1 a, table2 b set a.g_state='07',b.g_state='07' where a.g_id=b.g_id and
b.g_id='43';
pl_sql
估计都是虾米级别的!
如果要放到一个sql中,就需要建一个视图将两表关联起来,建一个替代触发器。或者像7楼说的,建一个触发器来解决,当更新一张表时,自动更新另外一张
不过oracle好象不支持?
面试这种题意义不大,有点象考别人回字的四种写法