MySQL Learning note _8_sql Language Basics Review

Source: Internet
Author: User

 SQLReview of the basic language



I. Overview

SQL Statement Comment Method

1 ) to " # " all content that starts at the end of the line is a comment

2 ) to " --" ( -- and a space at the beginning of the line until all the contents of the end are commented

3 ) to " / * " to begin with, " * * " all content that ends is a comment that can be used to comment on multiple lines


second, the database operation

1 , create a database

Create DATABASE db_name;

db_name naming rules:

1 ) name can be any letter, number, " _ " or " $ " , you can start with any of these characters, but you cannot use numbers as a database name alone.

2 ) Length limit: Database, table, column, and index names up to - characters, up to an alias of up to the a character.

3 ) cannot be used MySQL keyword as the database, table name.


2 , delete database

drop database db_name; #drop Fall, Terminate

He will not be recoverable to delete the database and all its data tables, it is recommended to use DROP Database first, back up the database


third, the operation of the table

1 , creating a data table

CREATE TABLE < Table name >

(< column name > < data type > [< Column-level integrity constraints ;]

[,< column names > < data types > [< Column-level integrity constraints ]] ...

[, table-level integrity constraints ]

);


Expansion: Create temporary table ... # creates a temporary table that is automatically deleted when the server interaction ends


2 , modifying data tables

Modify the structure of a table, using the Alter Talbe statement to modify the properties of a column in a table, or even to modify the name of a table

Alter Talbe < Table name >

[Add < new column name > < data type > [ integrity constraint ]]

[Drop < integrity constraint ;]

[Alter COLUMN < column name > < data type >]; #alter Modify, change


3 , delete a table

DROP TABLE table_name;

DROP table if exists table_name;


Iv. operation of Records

1 , inserting Data

INSERT INTO < Table name >

[(< attribute column 1>,< Property column 2> ...)]

VALUES (< constant 1>[,< constant 2> ...])

e.g. insert into Student_info (stu_id,stu_name,str_sex,str_age)

VALUES (234, "Xiaofang", " male",);


2 , update records

Update < Table name >

Set < Column Name >=< An expression >[,< column name >=< expression ;

[where< conditions >];

Description: Update statement includes Set clauses and where clause, Set clause Specifies the modification, the column to be modified, and the modified value, where clause is used to specify data records for key modifications, and all records in the table are modified by default. the key to updating a statement is to set up a good judgment where Condition!

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


3 , delete records

Delete from < table name >[where < conditions >];

Description: If the user is using the Delete statement is not set where condition, all records in the table will be emptied!

Delete from student_info where stu_id = 9028;


Five, inquiry

SELECT [All | distinct] < target list expression >[,< target list expression ;

From < table name or view name >[,< table name or view name ;] ...

[where < conditional Expressions ;]

[GROUP by < column name 1>[having < conditional expression ;]]

[ORDER by < column name 2>[asc|desc]];


VI. Student Course selection system Database Design Flow Example

1 , database design process:

System Analysis ---> logic Design ---> Physical Implementation


2 , System analysis



3 , logical design





MySQL Learning note _8_sql Language Basics Review

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.