I'm trying to use C# & MySql in order to copy an empty table (recreate the Schema really). The structure looks like this:
> TableTemplate (schema)
+ Tables
> FirstTable (table)
> second table (table)
> ...
> SomeOtherTable
+ Tables
> ...
What I would like is to copy the TableTemplate
into a new Schema with the user name.
The first obvious path to oblivion was trying CREATE TABLE @UserName LIKE TableTemplate
, swiftly learning that sql parameters are supposed to be used for values and not table names (all hail jon skeet, again: How to pass a table as parameter to MySqlCommand?).
So that leaves us with manual validation of the user names in order to build the table names (robert's a prime example).
Next, it seems that even CREATE TABLE UserID LIKE TableTemplate;
won't work (even from MySQL Workbench), since TableTemplate
isn't a table.
So It's down to writing a loop that will create a table LIKE
each table in TableTemplate
, after creating a UserID
Schema (after manual validation of that string), or trying other options like dumping the database and creating a new one, as seen in these questions:
But I would prefer avoid running a process, dumping the database, and creating it from there every time I add a user.
Any suggestions would be highly appreciated.