Saturday, June 8, 2013

SELECT * FROM table_name

SELECT * FROM HumanResources.Employee

Never use: SELECT * FROM - in production code.

Reason:

1. COLUMNS can vary. Addition or removal of columns affect client application using them.
2. Network traffic - No need to select all the information, if you need only very few.

OperatorDescription
!=Tests two expressions not being equal to each other.
!>Tests whether the left condition is less than or equal to (i.e., not greater than) the condition on the right.
!<Tests whether the left condition is greater than or equal to (i.e., not less than) the condition on the right.
<Tests the left condition as less than the right condition.
<=Tests the left condition as less than or equal to the right condition.
<>Tests two expressions not being equal to each other.
=Tests equality between two expressions.
>Tests the left condition being greater than the expression to the right.
>=Tests the left condition being greater than or equal to the expression to the right.

SELECT * FROM HumanResources.Employee
WHERE JobTitle='SALES Representative'

WHERE - can be combined with AND and OR 

SELECT 
FirstName
,LastName AS [Surname]
FROM
Person.Person


COLUMN ALIAS

SELECT BusinessEntityID AS EmployeeID
       ,VacationHours + SickLeaveHours AS [TotalHolidaysAvailable]
FROM HumanResources.Employee;

TABLE ALIAS:

SELECT E.BirthDate FROM HumanResources.Employee AS E

No comments:

Post a Comment