Transact-SQL Retrieve Data From A Table Examples


Tool : Microsoft SQL Server Management Studio (SSMS)

Transact-SQL Create Database And Create Table Examples

Transact-SQL Insert Data Into Table Examples

Retrieve All The Data from The Table [Departments]

/* Retrieve all the data from the table [Departments] in the database [SampleDB] */

Use [SampleDB]
Go
Select * From [Departments]

retrieve : get or bring (something) back

Retrieve Specific Columns from the table [Departments]

/* Retrieve specific columns (Name and Location) from the table [Departments] in the database [SampleDB] */

Use [SampleDB]
Go
Select Name,Location From [Departments]


Join (Concatenate) Columns of The Table [Employees]

/* Join (concatenate) columns of the table [Employees] in the database [SampleDB] */

Use [SampleDB]
Go
Select FirstName + ' ' + LastName As FullName 
From [Employees]

concatenate : link (things) together in a chain or series

Specify Multiple Values In A Where Clause

/* Specify multiple values In a Where Clause */

Use [SampleDB]
Go
Select * From [Employees]
Where FirstName In ('Daisy','Andrea','Jason')

specify : identify clearly and definitely

Select Data Between Two Values

/* Select data between two values in the table [Employees] */

Use [SampleDB]
Go
Select * From [Employees]
Where Salary Between 40000 and 50000


張貼留言

0 留言