SQL Server 关键字

SQL Server (Transact-SQL) FROM 关键字用于指定应从中选择或删除数据的表。

示例:

考虑一个名为 Employee 的数据库表,其中包含以下记录:

EmpIDNameCityAgeSalary
1JohnLondon253000
2MarryNew York242750
3JoParis272800
4KimAmsterdam303100
5RameshNew Delhi283000
6HuangBeijing282800

选择姓名Employee表中存在员工的和Salary数据,可以使用以下查询:

SELECT Name, Salary FROM Employee; 

This将产生如下所示的结果:

NameSalary
John3000
Marry2750
Jo2800
Kim3100
Ramesh3000
Huang2800

要选择 Employee 表的所有字段,查询将为:

SELECT * FROM Employee; 

以下代码的结果将是:

EmpIDNameCityAgeSalary
1JohnLondon253000
2MarryNew York242750
3JoParis272800
4KimAmsterdam303100
5RameshNew Delhi283000
6HuangBeijing282800

要删除 EmpID 为 5 的员工的记录,查询将是:

DELETE FROM Employee
WHERE EmpID = 5;

--查看结果
SELECT * FROM Employee 

现在Employee表将包含以下记录:

EmpIDNameCityAgeSalary
1JohnLondon253000
2MarryNew York242750
3JoParis272800
4KimAmsterdam303100
6HuangBeijing282800

类似地,删除 city 以"New"开头的员工记录,查询将为:

DELETE FROM Employee
WHERE City LIKE 'New%';

-- 查看结果
SELECT * from Employee; 

现在Employee表将包含以下记录:

EmpIDNameCityAgeSalary
1JohnLondon253000
3JoParis272800
4KimAmsterdam303100
6HuangBeijing282800