MySQL Command line summary (i)

Source: Internet
Author: User

<---------Simple database operation-------------->//CREATE database database_name//view database show databases//Select database use database_name//Deleting a database------------------the storage engine and data type in database database_name <-----------------databases >// View supported storage engines show engines;//query the default storage engine show valiables like ' storage_engine% ';<----------------    Table Operation----------------------->//CREATE TABLE table_name (property name data type, property name data type, ... Property name data type)//view table show tables;//view table definition describe table_name//view table detailed definition show CREATE TABLE table_name//Delete Table drop tables table_name Modify table name ALTER TABLE old_table_name rename new_table_name//Modify table-add field-adds ALTER TABLE table_name Add property Name property type in the last field of the table /Modify Table--Add field--add ALTER TABLE table_name Add property Name property type first//Modify Table-Add field-add field after specified field ALTER TABLES table_name Add property Name property Type after property name/modify Table--delete field ALTER TABLE table_name DROP property name//Modify table--Modify field--Modify the data type of the field ALTER TABLE table_name Modify property name data type//modify table-- Modify the name of the field ALTER TABLE TABLE_NAME change old property name new property name old data type//modify table--Modify field name and property ALTER TABLE TABLE_NAME change old property name new data type//Modify Table--Change the order of fields ALTER TABLE table_name Modify property name 1 Data type First|after property name 2//action table constraint//action table constraint--set non-null constraint (NOT NULL) CREATE table TABLE_NAME (Property Name property type NOT NULL, ...) Constraint on action table--Set default value for field--CREATE TABLE table_name (property Name property type default defaults, ...) ACTION table constraint--Set UNIQUE constraint (UNIQUE,UK) CREATE TABLE table_name (property Name property type Unique, ...) ACTION table constraint--Set PRIMARY KEY constraint (primary KEY,PK)--Set single field primary key, primary key is when Table attribute action CREATE TABLE table_name (property Name property type Primary key, ...) ACTION table constraint--Set PRIMARY KEY constraint (primary KEY,PK)--Set multi-field primary key, which is the function of a table attribute in Create tables table_name (property Name property type, ..., [constraint constraint name] pri Mary Key (property name, property name ...) Constraint on action table--Set field value Auto Increment (auto_increment) CREATE TABLE table_name (property Name property type Auto_increment)//Constraint on action table--Set FOREIGN KEY constraint (foreign KEY,FK) CREATE TABLE table_name (property Name property Type, property Name property type, ... constraint foreign KEY constraint name foreign key (property name 1) References table name (property name    2) <-----------------index operations--------------->//Create and view normal indexes//create tables while creating the CREATE TABLE table_name (property Name property Type, property Name property type,    ... Property Name property type, Index|key [index name] (property name 1 [(length)] [ASC|DESC]))//Create a normal index on an already existing table creation index name on table name (property name [length] [ASC|DESC])//ALTER TABLE of SQL statement create normal index ALTER TABLE table_name ADD Index|key    Index name (attribute name 1 [(length)] [ASC|DESC])//Create and view unique index//CREATE TABLE table_name (property Name property Type, property Name property type, ... Property Name property type, unique Index|key [index name] (property name 1 [(length)] [ASC|DESC])//Create a generic index on an existing table creation unique index name on table name (property name [length] [asc| DESC]//Create a normal index from an ALTER table in an SQL statement ALTER TABLE TABLE_NAME add unique Index|key index name (property name 1 [(length)] [ASC|DESC])//Create and view full-text index//    CREATE TABLE table_name (property Name property Type, property Name property type, ... Property Name property Type, fulltext Index|key [index name] (property name 1 [(length)] [ASC|DESC])//Create a normal index on an existing table creation fulltext index name on table name (property name [length] [ ASC|DESC]//Create a normal index by ALTER TABLE of SQL statement ALTER TABLE TABLE_NAME ADD FULLTEXT INDEX|KEY index name (property name 1 [(length)] [ASC|DESC])//    Create and view multi-column indexes//create tables at the same time CREATE TABLE table_name (property Name property Type, property Name property type, ...                                Property Name property Type, fulltext Index|key [index name] (property name 1 [(length)] [Asc|desc], ... Property name n [(length)] [aSC|DESC])//CREATE FULLTEXT index index name on table name on existing table (property name 1 [length] [Asc|desc], ... Property name n [(length)] [ASC|DESC])//Create an ordinary index by ALTER TABLE of SQL statement ALTER TABLE TABLE_NAME ADD FULLTEXT IND                                                    Ex|key Index Name (property name 1 [(length)] [Asc|desc], ... Property name n [(length)] [ASC|DESC])//delete index drop index_name on table_name<------------------view Operation------- ----------->//view can be viewed as a virtual table, but it does not physically exist//create a view for View_name as query statement//view view use Database_nameshow tables// View information details Show table status [from db_name] [like ' pattern ']//View definition information Show CREATE VIEW view_name//view design information describe | Desc view_name//Delete Views Drop view view_name//Modify view--create or Replace view statement modify views CREATE VIEW View_name as query statement-can drop view V Iew_exist;create View New_view as query statement//Modify View--alter statement modify view alter views view_name as query statement//view Operation base Table//Retrieve (query) data--query data through a view, It is exactly the same as querying through a table, except that it is more secure, simpler, and more practical than a table by a view query. --When implemented, simply replace the table name with the view name-Example: SELECT * from view_selectproduct//use the view to manipulate the data of the basic table--Add data action insert into View_select [(field)] Values (related values)//Use views to manipulate basic table data--delete data operations Delete from View_select query statement//Use view to manipulate basic table data--Update data operations updates View_select set related statements

  

MySQL Command line summary (i)

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.