To 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 ' D column_name = ' ifupsend ') THEN
ALTER TABLE rtc_order
ADD column ' ifupsend ' BIT not NULL DEFAULT COMMENT ' Whether or not to upload Upload ';
End IF;
end//
DELIMITER;
To 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_photot Ype ' and index_name = ' index_name ') THEN
ALTER TABLE ' rtc_phototype ' ADD index index_name (' Imgtype ');
End IF;
end//
DELIMITER;
From these two paragraphs can see a lot of things, you can test yourself
About the small series to introduce the MySQL Judge table field or whether the index exists content to introduce to everyone here, I hope to help you!