· 6 years ago · Jun 03, 2019, 03:54 AM
1DELIMITER $$
2
3DROP PROCEDURE IF EXISTS add_email_address_column_to_customers_table $$
4
5-- Create the stored procedure to perform the migration
6CREATE PROCEDURE add_email_address_column_to_customers_table()
7
8BEGIN
9
10 -- Add the email_address column to the customers table, if it doesn't already exist
11 IF NOT EXISTS ((SELECT * FROM information_schema.columns WHERE table_schema=DATABASE() AND table_name='customers' AND column_name='email_address')) THEN
12 ALTER TABLE customers ADD email_address VARCHAR(256);
13 END IF;
14
15END $$
16
17-- Execute the stored procedure
18CALL add_email_address_column_to_customers_table() $$
19
20-- Don't forget to drop the stored procedure when you're done!
21DROP PROCEDURE IF EXISTS add_email_address_column_to_customers_table $$
22
23DELIMITER ;