SQL Server Tutorial SQL Server Advanced SQL Server Database SQL Server References

SQL Server - FROM Keyword



The SQL Server (Transact-SQL) FROM keyword is used to specify the table from which the data should be selected or deleted.

Example:

Consider a database table called Employee with the following records:

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

  • To select the Name and Salary data of the employees present in the Employee table, the following query can be used:

    SELECT Name, Salary FROM Employee;
    

    This will produce the result as shown below:

    NameSalary
    John3000
    Marry2750
    Jo2800
    Kim3100
    Ramesh3000
    Huang2800
  • To select all fields of the Employee table, the query will be:

    SELECT * FROM Employee;
    

    This result of the following code will be:

    EmpIDNameCityAgeSalary
    1JohnLondon253000
    2MarryNew York242750
    3JoParis272800
    4KimAmsterdam303100
    5RameshNew Delhi283000
    6HuangBeijing282800
  • To delete the records of an employee whose EmpID is 5, the query will be:

    DELETE FROM Employee
    WHERE EmpID = 5;
    
    --See the result
    SELECT * FROM Employee
    

    Now the Employee table will contain following records:

    EmpIDNameCityAgeSalary
    1JohnLondon253000
    2MarryNew York242750
    3JoParis272800
    4KimAmsterdam303100
    6HuangBeijing282800
  • Similarly, to delete the records of an employee where city starts with 'New', the query will be:

    DELETE FROM Employee
    WHERE City LIKE 'New%';
    
    -- see the result
    SELECT * from Employee;
    

    Now the Employee table will contain following records:

    EmpIDNameCityAgeSalary
    1JohnLondon253000
    3JoParis272800
    4KimAmsterdam303100
    6HuangBeijing282800

❮ SQL Server Keywords