What is SQL server agent?

QA-SQL Server

SQL Server agent plays an important role in the day-to-day tasks of a database administrator (DBA).

It is often overlooked as one of the main tools for SQL Server management. Its purpose is to ease the implementation of tasks for the DBA, with its full-function scheduling engine, which allows you to schedule your own jobs and scripts.

What is sub-query? Explain properties of sub-query.

QA-SQL Server

Sub-queries are often referred to as sub-selects, as they allow a SELECT statement to be executed arbitrarily within the body of another SQL statement. A sub-query is executed by enclosing it in a set of parentheses. Sub-queries are generally used to return a single row as an atomic value, though they may be used to compare values against multiple rows with the IN keyword. Continue reading “What is sub-query? Explain properties of sub-query.”

What is the difference between a HAVING CLAUSE and a WHERE CLAUSE?

QA-SQL Server

Specifies a search condition for a group or an aggregate.

  1. HAVING can be used only with the SELECT statement.
  2. HAVING is typically used in a GROUP BY clause. When GROUP BY is not used, HAVING behaves like a WHERE clause.
  3. Having Clause is basically used only with the GROUP BY function in a query.
  4. WHERE Clause is applied to each row before they are part of the GROUP BY function in a query.
  5. HAVING criteria is applied after the the grouping of rows has occurred.

Difference between Function and Stored Procedure?

QA-SQL Server

User-Defined Functions(UDF) can be used in the SQL statements anywhere in the WHERE/HAVING/SELECT section

where as Stored procedures cannot be.
UDFs that return tables can be treated as another rowset. This can be used in JOINs with other tables.
Inline UDF’s can be though of as views that take parameters and can be used in JOINs and other Rowset operations.

How to implement relationships while designing tables?

QA-SQL Server

One-to-One relationship can be implemented as a single table and rarely as two tables with primary and foreign key relationships.
One-to-Many relationships are implemented by splitting the data into two tables with primary key and foreign key relationships.
Many-to-Many relationships are implemented using a junction table with the keys from both the tables forming the composite primary key of the junction table.