SQL Interview Questions – Basics Book III
What is the difference between a “where” clause and a “having” clause?
”Where” is a kind of restiriction statement. You use where clause to restrict all the data from DB.Where clause is used before result retrieving.
Ex:
Select * from EmployeeTable
Where EmpName = ‘Smith’
“Having” clause is used after Group by clause. It works the same way as the where clause on the results after applying group by.
Ex:
Select EmpName, Sum(salary)
From SalaryTable
Where SalaryDate >’01/01/2010’
Group By EmpName
Having Sum(Salary) > ‘200000’
What is the basic form of a SQL statement to read data out of a table?
The basic form to read data out of table is “SELECT * FROM table_name;”
What is a “constraint”?
A constraint allows you to apply simple integrity checks on a table. The primary types of constraints that are currently supported by SQL Server are :
PRIMARY/UNIQUE – enforces uniqueness of a particular table column.
FOREIGN KEY – validates that every value in a referenced column exists in a primary column of another table.