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

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

Related

How to view table structure sql query?

I want to make a new table like as an existing table in MySQL database with some "column name" changes. So, is there any way to see the SQL dump of the existing table without importing?
You can use SHOW CREATE TABLE:
SHOW CREATE TABLE oldtable

Merge two database into a third one

I have two MySQL database k_db1 and k_db2 on a single server.
In k_db1, I have k_db1.table1 and k_db1.table2.
In k_db2, I have k_db2.table3 and k_db2.table4.
I want to create a third database k_db3 where I copy/paste tables of others databases.
It will result in k_db3.db1-table1, k_db3.db1-table2, k_db3.db2-table3, k_db3.db2-table4. I want to transfer data, indexes etc... and I don't want to delete k_db1 and k_db2 tables in the process. It must duplicate datas.
Do you know a way to do this just with SQL command?
Thanks in advance for your help.
You can try something like this:
DROP TABLE IF EXISTS k_db3.db1_table_1;
CREATE TABLE k_db3.db1_table_1 AS
SELECT * FROM db1.table_1;
Then you can recreate the indexes on the new table via ALTER TABLE statements.
Also I would avoid using - in table names.

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?
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

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 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.