CRUD–(创建、读取、更新、删除)
一、 创建数据
1.1、建表语句
CREATE TABLE table_name(column_1 data_type,column_2 data_type,column_3 data_type,);
1.2、插入式添加数据
INSERT INTO TABLE table_name (column_1,column_2,…,column_3) VALUES (value_1,value_2,…,value_n);
二、读取数据
2.1、基本查询语句
(1)SELECT column_1,column_2,…,column_n FROM table_name;
(2)SELECT * FROM table_name;
2.2、WHERE过滤查询
SELECT column_1,column_2,…,column_n FROM table_name WHERE cloumn_name operator value;
operator说明:
1、”=”(等于);”>”(大于);”<”(小于)
2、”>=”(大于等于);”<=”(小于等于);”<>”(不等于)
3、BETWEEN(在两个值之间)
4、LIKE(匹配搜索/模糊搜索)
5、IN(针对一个列的多种可能性)
2.3、组合逻辑运算符”AND”和”OR”
SELECT * FROM table_name WHERE column_name = value_1 AND value_2;
可以替换为IN语句:
SELECT * FROM table_name WHERE column_name IN (value_1,value_2);
2.4、排序ORDER BY
SELECT * FROM table_name WHERE column_name operator value_1 ORDER BY value_2;
加上DESC表示降序
SELECT * FROM table_name WHERE column_name operator value_1 ORDER BY value_2 DESC;
三、更新数据
UPDATE table_name SET column_name = new_value WHERE column_name operator value;
四、删除数据
1.1、删除所有
DELETE FROM table_name;
1.2、WHERE过滤删除
DELETE FROM table_name WHERE column_name operator value;
1.3、移除表和表内容
DROP TABLE table_name;