SQL 基础增删改查语句

时间:2022-12-26 10:42:09

1. select

查询一个表的所有结果集。

select * from Persons

SQL 基础增删改查语句


2.关键词 DISTINCT 用于返回唯一不同的值

SELECT DISTINCT FirstName FROM Persons

SQL 基础增删改查语句


3.WHERE

SELECT * FROM Persons WHERE City = 'Beijing'

SQL 基础增删改查语句


4.AND 和 OR运算符


SELECT * FROM Persons WHERE (LastName = 'Bush' or LastName = 'David') and FirstName = 'George'

SQL 基础增删改查语句


5.ORDER BY 语句用于对结果集进行排序

默认ASC升序,DESC 降序

SELECT City FROM Persons ORDER BY City DESC

SQL 基础增删改查语句


6.INSERT

插入新的行:

INSERT INTO Persons VALUES (5,'Gates', 'Bill', 'Xuanwumen 10', 'Beijing')

向指定的列插入数据:

INSERT INTO Persons (Id_P,LastName, Address) VALUES (6,'Wilson', 'Champs-Elysees')

SQL 基础增删改查语句


7.UPDATE

更新某一行中的若干列:

UPDATE Persons SET Address = 'Zhongshan 23', City = 'Nanjing' WHERE LastName = 'Wilson'

SQL 基础增删改查语句


8.DELETE

删除某行:

DELETE FROM Persons WHERE LastName = 'Wilson' 

SQL 基础增删改查语句