您好,登錄后才能下訂單哦!
這篇文章給大家介紹怎么在Mysql中動態更新數據庫,內容非常詳細,感興趣的小伙伴們可以參考借鑒,希望對大家能有所幫助。
動態刪除索引
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;
動態添加字段
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;
關于怎么在Mysql中動態更新數據庫就分享到這里了,希望以上內容可以對大家有一定的幫助,可以學到更多知識。如果覺得文章不錯,可以把它分享出去讓更多的人看到。
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。