First, personal summary of the Novice tutorial |sql tutorial Knowledge points (SQL Tutorial)

Source: Internet
Author: User
Tags create index sql tutorial

A. SQL tutorial

1. SQL syntax

Dml

Select query data

Update updates data

Delete Deletes data

INSERT INTO Inserts data

Ddl

Create DATABASE table

ALTER DATABASE modifies databases

CREATE table Creating tables

ALTER TABLE Modify tables

drop TABLE Delete Tables

CREATE index

Drop INDEX to delete indexes

Set names UTF8; sets the charset used

The SQL statement is not case sensitive.

2. SQL SELECT

SELECT * FROM table name

Select Column name from table name

Select Lastname,firstname from persons;

3. SQL SELECT DISTINCT

SELECT DISTINCT column_name,column_name from table_name;

Select distinct country from websites;

4. SQL WHERE

Select Column_name,column_name from table_name where column_name operator value;

SELECT * FROM websites where country= ' cn '

SQL uses single quotation marks (') to surround text values

If the number field, do not use single quotation marks.

SELECT * FROM websites where id=1

The following operators can be used in a where statement:

= equals

<> does not equal (you can use! = in some versions of SQL)

> Greater than

< less than

>= greater than or equal to

<= less than or equal to

Between within a certain range

Like search for a pattern

In developing multiple possible values for a column

5. SQL ADN & OR

If both the first condition and the second condition are true, the AND operator displays a record.

If only one of the first and second conditions is true, the OR operator displays a record.

SELECT * FROM websites where country= ' cn ' and ALEXA>50

SELECT * from websites where country = ' USA ' or country= ' CN '

SELECT * from websites where Alexa > and (country= ' cn ' or country= ' USA ')

6. SQL ORDER by

The ORDER BY keyword is used to sort the result set by one column or multiple columns.

The order by keyword sorts records by default in ascending order. If you need to sort records in descending order, you can use the DESC keyword.

Select Column_name,column_name from table_name ORDER by Column_name,column_name Asc|desc

SELECT * FROM websites ORDER by Alexa

SELECT * FROM websites ORDER by Alexa Desc

SELECT * FROM websites ORDER by Country,alexa

7. SQL INSERT into

The INSERT INTO statement is used to insert a new record into the table.

INSERT INTO table_name values (V1,v2,v3,.....);

INSERT INTO table_name (C1,C2) values (V1,V2);

Insert INTO websites (name,url,alexa,country) VALUES (' Baidu ', ' https://www.baidu.com ', 4, ' CN ')

The ID column is automatically updated

Insert INTO websites (name,url,country) VALUES (' StackOverflow ', ' http:/stackoverflow.com ', ' ind ')

8. SQL UPDATE

UPDATE table_name Set c1 = V1,C2 = V2 where c3 = V3;

The WHERE clause specifies which record or records need to be updated. If you omit the WHERE clause, all the records will be updated!

Update websites set Alexa =5000,country= ' USA ' where name= ' rookie tutorial '

9. SQL DELETE

Delete FROM table_name where c1 = v1;

The WHERE clause specifies which record or records need to be deleted. If you omit the WHERE clause, all records will be deleted!

Delete from websites where name= ' Baidu ' and country = ' CN '

Delete all records

DELETE from TABLE_NAME;

Or

DELETE * FROM table_name;

This article is from "Zhongyong's personal blog" blog, make sure to keep this source http://zhuangyong.blog.51cto.com/12459964/1887175

First, personal summary of the Novice tutorial |sql tutorial Knowledge points (SQL Tutorial)

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.