How to add column to all tables in MySQL Database - MySQL Developer Tutorial

How to add column to all tables in MySQL Database

Let's say that you are working as MySQL Developer and you need to provide script to add a new column to all tables in MySQL Database. 

You can use system tables to get the list of table names, we can generate the DDL statement to add column to all the tables in MySQL Database. Think about that I want to add "CreatedDate" column of datetime to all the tables in "TechBrothers" database. I can use below script. You can make changes according to your database name and column with data type for @DatabaseName and @ColumnName variable.

SET @DatabaseName ="TechBrothers";
SET @ColumnName= " CreatedDate datetime";
SELECT Concat('ALTER TABLE  ', TABLE_NAME,' Add',@ColumnName,';') as Query
FROM information_schema.TABLES

How to add column to all tables in MySQL Database - MySQL Tutorial for beginners


  1. Though space is limited, one of the best parts about city life is having people over for a good time. space saving table

  2. BSNL Selfcare is a magical or technological doorway on the web, and it aims to provide all customer facilities through online account and it delivers excellent measurable ongoing customer care updated telecom services through a gateway called Selfcare. BSNL selfcare portal The main motto is to offer each service to the client online, but this is to be done on registration only, BSNL Mobile, Landline, and Broadband can enjoy with various telecom services provided inside the Selfcare BSNL portal like submit a service request for BSNL broadband plan change online etc. Have a look at all of them.