Sql Server Interview Questions and Answers (1758) - Page 13

How do we convert money to character?

convert(varchar,amount,1)
How do we find the duplicate records of a table?

Using the query

SELECT  empname, COUNT(*) AS n FROM employee GROUP BY  empname HAVING COUNT(*)>1

How do we find the last date of current month?

By the query

Select DateAdd(d,-day(GetDate()),GETDATE()-1) as LASTDATE

What is a table variable in T-SQL?

Table Variables are the special data type to store the values as in a table. This is stored inside of heap.
Tell me the difference between temporary table and table variable? Which is better?

Better one is table variable.

In most of our real time scenario we are using the temp table which is physically created in tempdb. This creates overhead, but when you create a table Variable it only resides in the memory which clearly shows that it will be much faster than Temp table.
A table variable goes out of scope immediately after the batch end. If we use Table Variable then we no need to explicitly drop it.
Write a sample syntax of table variable?

DECLARE @TableVariableSample table (ID int IDENTITY(1,1),Name VARCHAR(150) NOT NULL)

How to execute the stored procedure?

With exec keywork or directly we can execute a stored procedure
What is the use of Dense_Rank in Sqlserver?

Dense_Rank function produces the gaps in the ranking system
How to rename a database in SQLserver?

using the procedure sp_renamedb. Following is the syntax

Exec sp_renamedb ‘olddbname’,’newdbname’

How do we Unlock Particular User in Sql Server

First Login with Window Authentication then take Master Database
Afterwards, execute the below query

alter login databaseusername01 with password='password' unlock

What is the purpose of DATENAME fucntion?

DATENAME returns the part of the date in a literal form.

Following is the example
SELECT DATENAME(mm,GETDATE())

What is BCP?

The Bulk Copy Program (BCP) is a command-line utility that ships with SQL Server. It is used to transform data from one database to another.
What is DTS?

Data Transformation Services (DTS) in SQL Server 2000 provides a set of graphical tools and programmable objects to export and import data.
Which one is faster? BCP or DTS?

BCP is faster than DTS.
How do we get Current Months First Day?

SELECT CONVERT(VARCHAR(25),DATEADD(dd,-(DAY(getDate())-1),getDate()),101)

What is compute in sql server?

Compute generates totals that appear as additional summary columns at the end of the result set.
What is a COMPUTE BY statement?

COMPUTE BY statement has both detail and summary rows within the SELECT statement. It calculates the summary values for subgroups, or a summary value for the entire result set.
What is the use of @@CONNECTIONS statement?

@@CONNECTIONS returns the number of attempted connections, either successful or unsuccessful since SQL Server was last started.
What is the use of @@CPU_BUSY statement?

@@CPU_BUSY returns the time that SQL Server has spent working since it was last started.
Found this useful, bookmark this page to the blog or social networking websites. Page copy protected against web site content infringement by Copyscape

 Interview Questions and Answers Categories