---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