Create multiple tables with a single SQL query
-
Is there any way of creating say 100 different tables using a single SQL query/statement..Or is there another way around?:java:
-
Is there any way of creating say 100 different tables using a single SQL query/statement..Or is there another way around?:java:
You could use a cursor or loop, generating inline create table statements which you then execute
========================================================= I'm an optoholic - my glass is always half full of vodka. =========================================================
-
Is there any way of creating say 100 different tables using a single SQL query/statement..Or is there another way around?:java:
No. A single create-statement creates a single table. You can build your own loop, but then it wouldn't be a single statement anymore. If you want it to be a single query, simply concatenate the statements. Logically, each table would have it's own layout/schema - unless all tables look the same (which would be a code-smell), different column-specifications need to be used per table.
Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^]
-
Is there any way of creating say 100 different tables using a single SQL query/statement..Or is there another way around?:java:
From your question, I'm assuming you're trying to partition a table. Creating 100 physical tables is probably not the best approach. For MS SQL, have a look at Partitioned Tables and Indexes[^] instead.
"These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer
-
No. A single create-statement creates a single table. You can build your own loop, but then it wouldn't be a single statement anymore. If you want it to be a single query, simply concatenate the statements. Logically, each table would have it's own layout/schema - unless all tables look the same (which would be a code-smell), different column-specifications need to be used per table.
Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^]
Eddy Vluggen wrote:
Logically, each table would have it's own layout/schema - unless all tables look the same (which would be a code-smell)
It's common to see more than one table with the same schema in horizontal partitioning. Eg., CustomerEast and CustomerWest. I know this violate normalization rules, but again, not all production databases are normalized completely.
-
Eddy Vluggen wrote:
Logically, each table would have it's own layout/schema - unless all tables look the same (which would be a code-smell)
It's common to see more than one table with the same schema in horizontal partitioning. Eg., CustomerEast and CustomerWest. I know this violate normalization rules, but again, not all production databases are normalized completely.
Shameel wrote:
not all production databases are normalized completely.
That's rather an understatement. You'll also often have multiple small tables consisting of an
BIGINT|UUID
and a[N]VARCHAR
, but even though they share their structure - you don't have a single statement.Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^]
-
Is there any way of creating say 100 different tables using a single SQL query/statement..Or is there another way around?:java:
you can do by using loop statement