TCS 10 Tricky SQL Server Interview Questions/Query Asked during TCS Interview

TCS SQL SERVER INTERVIEW QUESTIONS ANSWERS 2016 SET  Today I want to share my interview experince with you, TCS was looking for 4+ years...

TCS SQL SERVER INTERVIEW QUESTIONS ANSWERS 2016 SET 
Today I want to share my interview experince with you, TCS was looking for 4+ years SQL Server Experienced Developers, So I attend this interview(05/05/2016) to know the latest SQL Server question asked in marked currently.
Below are the set of query which are asked during my TCS interview question answers session(tech round), Which was held in Gurgaon TCS office. So be updated with new set of query, last query is most interesting. Some of them asked during HCL interview as well I had attend HCL interview as well. Most of them are very tricky queries. Must share with your friends.

1). How to select random record form a table? 
Ans: Select top 1 * from <TableName> order by newId()

2). Suppose that you have table Employee with a column EName which contain Records Employee name(EName) as  A,B,A,A,B,D,C,M,A, Write a query which will change/Swap the EName A to B and B to A.
Ans: UPDATE Employee
set EName = (CASE
WHEN EName='A' THEN 'B'
WHEN EName='B' THEN 'A'
ELSE EName
END)

3). Write a query to create a clone of existing table without using Create Command.
Ans: SELECT * INTO <NewTable> FROM <ExistingTable> WHERE 1=2
SELECT TOP 0 * INTO <NewTable> FROM <ExistingTable>

4). Table Tbl1 has 100 rows, Table Tbl2 has 0 rows so number of rows returned by the below query?
SELECT Tbl1.* from Tbl1, Tbl2;
Ans : No row will be retun by this query

5). Write a query to print 1 to 100 in sql server without using loops?
Ans: Use Recursive common table expression:
;WITH CTE
AS
(
SELECT 1 [Sequence]
UNION ALL
SELECT [Sequence] + 1 FROM CTE WHERE [Sequence] <100
)
SELECT * FROM CTE

Using Loop:
DECLARE @i INT
SET @i = 0
WHILE (@i < 100)
BEGIN
SELECT @i = @i + 1
PRINT @i
END

6). Write a query to calculate number of A in string 'VIKASAAA'?
Ans: SELECT LEN('VIKASAAA') - LEN(REPLACE('VIKASAAA', 'A', ''))

7). What would be the output of below query?
SELECT * FROM ( SELECT 1  UNION ALL SELECT 2 ) M
Ans: It will throw error because in sub query no column name specified

8). What would be the output of below query?
Ans: SELECT SUM(A) AS [Sum] FROM ( SELECT 1 A UNION ALL SELECT NULL A) M


9). For 5/2, I want resut as 2.5, How you will do that in SQL Server?
SELECT CAST(MyIntField1 AS float) / CAST(MyIntField2 AS float)

10). You have two tables with blank value in both table as shown in below image, Then what would be the output of the following Query based on the tables shown in image? 
SELECT T1.*, T2.* FROM Table1 T1 INNER JOIN Table2 T2
ON T1.Name = T2.Name


Ans: Output of the above query would be as below, Inner join will join both blank values
Click here for more query

Related

TRICKY SQL INTERVIEW QUESTION 1682518863047103618

Post a comment

  1. There should be an option for copy the content/question.

    ReplyDelete
    Replies
    1. press f12 for developer option from there u copy

      Delete
  2. Great, Sharing...

    ReplyDelete
  3. How to find the total no of column that contains '%' as a character in the string?
    Example:
    Column1
    20
    30
    40
    50%
    60
    70%
    80%
    90%
    10%

    in the above column we have 5 rows that contain %., so need a query for it?

    ReplyDelete
    Replies
    1. SELECT COUNT(1) FROM TABLENAME WHERE CHARINDEX('%',COLUMN1,0)>1
      SELECT COUNT(1) FROM TABLENAME WHERE LEN(COLUMN1)>2

      Delete
  4. Select count(*) count from tbl where column like '%/%%' escape '/'

    ReplyDelete

emo-but-icon

Follow Us

Recent

Comments

Donate

Side Ads

Text Widget

Connect Us

Sql Server 2017 Interview Questions
Sql Server Basic Interview Query Set-1
Sql Server Basic Interview Query Set-2
Sql Server Date-Time Interview Query SET-3
Sql Server Salary Interview Query SET-4
Sql Server Group By Interview Query SET-5
Sql Server Join Interview Query SET-6
Sql Server Tricky Join Interview Query SET-7
Sql Server DDL Interview Query SET-8
Small but very Tricky Sql Server Query SET-9
Very Much Tricky Query (not 4 fresher)SET-10
Sql Server Complex Interview Query SET-11
Sql Server Datatype Interview Questions
Sql Server View Interview Questions
Sql Server Index Interview Questions
TCS Tricky Sql Interview Queries
HCL Sql Interview Queries
Sql Server SP Interview Questions
Sql Server Trigger Interview Questions
Sql Server Temp Table Interview Questions
Sql Server 2016 Interview Questions
Sql Server Performance Tuning Interview Q.
Sql Server Constraints Interview Questions
Sql Server Storage/Size Interview Questions
Sql Server Very Basic Interview Questions
Sql Server Quiz for Fresher
Sql Server Icon Quiz for All
Sql Server 300+ Theoretical Interview Questions
Sql Server Complete Set

ASP.NET AND JQUERY INTERVIEW QUESTION
ASP.NET: Web Config Interview Question
ASP.NET: View State Interview Question
ASP.NET: Session Interview Question
ASP.NET: Session Interview Question 
ASP.NET: Security Interview Question
ASP.NET: Catching Interview Question
C# OOPS Interview Question
MORE Interview Question
JQUERY: Interview Question Set-1
JQUERY: Interview Question Set-2
JAVA-SCRIPT: Interview Question Set-1
JAVA-SCRIPT: Interview Question Set-2
ASP.NET MVC: Interview Question Set-1

POPULAR POSTS
10 MOST DIFFICULT INTERVIEW QUESTIONS
5 BEST INTERVIEW TIPS
YOUR 10 MISTAKE DURING INTERVIEW
2016 TOP 20 GROUP DISCUSSION TOPICS
HOW SQL PERFORMANCE AFFECTED BY DATATYPE
item