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

Waht is the output of below ? DECLARE @Date DATETIME = '2015/07/01 10:23AM' SELECT FORMAT(@Date, 'tt', 'en-US')

NOTE: This is objective type question, Please click question title for correct answer.
Which of the followinf is NOT VALID for TRUNCATE TABLE statement?

NOTE: This is objective type question, Please click question title for correct answer.
How to format datetime to MMM.YYYY format?

SELECT REPLACE(RIGHT(CONVERT(VARCHAR(11),GETDATE() , 106), 8), ' ', '.') AS [Mon.YYYY] 


OutPut:
Mon.YYYY
Jul.2015
How to format datetime value to Mon.YY ?

SELECT RIGHT(REPLACE(CONVERT(VARCHAR(9),GETDATE(), 6), ' ', '.'), 6) AS [Mon.YY] 



Output:

Mon.YY
Jul.15

Which commands among the following execute faster?

NOTE: This is objective type question, Please click question title for correct answer.
How SQL Server 2008's Hierarchyid performs the Tree Traversal?

NOTE: This is objective type question, Please click question title for correct answer.
How to pass table variable as a parameter in Sql Server Stored Procedure?

We need to use Dynamic SQL Approach.

e.g

CREATE PROCEDURE usp_PassTableVariable @table_name SYSNAME

AS
BEGIN
DECLARE @SQL NVARCHAR(MAX)
SET @SQL = 'SELECT *
FROM '+ @table_name
EXEC sp_executesql @SQL
END


OR

CREATE PROCEDURE usp_PassTableVariable @table_name VARCHAR(100)

AS
BEGIN
DECLARE @SQL NVARCHAR(MAX)
SET @SQL = 'SELECT *
FROM '+ @table_name
EXEC sp_executesql @SQL
END


Execute as: EXEC usp_PassTableVariable '[dbo].[tblLocation]'

LocationID	Latitude	Longitude

1 26.457904 80.320663

Which kind of object does SQL Server 2008 provided by using which we can pass table type variable to the stored procedures?

NOTE: This is objective type question, Please click question title for correct answer.
With an example how can we create a Table Valued Parameter in Sql Server 2008?

Assuming we have a table by the name tblTest with the below columns
ID  INT,

Name VARCHAR(50)


Step 1: Declare a new table User Defined Type
CREATE TYPE tblTestType AS TABLE

(
ID INT,
Name VARCHAR(50)
)


Step 2: Create a STORED PROCEDURE that has tblTestType as parameter
CREATE PROCEDURE countcv

(
@tblName tblTestType readonly
)

AS
INSERT INTO tblTest (ID, Name)
SELECT ID, Name
FROM
@tblName;

How can you prevent user to enter duplicate value into column while creating a table?

NOTE: This is objective type question, Please click question title for correct answer.
You would include a HAVING clause in a query to

NOTE: This is objective type question, Please click question title for correct answer.
Which of the following is a server-scoped securable?

NOTE: This is objective type question, Please click question title for correct answer.
What is the purpose of Lead Function in Denali?

NOTE: This is objective type question, Please click question title for correct answer.
Which of the following is true about Lead Function of DENALI?

NOTE: This is objective type question, Please click question title for correct answer.
Which of the below are true about the LEAD FUNCTION of Denali?

NOTE: This is objective type question, Please click question title for correct answer.
Explain the below Lead(expression [,offset [,default] ] ) over( [ Partition_By_clause] order by clause)

Expression => A table column or built-in function but not analytical functions

Offset => It is optional and represents the physical offset from the current row in the table. If not specified, the default value is 1 and cannot accept negative numbers.

Default = > It is again optional. If not specified, then whenever the offset value goes out of the table bounds, then default null is returned.

Partition_By_clause = > Partition the query result set. It is again optional

Order By Clause = > Indicates how the data is ordered within the partition.
Which of the following is true about Lag Function of DENALI?

NOTE: This is objective type question, Please click question title for correct answer.
Explain the below Lag(expression [,offset [,default] ] ) over( [ Partition_By_clause] order by clause)

Expression => A table column or built-in function but not analytical functions

Offset => It is optional and represents the physical offset from the current row in the table. If not specified, the default value is 1 and cannot accept negative numbers.

Default = > It is again optional. If not specified, then whenever the offset value goes out of the table bounds, then default null is returned.

Partition_By_clause = > Partition the query result set. It is again optional

Order By Clause = > Indicates how the data is ordered within the partition.
Which of the below are true about the LAG FUNCTION of Denali?

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