Recipe 5.6. Using SQL to Generate SQL

wuxidba發表於2010-12-07
 select 'select count(*) from '||table_name||';' cnts
  from user_tables;


CNTS
----------------------------------------
select count(*) from ANT;
select count(*) from BONUS;
select count(*) from DEMO1;
select count(*) from DEMO2;
select count(*) from DEPT;
select count(*) from DUMMY;
select count(*) from EMP;
select count(*) from EMP_SALES;
select count(*) from EMP_SCORE;
select count(*) from PROFESSOR;
select count(*) from T;
select count(*) from T1;
select count(*) from T2;
select count(*) from T3;
select count(*) from TEACH;
select count(*) from TEST;
select count(*) from TRX_LOG;
select count(*) from X;

/* disable foreign keys from all tables */


select 'alter table '||table_name||
       ' disable constraint '||constraint_name||';' cons
  from user_constraints
where constraint_type = 'R';


CONS
------------------------------------------------
alter table ANT disable constraint ANT_FK;
alter table BONUS disable constraint BONUS_FK;
alter table DEMO1 disable constraint DEMO1_FK;
alter table DEMO2 disable constraint DEMO2_FK;
alter table DEPT disable constraint DEPT_FK;
alter table DUMMY disable constraint DUMMY_FK;
alter table EMP disable constraint EMP_FK;
alter table EMP_SALES disable constraint EMP_SALES_FK;
alter table EMP_SCORE disable constraint EMP_SCORE_FK;
alter table PROFESSOR disable constraint PROFESSOR_FK;
/* generate an insert script. from some columns in table EMP */

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/23895263/viewspace-681084/,如需轉載,請註明出處,否則將追究法律責任。

相關文章