MySQL Database common statements

Source: Internet
Author: User

About the collation of common commands in MySQL database:

One: For the operation of the database

show databases; Displays all database names under the current user

Use database_name; Enter the current database

CREATE DATABASE database_name;

DROP DATABASE database_name;

Second: The operation of the table

DDL operations: Data Definition language

CREATE TABLE table_name (

ID int primary KEY auto_increment,

Name varchar (20),

); Build a Table statement

DROP TABLE TABLE_NAME, delete the statement of the tables, delete the contents of the table and the table structure directly.

TRUNCATE TABLE table_name; Deletes the contents of the tables, preserves the structure of the table, and does not roll back, the efficiency is high.

Delete from Talbe_name, deleting the contents of the table, without deleting the table's mechanism, is less efficient than truncate.

Rename table Old_name to new_name; Modify the name of the tables.

ALTER TABLE table_name ADD COLUMN_NAME varchar (30);

ALTER TABLE table_name DROP COLUMN_NAME varchar (30);

ALTER TABLE table_name MODIFY COLUNM_NAME varchar (30);

DESC table_name; Query table structure

DML: Data Manipulation language

Delete from table_name where column_table=column_value; Delete data under condition

UPDATE table_name Set column_name= ", column=" where column_name=column_value; updates the data under the condition

INSERT INTO table_name (column_name1,column_name2 ...) VALUES (Column_values,column_values,...);

Query statement:

SELECT * FROM table_name where column_name=column_value; query the data that satisfies the condition based on the specific conditions

Select A.column1,a.column2,... from table_name where column_name=column_value; query data for some fields based on criteria

There are also sub-queries, sequences, views, and indexes.

MySQL Database common statements

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.