已知有3张表,每张表都有自己独有的字段,例如下:
table1
  f1 f2 f3
table2
  f2 f3 f4
table3
  f3 f4 f5
请问sql如何写使得3张表的字段都修改为f1 f2 f3 f4 f5?即在每张表里都加上自己没有而另外2张表中存在的字段。
希望过程尽量可扩展,可以分步,但最好少些 因为需要操作的表比较多
谢谢~~

解决方案 »

  1.   

    这个使用数据字典信息加上动态SQL来实现. 
      

  2.   


     for 这几张表 
         声明游标 定义为select distinct cname,coltype,width from col where tname in ('TEST_B','TEST_A'...) and cname not in (select cname from col where tname = '某张表')   然后把游标里的每个值拼成'alter table '||'表名'||' Add('||cname||' '||coltype||'('||width ||'))'
    最后再执行一下...