Simple and common SQL commands

Source: Internet
Author: User

---restore content starts---

1 Database operations

1: Creating Databases: Create DATABASE <name>

2: Display database show databasess (note that there is a last s)

3: Delete Database drop <name>

2 Table Operation:

2.1 Get Table structure: desc <name> or Show columns from <name>

2.2 Delete tables: Drop table <name>

2.3 Insert a piece of data into the table: INSERT into < table name > [(< Field name 1>[,.. < field name n >])] VALUES (value 1) [, (value N)]

Eg:insert into MyClass values (1, ' Tom ', 96.45), (2, ' Joan ', 82.99), (2, ' Wang ', 96.59);

2.4 Enquiry Form:

Query all rows: Select *from <name>

View the first 2 rows of data in table MyClass
Mysql> SELECT * from MyClass ORDER by ID limit 0, 2;

2.5 Deleting a data delete from <name> where id=1

2.6 Modify the data in the table update class set Name= ' BB ' where id=1

DISTINCT clause: Select only a different value, repeat value only once

SELECT DISTINCT < column name > from < table name >

ORDER BY Statement : Sorts records in ascending order.

ORDER BY desc: Sort records in descending order

Select Company,ordernumber from Orders order by Company

SELECT Company, OrderNumber from OrdersORDER BY Company DESC

Insert a piece of data into the table:

INSERT into table_name (column 1, column 2,...) Values (value 1, value 2,....)

INSERT into table name values (value 1, value 2,....)

INSERT into Persons VALUES (' Gates ', ' Bill ', ' xuanwumen ', ' Beijing ')

UPDATE statement:

Update < table name > set < column name >= new value where column name = value

Update class set Name=joy where ID =3

UPDATE person SET Address = ' Zhongshan ", city = ' nanjing ' where LastName = ' wils '

Delete statement: Used to delete a row in a table

Delete from class where city= ' Beijing '

---restore content ends---

Simple and common SQL commands

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.