Add mysql table column dynamically - mysql

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?

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.

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

Related

adding multiple column in table dynamicaly without using alter command in sql

I have to design a database in such a manner so that when ever i have to add or delete any column from the table i should not have to use alter command . Please guide me if it is possible to design a database like that

Alter a MySQL table by providing the new schema

Is it possible to alter the schema of a mysql table by simply providing the new schema and having the database figure out how to migrate? For example, let's say I have a table with two columns: id, name. I want to modify this table by adding a new column: title. I know that I can issue the command ALTER TABLE tbl ADD COLUMN title. Is there a way I can just provide the complete schema and have mysql figure out that it needs to add a title column?
I hope that makes sense what I am asking.
MySQL can't do this by itself, but I found a blog that says MySQL Workbench can do it.
No - It cannot do that just giving your database a new schema. It would have to go about and second guess what to do with the data. (Also what happens to triggers, stored procedures ...)
You have a couple of choices
Modify each table and decide what needs to be done
Export the data, create a new database and then figure out how to import it into the new regime.

ALTER ms-access table that is locked

I am trying to add a column to a table in an ms-access backend which is being used by multiple ms-access front-ends. When I try to add a column to the table like so (or with DAO):
sql = "ALTER Table MyTable " & _
"ADD COLUMN NewCol Integer "
CurrentDb.Execute (sql)
I get an error, and Access complains that the table is already locked by another user.
Is there a way to ALTER a locked table?
If you can't, how do you handle modifying a backend table that is always in use? Just wait until everyone goes home for the weekend? Are there some admin tricks that I can use to avoid this in the future?

Dynamically ALTERing MySQL tables to add missing fields on INSERT

I'm attempting to merge data from one MySQL database into another. The problem is, some of the tables in Source_DB have fields that the matching table in Target_DB does not have.
Is there a way to automatically ALTER the table in Target_DB to add these missing fields as they are found?
Or should I go about it another way, like doing a first pass where I compare each table to first add any missing fields?
You could query the INFORMATION_SCHEMA.COLUMNS on each DB and figure out what's missing with a NOT IN query and then using the data in the INFORMATION_SCHEMA.COLUMNS dynamically generate the DDL.
Or you could use a tool like MySQL Compare to do it.

Alter table in multiple databases

I have a set of databases and each of them contains a table named 'data'. I would like to add a new column to the table 'data' in all databases. Is it possible to do this with a sql statement? And would it work on MySQL 3.x server?
As far as I know you must do an "Alter Table" on every table of every database.