Iznogud Iznogud - 2 years ago 88
SQL Question

Create a columns in MySQL table from a text/Excel/CSV

I have to create a table with 920 columns, each with different varchar name. Is there a way to to it automatically from the list and in which format it should be.

Answer Source

You can use Excel fill handle to "smart" create your query.

If you have an Excel sheet like this

| A |    B    |     C
| 1 | column1 | 
| 2 | column2 |
| 3 | column3 |

you can write on cell C1 this formula

=B1 & " VARCHAR(100),"

and then use fill handle to populate this for all lines (all fields name)

Copy all data from C column and add CREATE TABLE tablename ( at the begining and remove the last comma and add a closing parenthesis ).

Also you need to add primary key, etc.

Thats it!

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download