-1

I'm using MySQL.Data 6.9.9 library and .Net framework 4.5 to work with MySQL server in C# code.

There is a table1 with rows and I want to create the table2 with the same structure as table1 in same database but without rows.

Please advice how to create it?

borobos
  • 21
  • 1
  • 5

2 Answers2

4

MySQL can do that out of the box.

CREATE TABLE
 table
LIKE 
 table

Use CREATE TABLE ... LIKE to create an empty table based on the definition of another table, including any column attributes and indexes defined in the original table:

source https://dev.mysql.com/doc/refman/8.0/en/create-table-like.html

Raymond Nijland
  • 11,488
  • 2
  • 22
  • 34
0

You can do it manually:

CREATE TABLE table2  LIKE table1;

And then update your edmx model if you use "Database First" approach.

  • Thanks, I'm not use "Database First" approach but the usage of MySqlCommand with this create syntax is that what I needed. Also, found the related https://stackoverflow.com/a/20320118/2679054 – borobos Apr 20 '18 at 14:02