Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to update database dynamically in Mysql

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)05/31 Report--

This article introduces how to update the database dynamically in Mysql. The content is very detailed. Interested friends can use it for reference. I hope it will be helpful to you.

Dynamically delete index

DROP PROCEDURE IF EXISTS UPGRADE;DELIMITER $$CREATE PROCEDURE UPGRADE () BEGIN-- RESOURCE.AUDIO_ATTRIBUTE IF EXISTS (SELECT * FROM INFORMATION_SCHEMA.STATISTICS WHERE TABLE_SCHEMA = 'RESOURCE' AND TABLE_NAME =' AUDIO_ATTRIBUTE' AND INDEX_NAME = 'resource_publish_resource_id_index') THEN ALTER TABLE `AUDIO_ ATTRIBUTE` DROP INDEX resource_publish_resource_id_index; END IF;END$$DELIMITER; CALL UPGRADE (); DROP PROCEDURE IF EXISTS UPGRADE

Add fields dynamically

DROP PROCEDURE IF EXISTS UPGRADE;DELIMITER $$CREATE PROCEDURE UPGRADE () BEGIN-- HOMEWORK.HOMEWORK_QUESTION_GROUP.FROM_ID IF NOT EXISTS (SELECT * FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_SCHEMA = 'HOMEWORK' AND TABLE_NAME =' HOMEWORK_QUESTION_GROUP' AND COLUMN_NAME = 'FROM_ID') THEN ALTER TABLE `HOMEWORK_QUESTION_ GROUP` ADD COLUMN FROM_ID VARCHAR (50) NULL; END IF -- HOMEWORK.HOMEWORK_QUESTION_GROUP.QUESTION_TYPE IF NOT EXISTS (SELECT * FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_SCHEMA = 'HOMEWORK' AND TABLE_NAME =' HOMEWORK_QUESTION_GROUP' AND COLUMN_NAME = 'QUESTION_TYPE') THEN ALTER TABLE `HOMEWORK_QUESTION_ GROUP` ADD COLUMN QUESTION_TYPE VARCHAR (50) NULL; END IF -- HOMEWORK.HOMEWORK_QUESTION_GROUP.DIFFICULTY IF NOT EXISTS (SELECT * FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_SCHEMA = 'HOMEWORK' AND TABLE_NAME =' HOMEWORK_QUESTION_GROUP' AND COLUMN_NAME = 'DIFFICULTY') THEN ALTER TABLE `HOMEWORK_QUESTION_ GROUP` ADD COLUMN DIFFICULTY VARCHAR (50) NULL; END IF;END$$DELIMITER; CALL UPGRADE (); DROP PROCEDURE IF EXISTS UPGRADE On how to dynamically update the database in Mysql to share here, I hope the above content can be of some help to you, can learn more knowledge. If you think the article is good, you can share it for more people to see.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report