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

What is difference between RANK and DENSE_RANK.

The main difference between RANK and DENSE_RANK comes when they leave gap among records while ranking them.

For an example, if you have three records at position one. Both the functions will place all three records at same position of one but the difference comes is when they rank the next record. RANK() will rank the next record as fourth record while DENSE_RANK() will rank it as second.
What will you do if you need to create clustered index on more than one field? Is it possible?

The answer is yes and no.
You can create only one clustered index in table.
Workaround for such scenario can be :
Either you can create index on entire table or you can create clustered index on a view covering entire table.

Suppose, you have created table with following:
CREATE TABLE [dbo].[Table1](

[field1] [int] IDENTITY(1,1) NOT NULL,
[field2] [nchar](10) ,
[field3] [nchar](10) ,
[field4] [nchar](10)
) ON [PRIMARY]

Create index on entire table:
CREATE INDEX idx_coverTable ON Table1(field1, field2) INCLUDE (field3, field4)

Create clustered index on a view covering entire table:
CREATE VIEW v1111 with SCHEMABINDING

AS
SELECT field1, field2, field3, field4 FROM dbo.Table1
GO
CREATE UNIQUE CLUSTERED INDEX idx_viewClustered ON dbo.v1111(field1, field2, field3, field4)
GO


Thanks,
Bhakti Shah
Can you control concatenation of string values with null values? How ?

We can control this by setting CONCAT_NULL_YIELDS_NULL on or off.
When it is set to ON, the concatenation will result null and when it is set to OFF, it will result the string.
Setting it ON,
SET CONCAT_NULL_YIELDS_NULL on;

print 'testing' + NULL; --results NULL and prints nothing


Setting it OFF,

SET CONCAT_NULL_YIELDS_NULL off;

print 'testing' + NULL; -- results testing and prints the same

This is used to terminate a query when an overflow or divide-by-zero error occurs during query execution…

NOTE: This is objective type question, Please click question title for correct answer.
SET NOCOUNT specified settings are in effect at…

NOTE: This is objective type question, Please click question title for correct answer.
SET OFFSETS specified settings are in effect at…

NOTE: This is objective type question, Please click question title for correct answer.
To terminate SQL Server immediately, used is…

NOTE: This is objective type question, Please click question title for correct answer.
Return type of RAND() is...

NOTE: This is objective type question, Please click question title for correct answer.
Write and justify output of - select nullif('test','test')

The output will be – NULL
Justificatio n : nullif returns NULl if given two arguments are same else returns the first specified argument. So, for the given SQL, output will be NULL.
How to get date of 234 days back in SQL?

SQL :
SELECT DATEADD(dd,-234,getdate())
What is SIGN() ?

SIGN() is used to determine whether the specified is positive, negative or zero. In case of positive, negative and zero it returns +1,-1 and 0 consecutively.

print sign(0) -- prints 0

print sign(10) -- prints 1
print sign(-10) -- prints -1


Sometimes before using SIGN(), you need to confirm you are passing numeric value as argument.
You can do this using, ISNUMERIC()
SQL_VARIEANT datatype column can be any datatype except?

NOTE: This is objective type question, Please click question title for correct answer.
Which of the following is a Large object Binary Data Type?

NOTE: This is objective type question, Please click question title for correct answer.
Which of the following is a Large object data type?

NOTE: This is objective type question, Please click question title for correct answer.
INNER JOIN cannot be used without the

NOTE: This is objective type question, Please click question title for correct answer.
select COUNT(column_name) from table_name counts only

NOTE: This is objective type question, Please click question title for correct answer.
Which of the following is a Aggreate Function?

NOTE: This is objective type question, Please click question title for correct answer.
What will be the OutPut of the following Query? Select CELING(7.69) as number

NOTE: This is objective type question, Please click question title for correct answer.
what is CHECK Constraint?

The CHECK constraint is used to limit the value range that can be placed in a column.

If you define a CHECK constraint on a single column it allows only certain values for this column.
If you define a CHECK constraint on a table it can limit the values in certain columns based on values in other columns in the row.

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