List:General Discussion« Previous MessageNext Message »
From:joe j Date:April 3 2012 8:27pm
Subject:create multiple tables in a single query
View as plain text  
Dear all,
I need to create over 100 tables each representing a country. Instead
of repeating the commands could I create all tables in one single
query?

The following are two examples of the tables I'd like to create:
1. for USA
CREATE TABLE `US_table_new`
SELECT var1, var2`
, (case when (country='US') then 1 else 0 end) AS US_citizen
FROM `USA_table_old`
LEFT JOIN
WORLD
USING(YEAR);

2. for UK
CREATE TABLE `UK_table_new`
SELECT var1, var2`
, (case when (country='UK') then 1 else 0 end) AS UK_citizen
FROM `UK_table_old`
LEFT JOIN
WORLD
USING(YEAR);

So what I am trying to get is a script that runs through a list of
country names (US, UK, NL, etc) and create tables for each one of them
as above. Is this feasible in MySql?

Thanks,
Joe.
Thread
create multiple tables in a single queryjoe j3 Apr
  • Re: create multiple tables in a single queryhsv4 Apr
    • Re: create multiple tables in a single queryRick James4 Apr
      • Re: create multiple tables in a single queryJohan De Meersman5 Apr
  • Re: create multiple tables in a single queryJohan De Meersman4 Apr
    • Re: create multiple tables in a single queryjoe j4 Apr
      • Re: create multiple tables in a single queryjoe j4 Apr
        • Re: create multiple tables in a single queryJohan De Meersman5 Apr
          • Re: create multiple tables in a single queryjoe j5 Apr
            • Re: create multiple tables in a single queryjoe j5 Apr
              • Re: create multiple tables in a single queryJohan De Meersman6 Apr
        • Re: create more tables in a single queryhsv5 Apr
Re: create multiple tables in a single queryJan Steinman5 Apr