MySQL alter command, mysqlalter
Use the alter command in mysql to edit the table structure. The details are as follows:
Modify Field Type
mysql> alter table employee change depno depno int(5) not null;
Add Index
Mysql> alter table name add index name (field name 1 [, field name 2…]);
Example:
mysql> alter table employee add index emp_name (name);
Index with primary keywords
Mysql> alter table name add primary key (field name );
Example:
mysql> alter table employee add primary key(id);
Add an index with unique conditions
Mysql> alter table name add unique index name (field name );
Example:
mysql> alter table employee add unique emp_name2(cardnumber);
View the index of a table
Mysql> show index from table name;
Example:
mysql> show index from employee;
Delete An index
Mysql> alter table Name drop index name;
Example:
mysql>alter table employee drop index emp_name;
Modify Table: add field:
mysql> ALTER TABLE table_name ADD field_name field_type;
View table:
mysql> SELECT * FROM table_name;
Modify the original field name and type:
mysql> ALTER TABLE table_name CHANGE old_field_name new_field_name field_type;
Delete field:
ALTER TABLE table_name DROP field_name
The above is all the content of this article. I hope it will be helpful for your learning and support for helping customers.
Finally, I wish you a successful pass of the Computer Grade examination.