MySQL table operation syntax

Source: Internet
Author: User

Checklist
Check table table_name;
Repair table
Repair table table_name;
Optimization table
Optimize table table_name;
Analysis table
Analyze table table_name;
Clear table
Truncate table_name;
Delete table
Drop table_name;
Drop table if exists table_name;

Show all databases on the server
Show databases;

Show all tables of the current database
Show tables;
Display tables that meet the given conditions
Show tables like '% table_name % ';

Display the table structure of the specified table
Describe table_name;

Rename a table
Alter table Table1 rename Table2;

Create a table
Create Table table_name (
Field1 int (10) unsigned not null auto_increment,
Field2 varchar (10) Not null,
Primary Key (field1)
) Engine = MyISAM default charset = Latin1;

Change the attribute of a field and rename the field name.
Alter table table_name change old_name new_name varchar (80) not null;
Modify Field attributes without changing field names
Alter table table_name modify field_name varchar (100) not null;

Add a field at the beginning of the table
Alter table table_name add field_name varchar (10) Not null first;
Add a field at the end of the table
Alter table table_name add field_name varchar (10) Not NULL;
Add a field after a field
Alter table table_name add field_name varchar (10) Not null after field_x;

Deletes a field from a table.
Alter table table_name drop field_name;

Create an index
Create index index_name table_name (column_name );
Create an index using the first 10 characters of the name column:
Create index index_name on table_name (name (10 ));

Delete Index
Alter table table_name drop index index_name;
This article comes from the time drift bottle http://www.9usb.net, the original address: http://www.9usb.net/200811/mysql-yufa.html

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.