Oct 14, 2016

Interview Questions and answers - SQL Server Day 9

Question: What is the difference between char, nchar, varchar, and nvarchar in SQL Server?

Answer:
nchar and nvarchar can store Unicode characters.
char and varchar cannot store Unicode characters.
char and nchar are fixed-length which will reserve storage space for number of characters you specify even if you don't use up all that space.
varchar and nvarchar are variable-length which will only use up spaces for the characters you store. It will not reserve storage like char or nchar. For more details click here

Question: What is Difference between @@CONNECTIONS and @@MAX_CONNECTIONS in SQL Server?

Answer:
@@MAX_CONNECTIONS: @@MAX_CONNECTIONS returns maximum number of synchronous user connection allowed. SQL Server allowed by default maximum 32767 connections. To avoid many connections it can be configured at server level.
Note: Maximum connections (32767) are depending on application and server hardware limits.

@@CONNECTIONS: @@CONNECTIONS returns number of connection attempt on SQL Server since SQL Server has been started.
SELECT [ConnectionAttempts] = @@CONNECTIONS,
       [MaximumAllowed] = @@MAX_CONNECTIONS
For more click here 

Question: What is the difference between DATEFIRST and @@DATEFIRST in SQL Server?

Answer: DATEFIRST keyword use to reset first day of week in SQL Server and @@DATEFIRST return the current value for the session of DATEFIRST.
For details click here 

Question: What is Difference between a HAVING CLAUSE and a WHERE CLAUSE in SQL Server?

Answer:
WHERE clause applies to individual rows. While HAVING clause is like a WHERE clause, but applies only to groups as a whole.

The WHERE clause is applied first to the individual rows in the tables, means WHERE clause is fetched data from memory according to condition. The HAVING clause is applied to the rows in the result set, means first data is fetched from memory to result set then apply HAVING clause on the row of result set.


We can use WHERE clause with the HAVING clause, but it apply before the GROUP BY clause. We can apply a HAVING clause only to columns that also appear in the GROUP BY clause or in an aggregate function. For more details click here