title: Is that possible the copy all table on same schema in plsql
body: <p>Is that possible to write copy all table include <strong>(data ,pk , fk .....)</strong> scripts on same schema with all object ?
  When I run the code below<br>
  <code>create table testmember as (select * from member);</code></p>
  
  <p>I can only bring table data . When i executed this code  i did not see table keys ( FK , PK ) please somebody show me a way</p>
  
  <p>UPDATE----
  Hı  i create all tables with data you can test it but be carrefully :) 
  In my question again how can i add pk with this table ? </p>
  
  <pre><code>    declare 
        Procedure test_copy_table is 
         sqlString VARCHAR2(2000) := '';
            Cursor tables is
           select * from user_tables;
        begin
          for rec in tables
           loop
           dbms_output.put_line(rec.table_name);
         sqlString:='CREATE TABLE T_' ||rec.table_name || ' AS (SELECT * FROM ' ||rec.table_name|| ')';
    dbms_output.put_line(sqlString);
    execute immediate sqlString;
    end loop;
     end;
  begin
    test_copy_table();
   end;`
  </code></pre>
  
  <p>In this code part create all tables with data as i said before please add some more clear information.UPDATE---</p>
  
  <p>Hı ı can get all primery key you can see below code thx for helpinn. This scripts helps you Thx for helping resolved. </p>
  
  <pre><code> procedure copy_pk_same_schema is
  put_semicolumn varchar2(1);
    begin
  
  for uc in (select *
               from user_constraints
              where constraint_name not like 'BIN$%'
                and constraint_name not like 'SYS_%'
                and constraint_type = 'P') loop
    -- dbms_output.put_line('--table/pk: ' || uc.table_name || ' ' ||
    --     uc.constraint_name);
  
    --   dbms_output.put_line('alter table T_' || uc.table_name || ' drop constraint ' || uc.constraint_name||';');
    if LENGTH('T_' || uc.table_name) &gt; 30 then
      dbms_output.put_line('alter table T_' ||
                           substr(uc.table_name,
                                  1,
                                  (length(uc.table_name) - 5)) ||
                           ' add constraint');
    else
      dbms_output.put_line('alter table T_' || uc.table_name ||
                           ' add constraint');
    end if;
  
    if LENGTH('T_' || uc.constraint_name) &gt; 30 then
      dbms_output.put_line('T_' ||
                           substr(uc.constraint_name,
                                  1,
                                  (length(uc.constraint_name) - 5)) ||
                           ' primary key (');
    else
      dbms_output.put_line('T_' || uc.constraint_name ||
                           ' primary key (');
    end if;
  
    put_semicolumn := 'F';
    for pk in (select *
                 from user_cons_columns
                where constraint_name not like 'BIN$%'
                  and table_name = uc.table_name
                  and constraint_name = uc.constraint_name
                order by constraint_name, position) loop
      if put_semicolumn = 'F' then
        dbms_output.put_line(pk.column_name);
        put_semicolumn := 'T';
      else
        dbms_output.put_line(',' || pk.column_name);
      end if;
    end loop;
  
    dbms_output.put_line(');');
  end loop;
  end;
  </code></pre>