Top SQL interview questions Part 1

What is the difference between the WHERE and HAVING clauses?

The WHERE clause is evaluated row by row, before the rows are grouped. The HAVING clause is evaluated after the rows have been grouped, so it is evaluated group by group.

Why are you not allowed to refer to a column alias defined by the SELECT
clause in the WHERE clause?


Because the WHERE clause is logically evaluated in the previous phase and after that It evaluates the SELECT clause.

Why are you not allowed to refer to a column alias defined by the SELECT
clause in the same SELECT clause ?

Because all expressions that appear in the same logical query processing phase are evaluated conceptually at the same point in time.

What are the forms of aliasing an attribute in T-SQL?

The forms are <expression>AS <alias> , <expression> <alias> , and

<expression> =<alias>

What is an irregular identifier?

An identifier that does not follow the rules for formatting identifiers; for example, it starts with a digit, has an embedded space, or is a reserved T-SQL keyword.

Would you use the type FLOAT to represent a product unit price?

No, because FLOAT is an approximate data type and cannot represent all values precisely

What is the difference between NEWID and NEWSEQUENTIALID?

The NEWID function generates GUID values in random order, whereas the NEWSEQUENTIAL ID function generates GUIDs that increase in a sequential order.

Which function returns the current date and time value as a DATETIME2 type?

SYSDATETIME

When concatenating character strings, what is the difference between the plus (+) operator and the CONCAT function

The + operator by default yields a NULL result on NULL input, whereas the CONCAT function treats NULLs as empty strings.


Comments

Popular Posts