Summary of common MySQL database commands _ MySQL

Source: Internet
Author: User
MySQL database common commands summary 1. first determine whether the database/table exists, and then create a database/table
CREATE DATABASE IF NOT EXISTS database_name;CREATE TABLE IF NOT EXISTS table_name;

2. modify the table name in MySQL. modify the table name in MySQL.
AITER TABLE table_old_name RENAME [TO] table_new_name; RENAME TABLE table_old_name TO table_new_name;

3. add columns for MySQL and add columns for MySQL
ALTER TABLE table_name ADD column_name data_type NOT NULL DEFAULT xxx [AFTER/BEFORE] column_name;ALTER TABLE person ADD age tinyint NOT NULL DEFAULT 16 AFTER name;

4. MySQL deletes a column.
ALTER TABLE table_name DROP [COLUMN] column_name;ALTER TABLE person DROP COLUMN age;

5. modify MySQL columns
Alter table table_name CHANGE [COLUMN] column_old_name column_new_name COLUMN declaration

6. MySQL modifies the column data type and only modifies the column data type.
ALTER TABLE table_name MODIFY [COLUMN] column_name data_type;ALTER TABLE person MODIFY COLUMN age int NOT NULL DEFAULT 16;

7. create an index for MySQL
Alter table table_name ADD index/unique/fulltext [index name] (column name); if no index name is added, the alter table table_name ADD primary key (column name) name is directly used );

8. MySQL deletes an index.
Alter table table_name DROP index name; alter table table_name DROP primary key;

9. View all indexes in MySQL
show index from table_name; show index from table_name/G;

10. MySQL /GMYSQL statement /GThe parameter changes the display mode of the output result set.

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.