Handy Manny
Handy Manny

Reputation: 388

Add mysql table column dynamically

How to add table column in mysql Dynamically?

I have a vb6 code and mysql as database.

Suppose I want to enter new column in the textbox then the value of textbox will be a column in mysql.

Is this possible? How to achieve this one?

Upvotes: 0

Views: 2463

Answers (2)

andy
andy

Reputation: 6079

Yes its possible

Query for adding a new column to database is

"ALTER TABLE mytable ADD COLUMN " + textbox.Text + " VARCHAR(40)"

From VB you can use ADO for it

Upvotes: 2

Archie
Archie

Reputation: 2672

See ALTER TABLE command for that.

But normally it is not a great idea to alter DB structure from your client application.

If you have to, this means that your DB is not very well designed.

You can always have a dynamic data structure presented in your statically structured DB tables set by using relationships between tables.

Upvotes: 3

Related Questions