Mysql determines whether a table field or index exists, and mysql determines a field Index
Determine whether a field exists:
Drop procedure if exists schema_change; DELIMITER // create procedure schema_change () begin declare CurrentDatabase VARCHAR (); select database () INTO CurrentDatabase; if not exists (SELECT * FROM information_schema.columns WHERE table_schema = CurrentDatabase AND table_name = 'rtc _ order' AND column_name = 'ifupsend ') then alter table rtc_orderADD COLUMN 'ifupsend' bit not null default comment' whether to upload or NOT '; end if; END // DELIMITER; CALL schema_change ();
Determine whether an index exists:
DROP PROCEDURE IF EXISTS schema_change; DELIMITER //CREATE PROCEDURE schema_change() BEGIN DECLARE CurrentDatabase VARCHAR();SELECT DATABASE() INTO CurrentDatabase;IF NOT EXISTS (SELECT * FROM information_schema.statistics WHERE table_schema=CurrentDatabase AND table_name = 'rtc_phototype' AND index_name = 'index_name') THEN ALTER TABLE `rtc_Phototype` ADD INDEX index_name ( `imgtype` );END IF; END// DELIMITER ; CALL schema_change();
We can see a lot of things from these two paragraphs. You can test them by yourself.
I would like to introduce you to Mysql's content about how to determine whether a table field or index exists. I hope it will help you!