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

Give any example of WaitFor Delay Command?

SELECT GETDATE() CurrentTime;

WAITFOR DELAY '00:00:10' 10 Second Delay
SELECT GETDATE() CurrentTime;


WAITFOR DELAY '10:30';
--10 Hours and 30 Minutes
How can we Replace Multiple Spaces in String with a Single Space in Sql Server?

We have to write below code:-
Select Replace(Replace(Replace(@str,' ','{}'),'}{',''),'{}',' ');

DECLARE @str varchar(150)
SET @str='Hello Welcome to dot net funda . com'
Select Replace(Replace(Replace(@str,' ','{}'),'}{',''),'{}',' ')


Output:-
Hello Welcome to dot net funda . com

Alternatively,we can create a Function,which will return us a string and this function may be used in different places.
How will we Rename a Table in Sql Server?

By using sp_rename stored procedure,we can rename any Table in Sql Server.
How can we Load large no of data in Sql Server?

BulkCopy is a tool used to copy huge amount of data from tables. BULK INSERT command helps to Imports a data file into a database table or view in a user-specified format.
How can we execute a DOS command from Sql Server?

Using xp_cmdshell extended Stored Procedure:-
exec xp_cmdshell 'dir c:\*.exe'

How to use Parsename in-built function to split delimited data?

Use below query:-
select parsename(replace(isnull('vishal kumar',''),' ','.'),1);

Output:
kumar

select parsename(replace(isnull('vishal kumar',''),' ','.'),2);

Output:
vishal

How to List All Tables of Database?

Using Sys.table,we can find out all database Tables:-
Select * 

From sys.Tables;

What is an alternate way to List All Tables of Database?

Using Information_Schema.Tables,we can find out all database Tables:-
Select * 

From Information_Schema.Tables;

How to Count number of Tables in a Sql Server Database?

select count(*) from information_schema.tables

where table_type = 'base table';

When to use DDL Triggers in Sql Server?

NOTE: This is objective type question, Please click question title for correct answer.
How to Remove Duplicate Records in Sql Server when Tables have No primary key defined?

WITH temp_Table as

(
SELECT ROW_NUMBER() Over(PARTITION BY FirstName,LastName,PAN_No ORDER BY FirstName) As RowNumber,*
FROM Employee_Master;
)
DELETE FROM temp_Table where RowNumber >1;

SELECT * FROM Employee_Master order by FirstName asc;

How to Remove Duplicate Records in Sql Server when Tables have Primary Key defined?

SELECT * FROM Employee_Master Group By PAN_No

Having Count(Pan_No) >1;

Which statement is(are) TRUE about @@Identity function?

NOTE: This is objective type question, Please click question title for correct answer.
Which statement is the correct statement for removing column from an existing table in Sql Server?

NOTE: This is objective type question, Please click question title for correct answer.
Which statement is(are) correct about Group By clause?

NOTE: This is objective type question, Please click question title for correct answer.
In how many ways we can select distinct records from a table?

NOTE: This is objective type question, Please click question title for correct answer.
Which keyword is used to call Stored Procedure?

NOTE: This is objective type question, Please click question title for correct answer.
What command is used to set a set of privileges that can be granted to users or different roles in Sql Server?

NOTE: This is objective type question, Please click question title for correct answer.
What is the use of Wildcard?

NOTE: This is objective type question, Please click question title for correct answer.
Which statement is used to define a Cursor?

NOTE: This is objective type question, Please click question title for correct answer.
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