MySQL Learning (MU lesson note 7) Modify data sheet (bottom)

Source: Internet
Author: User

Add a PRIMARY KEY constraint

ALTER TABLE tb1_name ADD [CONSTRAINT [symbol]] PRIMARY KEY [Index_type] (Index_col_name,.......)

ALTER TABLE user2 ADD CONSTRAINT pk_user2_id PRIMARY KEY (ID);

Add a UNIQUE Constraint

ALTER TABLE user2 ADD UNIQUE (username);

Add a DEFAULT constraint add, alter

Alter TABLE User2 ALTER age SET DEFAULT 15;

Delete primary key Drop '

ALTER TABLE user2 DROP PRIMARY KEY;

Remove UNIQUE Constraint

Show UNIQUE constraint show indexes from User2\g; (Rendered in grid form)

Modifying a column definition Modify

ALTER TABLE user2 MODIFY pid VARCHAR (a) first;

Modify column name change can modify name, type, and definition (almighty)

ALTER TABLE user2 Change pid p_id SMALLINT UNSIGNED;

Modify Table name Rename

ALTER TABLE user2 RENAME user3;

Method 2:rename table User3 to User2;

Modify table names, column names as few as possible

MySQL Learning (MU lesson note 7) Modify data sheet (bottom)

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.