MySQL study notes _ 8_ SQL language basics _ MySQL

Source: Internet
Author: User
MySQL study notes _ 8_ SQL basic language review bitsCN. comSQL basic language review I. Overview

SQL statement Comments

1) all contents starting with "#" until the end of the line are comments

2) all content starting with "--" (-- and then a space) until the end of the line is annotated.

3) all content ending with "/*" and ending with "*/" is annotated and can be used to comment multiple lines.

II. database operations

1. create a database

Create database db_name;

Db_name naming rules:

1) The name can consist of any letter, number, "_" or "$". it can start with any of the above characters, but cannot be used as the database name separately.

2) length limit: the name of a database, table, column, and index can be up to 64 characters in length, and the alias can be up to 256 characters in length.

3) you cannot use the MySQL keyword as the database or table name.

2. delete a database

Drop database db_name; # drop, terminate

It will unrecoverable delete the database and all its data tables. we recommend that you back up the database before using drop database.

III. table operations

1. create a data table

Create table <表名>

( <列名> <数据类型> [ <列级完整性约束条件> ]

[, <列名> <数据类型> [ <列级完整性约束条件> ]...

[, Constraints on table-level Integrity]

);

Extended: create temporary table... # create a temporary table. the temporary table will be automatically deleted when the server interaction ends.

2. modify a data table

Modifies the structure of a table, uses the alter talbe statement to modify the attribute of a column in the table, or even modifies the table name.

Alter talbe <表名>

[Add <新列名> <数据类型> [Integrity constraints]

[Drop <完整性约束> ]

[Alter column <列名> <数据类型> ]; # Alter modify, change

3. delete a table

Drop table table_name;

Drop table if exists table_name;

IV. recorded operations

1. Insert data

Insert <表名>

[( <属性列1> , <属性列2> ...)]

Values ( <常量1> [, <常量2> ...])

E.g. insert into student_info (stu_id, stu_name, str_sex, str_age)

Values (234, "xiaofang", "male", 18 );

2. update records

Update <表名>

Set <列名> = <表达式> [, <列名> = <表达式> ]...

[Where <条件> ];

Note: The update statement includes the set clause and the where clause. The set clause specifies the modification method, the columns to be modified, and the modified values. The where clause is used to specify the data records modified by the key, all records in the table are modified by default.The key to updating a statement is to set it for judgment.WhereCondition!

E.g. update student_info set str_age = 22 where stu_id = 9028;

3. delete records

Delete from <表名> [Where <条件> ];

Note: If you do not set the where condition when using the delete statement, all records in the table will be cleared!

Delete from student_info where stu_id = 9028;

5. query

Select [all | distinct] <目标列表表达式> [, <目标列表表达式> ]…

From <表名或视图名> [, <表名或视图名> ]...

[Where <条件表达式> ]

[Group <列名1> [Having <条件表达式> ]

[Order <列名2> [Asc | desc];

VI. example of the database design process of the course selection system for students

1. database design process:

System Analysis ---> logical design ---> physical implementation

2. system analysis


3. Logic Design

BitsCN.com

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.