Primary Key for Mysql operations

Source: Internet
Author: User

Mysql operation primary key 1. query the primary key [html] SELECT t. TABLE_NAME, t. CONSTRAINT_TYPE, c. COLUMN_NAME, c. ORDINAL_POSITION FROM www.2cto.com INFORMATION_SCHEMA.TABLE_CONSTRAINTS AS t, INFORMATION_SCHEMA.KEY_COLUMN_USAGE AS c WHERE t. TABLE_NAME = c. TABLE_NAME AND t. TABLE_SCHEMA = 'database name' AND t. CONSTRAINT_TYPE = 'Primary key' and t. TABLE_NAME = 'table name'; 2. delete the primary key [html] alter table Name drop primary key; www.2cto.com 3. add a primary key [html] alter ta Ble table name add primary key (column 1, column 2...); 4. Modify the primary key first, delete the primary key, and then add your new primary key, as described in the preceding steps 2 and 3. Author fellting

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.