Recent review of SQL, found a lot of things have been forgotten, good memory is not as bad as the written wisdom,
SQL: Structured queries language (structed query language)
1. Create a database
CREATE DATABASE my_data_base;
2. Use the library you just created
use my_data_base;
3. Create a table named teacher
CREATE TABLE Teacher ( VARCHAR) , ageINT, birthday DATE );
3.1. You can check the table created below
DESC Teacher;
3.2. If you want to delete the created table
DROP TABLE Teacher;
4. Add Data
INSERT into Teacher ( name, age, birthday)VALUES( 'Tom'29 '1988-09-25' );
5. Look at how the table looks when you join the data
SELECT * from teacher;
6. Provide conditions for database search
SELECT * from WHERE='Tom';
7. Combine queries with AND and OR
SELECT * from WHERE='Tom'and= ;
8. Looking for data with a value of NULL
SELECT * from WHEREisNULL;
9. Use wildcards to find,% is an alias of any number of unknown characters, _ is an alias of an unknown character
SELECT * from Teacher WHERE like ' %o_ ';
10. Use range starting and ending values to query
SELECT * from Teacher WHERE between - and ;
11. Query by using column values to match the collection
SELECT * from Teacher WHERE in ('Tom'Tony' Jone');
12. Reverse the query, not necessarily immediately after the where
SELECT * from Teacher WHERE not in ('Tom'Tony' Jone ');
13. Delete Data
DELETE from Teacher WHERE ='Tom';
14. Updating data
UPDATE Teacher SET ='Mike'WHERE= ' Tony';
15. Add a PRIMARY key
ALTER TABLE Teacher ADD COLUMN INT not NULL auto_increment First, ADD PRIMARY KEY
15.1. Create primary key, primary key cannot be NULL, cannot be modified
CREATE TABLE teacher ( ID INTnotNULL auto_increment, VARCHAR (ten), age INT, birthday DATE, PRIMARYKEY (id));
16. Change the name of the table
ALTER TABLE to student;
17. Changing the column name type of a table
ALTER TABLE COLUMNVARCHAR(notNULL;
18. Changing only the type of a column does not interfere with its name
ALTER TABLE COLUMNVARCHAR(+);
19. Remove a column
ALTER TABLE Student DROP COLUMN School;
20. Sorting
SELECT * from Student ORDER by DESC;
21. Add function
SELECT SUM (age) from student;
22. Grouping additions
SELECT SUM from Student GROUP by ID;
23. Average function
SELECT AVG (age) from student;
24. Maximum minimum value
SELECT MAX from student; SELECT MIN from student;
25. Specify the number of rows in a column
SELECT COUNT from student;
26. Choose a different value
SELECT DISTINCT from student;
27. Limit the number of query results The first number is the start of the query, the second number is the number of returned query results
SELECT * from 0 1;
Review the SQL