Basic MySql operation statements

Source: Internet
Author: User

Basic MySql operation statements
DATABASE:Create
CREATTE {DATABASE | SCHEMA} [if not exists] db_name [DEFAULT] character set [=] charset_name;
Delete:
DROP {DATABASE | SCHEMA} [if exists] db_name;
Display:
SHOW {DATABASES | SCHEMAS} [LIKE 'pattern' | WHERE expr];
Select:
USE database_name;


TABLE:Create:
Create table [if not exists] table_name (column_name data_type,...) // the name of each column in the database
Delete:
Drop table [if exists] table_name;
Display:
Show tables [FROM db_name] [LIKE 'pattern' | EHERE expr];






COLUMN:Add:
Alter table tbl_name ADD [COLUMN] col_name column_definition [FIRST | AFTER col_name]
// Add FIRST to the frontend, AFTER col_name, AFTER col_name. If this item is omitted, add it to the end;
Delete:
Alter table tbl_name DROP [COLUMN] col_name;


Record ROW:Add:
INSERT [INTO] tbl_name [(col_name,...)] VALUES (val ,..)
Delete:
Delete from tbl_name [WHERE where_condition]
Modify/update:
UPDATA [LOW_PRIORITY] [IGNORE] table_reference SET col_name1 = {expr1 | DEFAULT} [, col_name2 = {expr2 | DEFAULT}]...
[WHERE where_condition]
Example: UPDATE users SET age = 18 WHERE age = 17;
Display:
SELECT expr,... FROM tal_name;
SELECT * FROM tal_name; // view all
Query:
SELECT select_expr [, select_expr...]
[
FROM table_references
[WHERE where_condition]
[Group by {col_name | position} [ASC | DESC],...]
[HAVING where_condition]
[Order by {col_name | expr | position} [ASC | DESC],...]
[LIMIT {[offset,] row_count | row_count OFFSET}]
]
// Example: SELECT name FROM users WHERE id = 3;


Others:
Constraints:Not null; primary key; unique key; DEFAULT; FOREIGN KEY
Other common keywords: AUTO_INCREMENT



Related Article

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.