For a database, you need to know more about the basic SQL statements. Below are some basic SQL statements.
Create problems
• Show database; displays existing databases
• Use database_x; database database_x should be used now
• Create table coffee (id int (5) not null, coffee_name varchar (25); create a table with two fields: id and coffee_name
• Alter table coffee add taste varchar (10); add a new column
• Insert into coffee (id, coffee_name, taste, rank) value ("1", "BlueMountain", "well", "5"); insert data
• Show columns from coffee; view the table structure
• Show create table coffee; view table information, including table creation statements
• Alter table student rename ss; change the table name
• Alter table ss drop mark; Delete the mark column in the table ss
Select statement
• Select * from coffee where id = "1"; query all information with id = 1
• Select coffee_name from coffee where id = "2"; query the coffee name with id = 2
• Select * from club where id between "1" and "3"; query entries with IDs ranging from 1 to 3.
• Select * from club where id = "1" or id = "3"; query the two entries id = 1 and id = 3.
• Select club_name from club where mark> 50; query club with a mark greater than 50
• Select club_name from club where mark not between 48 and 50; query club whose mark is not between 48 and 50
• Select * from club where id in ("1", "3", "4"); query entries with id = 1, 3, 4
• Select * from club where id not in ("1", "3", "4 ");
• Select * from club where name like "M % r"; wildcard % represents any length of characters (it can be 0 and two Chinese characters)
• Select * from club where name like "M_r"; _ indicates a single character
• Select * from club where id in ("1", "3", "4") and mark> 50; multi-Query
• Select * from club order by mark desc; sort by mark in descending order (desc: descending, usc: ascending)
Quantity Query
• Select count (*) from club; queries the number of records in club
• Select count (distinct mark) from club; number of records with different scores
• Select sum (mark) from club; sum of points
• Select avg (mark) from club; average points
• Select max (mark) from club; maximum points
• Select min (mark) from club; minimum points
Update statement
• Update club set mark = mark-8 where id = "1"; club credits with id = 1 are 8 points
Delete statement
• Delete from club where id = "001"; delete club information with id = 001
The preceding statements are the most basic part of SQL statement addition, deletion, modification, and query. They are entry-level and must be mastered.