Common MySQL auto-increment Fields

Source: Internet
Author: User

To learn about the MySQL database, MySQL auto-increment fields are one of the most basic parts. The following describes some common statements for MySQL auto-increment fields. I hope this will help you learn about MySQL auto-increment fields.

1. When creating a table, add: create table table1 (id int auto_increment primary key ,...)

2. After creating a table, add the alter table table1 add id int auto_increment primary key auto-increment field, which must be set to primary key.

Appendix: alter table mysql> alter table employee change depno int (5) not null in mysql;

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 restrictions mysql> alter table name add unique index name (field name );

Example: mysql> alter table employee add unique emp_name2 (cardnumber );

View the index mysql> show index from Table Name of a table; 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 a field: mysql> alter table table_name ADD field_name field_type;

View the 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 preceding describes common statements for MySQL auto-increment fields.

Mysql character encoding method

Statement for modifying fields in mysql

How to delete multiple tables in MySQL

How MySQL connects to remote SQL

MySQL cluster introduction and Configuration

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.