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)