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
WHERE TABLE_SCHEMA = @DatabaseName;
How to add column to all tables in MySQL Database - MySQL Tutorial for beginners
Thanks for your interesting ideas.the information's in this blog is very much useful
ReplyDeletefor me to improve my knowledge.
Python Training in Chennai
Python course in Chennai
Big data training in chennai
JAVA Training in Chennai
Selenium Training in Chennai
Python Training in Chennai
Python Course in Chennai
Great Article. As I read the blog I felt a tug on the heartstrings. it exhibits how much effort has been put into this.
ReplyDeleteIEEE Projects for CSE in Big Data
Spring Framework Corporate TRaining
Final Year Project Centers in Chennai
JavaScript Training in Chennai
Though space is limited, one of the best parts about city life is having people over for a good time. space saving table
ReplyDelete