Common statement code blocks in MySQL list

Source: Internet
Author: User


See if the data table exists: show TABLES;
Displays the database that has been opened: SELECT databases ();
View data table structure: Show COLUMNS from * * * (data table name);
Insert data: Insert * * * (data table name) (,) VALUES (data);
Record Lookup: SELECT * FROM * * * (data table name)
Display data table information: Show CREATE Table * * * (data table name)
Display index: Show INDEXES from ***\g (data table name

Creating databases: Create Database
modifying databases: ALTER database
Delete database: Drop db
Open database: Use * * * (database name)
See if the database exists: show DATABASES;


Delete Column: ALTER TABLE tb1_name Drop[column] col_name;
Add multiple columns: ALTER TABLE tb1_name Add[column] (col_name column_definition,...);
Add single column: ALTER TABLE tb!_name Add[column] col_name column_definition [first| After Col_name];
Delete Record: Delete from province WHERE id=3;

Add PRIMARY KEY constraint: ALTER TABLE users2 add PRIMARY key (ID);
Add FOREIGN KEY constraint: ALTER TABLE users2 add FOREIGN KEY (PID) REFERENCES provinces (ID);
Add a DEFAULT constraint: Alter TABLE users2 alter age SET to default 15;
Delete default constraint: Alter TABLE users2 alter age DROP defaults;

Add UNIQUE constraint: ALTER TABLE table_name Add [CONSTRAINT [symbol]] unique [INDEX | KEY] [index_name] [Index_type] (index_col_name, ...)


Delete PRIMARY KEY constraint: ALTER TABLE tbl_name DROP PRIMARY key
Delete Unique constraint: ALTER TABLE tbl_name DROP {index| KEY} index_name
Delete foreign KEY constraint: ALTER TABLE tbl_name DROP FOREIGN KEY fk_symbol


Data table modification: Nothing but add columns, delete columns, add constraints, delete constraints. An alter is used, and insert is used to add an insert record to a data table.

Modify Column definition: ALTER TABLE tbl_name MODIFY [column] Col_name column_definition [first| After Col_name]
Modify Column Name: ALTER TABLE tbl_name Change [column] Old_col_name new_col_name column_definition [first| After Col_name

Method 1:alter TABLE tbl_name RENAME [To|as] New_tbl_name
Method 2:rename TABLE Tbl_name to New_tbl_name [, tbl_name2 to New_tbl_name] ...

Common statement code blocks in MySQL list

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.