MySQL determines if a table field exists and then modifies

Source: Internet
Author: User

-- ------------------------------determines whether the Vrv_paw_rule table exists thresholdmin field, does not exist, and then modifies the field type.DELIMITER??DROP PROCEDURE IF EXISTSschema_change??CREATE PROCEDURESchema_change ()BEGINIF  not EXISTS(SELECT *  fromInformation_schema.columnsWHERETable_schema= DATABASE() andtable_name= 'Vrv_paw_rule'  andcolumn_name= 'Thresholdmin') Then    ALTER TABLEVrv_paw_ruleADD COLUMNThresholdminBIGINT;ELSE        ALTER TABLEVrv_paw_rule MODIFYCOLUMNThresholdminBIGINT ;END IF; END?? DELIMITER; Call Schema_change ();

Delimit command:

is to tell the MySQL interpreter if the command is over, and if MySQL can execute it, change the input terminator.
By default, delimiter is a semicolon ";".
In the command-line client, if a single line of commands ends with a semicolon,
Then after the carriage return, MySQL will execute the command.
But sometimes, you don't want MySQL to do this. Because more statements may be entered, and the statement contains a semicolon.
By default, it is not possible to wait until the user has entered all of these statements before executing the entire statement.
Since MySQL encounters a semicolon, it will be executed automatically.
In this case, you can use delimiter to change the delimiter back to another symbol, such as//or $$.
At this point, the delimiter function is to make a simple encapsulation of the entire small segment statement.
This command is used in the definition subroutine, triggers the program and so on MySQL own embedded small program.

MySQL determines if a table field exists and then modifies

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.