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

I have a employe table which has SlNo as Identity column. Currently the identity is 100. Now due to some reason last 50 rows (SlNo 51-100) has been removed. Now write a synatx to reset the identity to 51.

To Reset the identity we need to use the following statement. But caution to be taken that the identity column should not be the primary key.

DBCC CHECKIDENT('tbl_Employee', RESEED, 51) 

On executing the above query the output will be

Checking identity information: current identity value '18', current column value '51'.

DBCC execution completed. If DBCC printed error messages, contact your system administrator.

You have a Studets table as follows. The student table doesn't contains SlNo. You need to create a reoprt with SlNo. Write a query that add SlNo with the result set. The student Master table is : StuID SName Marks S001 Naga 98 S102 Sundar 92 S203 Ganesh 95 S158 John 85 S211 Kumar 90

We need to use Row_Number() function to obtain the result. Row_Number() gives the sequential number of a row within a partition of a result set, starting at 1 for the first row in each partition. The query is

  SELECT ROW_NUMBER() OVER (ORDER BY StuID ASC) AS 'SlNo' ,* from StudentMaster


I used order by with StudentID. So student id gets ordered in ascending at first and then RowNumber() function will be implemented on the result set.

The output will be

SlNo  StuID   SName   Marks

1 S001 Naga 98
2 S102 Sundar 92
3 S158 John 85
4 S203 Ganesh 95
5 S211 Kumar 90

You have a Employe table with EmpId, EmpName, EmpAge. There are 5 records as of now. EmpId is a primary key with identity column. Now the identity value is 5. You need to start the identity value from 10 instead of 6. Write the query for that?

We need to add identity column value explicitly. For that we can use the following query:

Set identity_insert EmployeMaster on 

Insert into EmployeMaster(EmpId, EmpName, EmpAge)
values (10,'Shankar',19)


In the above query I mentioned "Identity_Insert on" for table name EmployeeMaster. Second I specified all the column names and inserted the values corresponding to tht column. Now we will be having identity value as 10.
Which of the following query will give the DAY of today? (if today is Sunday menas Sunday should come)

NOTE: This is objective type question, Please click question title for correct answer.
Which built-in function you can use for converting string data type to date/time and number type ?

NOTE: This is objective type question, Please click question title for correct answer.
How many columns you can created with View?

NOTE: This is objective type question, Please click question title for correct answer.
Which of the following SQL statements moves the Employees table from the Production schema to the Sales schema?

NOTE: This is objective type question, Please click question title for correct answer.
What is the Maximum Number of Index per Table?

In SQL Server 2005:
1 Clustered Index and 249 Nonclustered Index, Total 250 Index per table.

For SQL Server 2008:
1 Clustered Index and 999 Nonclustered Index, Total 1000 Index per table.
How many indexes can be applied to the table in both sql 2005 and 2008?

NOTE: This is objective type question, Please click question title for correct answer.
How to Insert multiple records in an insert statement in a single line..

INSERT INTO tbl_Student(Name,Class)


SELECT 'Ali','IV Standard'

UNION ALL

SELECT 'John','V Standard'

UNION ALL

SELECT 'Abraham','X Standard'

Can you split the one column in to two columns For Ex:FullName:Aswini Aluri It must split into firstname: Aswini. LastName :Aluri

create table splitS(FullName NVARCHAR(50))
select LEFT(fullname, CHARINDEX(' ', fullname + ' ') -1),
STUFF(fullname, 1, Len(FullName) +1- CHARINDEX(' ',Reverse(fullname)), '')
from splitS


insert into splitS values('ASWINI ALURI')
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