Results 1 to 3 of 3
  1. #1
    Join Date
    Dec 2008
    Posts
    53

    Unanswered: table which has structure like other table

    I have table:
    COUNTRY
    id_country
    country


    I have table Country. Is it possible to create table Country2 which has structure of table Country without writing what columns have table Country - because I have now:

    Code:
    create procedure create_table
    (
    IN table_name varchar(50),
    IN sentence long varchar(200)
    )
    begin
    declare new_table_name varchar(50);
    set new_table_name = table_name || '2';
    
    execute immediate 'create table ' || new_table_name || '(' || sentence || ');';
    
    end;
    
    
    call create_table('country','id_country integer, country varchar(40), Primary Key (id_country)');

    If I have other table for example 'city' I will have to write in calling this procedure all columns which have this table:
    Code:
    call create_table('city','________________');
    Is other way ?

  2. #2
    Join Date
    Jan 2004
    Posts
    545
    Provided Answers: 4
    Use select into:
    select * into new_table_name from country where 1 = 0

    That creates an emtpy table with the same structure as table 'country'. If you want to copy the records too, leave the where-clause out of it.
    I'm not crazy, I'm an aeroplane!

  3. #3
    Join Date
    Dec 2008
    Posts
    53
    thx you

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •