Q.1 What are Left
Outer Join, RIGHT Outer and Full Joins in SQL?
In Left outer Join it retrieves all the matching rows from
first table with second one, and complete rows from first table (unmatched)
too.
In Right outer Join it retrieves all the matching rows from
second table with first one, and complete rows from second table (unmatched)
too.
In Full Join it retrieves all the matching rows from second
table with first one, and complete rows from both the tables (unmatched) too.
Q.2 How to get
Highest (nth) & Lowest (nth) Salary?
For 3rd Highest Salary
SELECT TOP 1 marks, name from (SELECT TOP 3 marks, name from MyTable ORDER BY marks ASC) a ORDER BY marks
GO
For 3rd Lowest Salary
SELECT MIN(marks) from (SELECT TOP 3 marks from MyTable ORDER BY marks ASC) a
Q.3 Give an example
of Self Join?
The best example of self-join is to get employee with their
reporting manager e.g.:
Employee Master Table
id
|
name
|
ReportingTo
|
1
|
Satish Pal
|
NULL
|
2
|
Suraj Mishra
|
1
|
3
|
Hariom Mishra
|
NULL
|
4
|
Arvind Trivedi
|
3
|
5
|
Ved Pathak
|
NULL
|
6
|
Pradeep Kedare
|
5
|
Step 1.
You can find employee with their manager only using simple
self –join as:
select A.name, B.name from MyTable A ,MyTable
B WHERE B.ID = A.ReportingTo
Step 1.
You can find employee as well as their manager in
record as:
select A.name, ISNULL(B.name,'Manager') as ReportTo from MyTable A LEFT JOIN MyTable B ON B.ID = A.ReportingTo
Q.4 what is major
difference between stored procedure and functions?
Procedures
|
Functions
|
It is used for select as well as DML(Insert, Update, Delete)
operations
|
It is only used for select operations
|
It takes input and output both parameters
|
It takes only input parameters
|
It cannot be used in select query.
|
It is used in select query.
|
Exception handling try, catch can be used
|
Exception handling try, catch cannot be used
|
It can call functions
|
It cannot call procedures
|
It can return 0 or more values
|
It is mandatory to return one value
|
Q.5 what is
difference between CHAR, VARCHAR, VARCHAR2 & NVARCHAR?
We must have gone through in interview sometimes with the
biggest confusing difference of above questions, as it is very simple but
sometimes we get confuse to give right answer to interviewer:
Here I have found the major differences in all:
CHAR
|
NCHAR
|
Char is used for fixed length of data type
|
NChar is used for fixed length of data type
|
Char takes 1byte memory space for each character
|
NChar takes 2bytes memory space for each character
|
Char stores non-Unicode characters
|
NChar stores Unicode characters
|
Ex:DECLARE @gender char(10)
SET @gender=’Male’ as variable @gender take only 4 bytes space but it
takes full space of 10 bytes when you see actual data length .
|
Ex:DECLARE @gender nchar(10)
SET @gender=’Male’ as variable @gender take only 4 bytes space but it
takes full space of 20 bytes when you see actual data length . It takes
double of declared size length. Here
we can use multi languages i.e Hindi, English, Spanish etc.
|
VARCHAR
|
NVARCHAR
|
VarChar is used for variable length of data type
|
NVarChar is used for variable length of data type
|
VarChar takes 1byte memory space for each character
|
NVarChar takes 2bytes memory space for each character
|
VarChar stores non-Unicode characters
|
NVarChar stores Unicode characters
|
Ex:DECLARE @gender varchar(10)
SET @gender=’Male’ as variable @gender take only 4 bytes & actual
data length is also only 4 bytes.
|
Ex: DECLARE @gender nvarchar(10)
SET @gender=’Male’ as variable @gender take only 4 bytes & actual
data length is 8 bytes. It takes double of the used memory space. Here we can
use multi languages i.e Hindi, English, Spanish etc.
|
You can use this query to verify the exact space of bytes by
below example
DECLARE @gender as char(10)
SET @gender='Male'
SELECT LEN(@gender), DATALENGTH(@gender)
Q.6 what is Serialization
and De-serialization?
Process where converting the objects in to stream of bytes
is called serialization.
Process where creating the objects from stream of bytes is
called De-serialization.
Q.7 what is Garbage
collection?
Garbage Collection is also known as automatic memory
management, is the automatic recycling of dynamically allocated memory.
In .Net CLR has Garbage Collector that executes as a part of
the program in application and responsible for reclaiming the memory of no
longer used objects. Garbage collector frees the memory for objects that are no
longer used and keeps the memory free for future allocations.
Q.8 what is MSIL?
Q.9 what is the
difference between Server.Transfer and Response.Redirect ?
In asp.net both are
used for navigation purpose from source to destination page.
Server.Transfer works for .aspx page only, it does not take
round trip back to client browser by processing one page to another.
Response.Redirect works for internal and external both pages
(I.e. .aspx page, www.yahoo.com) but it
takes round trip back to client browser to complete.
Q.10 what is
Globalization and Localization?
Globalization is the process of creating multilingual
application by defining culture specific features i.e. Currency, date time
format, Language etc.
Localization is the process of cooperating cultural
differences in application.
Q.11 what is Partial
Class?
When there is a need to keep the business logic separate
from the user interface or when there is some class which is big enough to
handle by multiple programmers want to implement method from this class, the
class can be separate and written in different files as partial class:
As example:
Here is partial class file 1:
///
/// Summary description for myPartialClass1
///
public partial class myPartialClass
{
public int GetAge()
{
int age = 25;
return age;
}
}
Here is partial class file 2:
///
/// Summary description for myPartialClass2
///
public partial class myPartialClass
{
public int GetAge()
{
int age = 25;
return age;
}
}
You can access both methods as :
myPartialClass objPartial = new myPartialClass();
string name = objPartial.GetName();
int age = objPartial.GetAge();
Response.Write("Name :" +
name + " Age :" + age);
Partial classes allow us to divide the class definition into
multiple files i.e. (myPartialClass1, myPartialClass2). Although, all
the partial classes are treated as a single file by the compiler.
Q.12 what is the
difference between Custom Control and User Control?
Custom control are in pre-compiled form i.e (in the form of
dll), this can be added into toolbox where most of the inbuilt controls already
resides (Textbox, Dropdown etc.). Not easy to customize as per application
requirements.
It is ready to use like drag-drop features and reusable to
multiple applications.
User Controls are compiled with the application and it is
like .aspx page (with .ascx extension) . It is very easy to create and tightly
coupled with user interface and code. It is easy to customize as per
application requirements.
In order to User Control you have top copy and paste
manually to other applications.
Q.13 what is .Net
Framework?
A programming infrastructure created by Microsoft for
building, deploying, and running applications and services that use .NET
technologies, such as desktop applications and Web services. The .NET
Framework contains three major parts: the Common Language Runtime. The Framework Class
Library
Q.14 How to find out
Doctor who has seen most patients by using below table structures?
tblDoctor
|
|
doctorID
|
doctorName
|
1
|
Arvind Trivedi
|
2
|
Satish Pal
|
3
|
Hariom Mishra
|
4
|
Vikas Pathak
|
tblPatient
|
||
patientID
|
doctorID
|
patientName
|
1
|
1
|
rahul d
|
2
|
1
|
sunil s
|
3
|
2
|
hemant s
|
4
|
2
|
priya s
|
5
|
2
|
nayak s
|
6
|
2
|
ritu p
|
7
|
3
|
umesh
|
8
|
3
|
dinesh
|
1
|
1
|
rahul d
|
2
|
1
|
sunil s
|
Here is the query to get highest number of patient seen by
doctor:
SELECT TOP 1 D.doctorName as Doctor, COUNT(P.patientID) as [Patient Count] from tblDoctor D INNER
JOIN tblPatient P
ON D.doctorID = P.doctorID
GROUP BY D.doctorName
ORDER BY COUNT(P.patientID) DESC
Q.15 What is Assembly
in ASP.Net?
An assembly is a collection of types and resources that
forms a logical unit of functionality.
When you compile an application, the MSIL code created is
stored in an assembly.
Assemblies include both executable application files that
you can run directly from Windows without the need for any other programs
(these have a .exe file extension), and libraries (which have a .dll extension)
for use by other applications.
There are two types of assemblies in .NET;
1.
Private
2. Shared
Q.16 Difference
between ASMX web service and WCF?
There are many options to create we services using .net
framework. As web services were used before introducing WCF (indigo). WCF is
the latest model to create the web service. There are more advantages over .asmx
using WCF. Here will see all comparison on both:
ASMX
Here we defined WebService and WebMethod attributes to
define web services.
Support only HTTP, HTTPS protocol.
Hosted only on IIS.
Security is lesser than WCF.
It supports one way and Request-Response Service operations.
Services are little slow compare to WCF.
Unhandled exception return to client.
It does not support multithreading.
WCF
Here we defined Service Contract and Operation Contract
attributes to define WCF services.
Support only HTTP, HTTPS, TCP, and Named Pipes and MSMQ protocol.
Hosted on IIS, Self-hosting, WAS (windows Activation Services)
and windows service.
Security is more.
It supports one way and Request-Response and Duplex Service
operations.
WCF is faster.
Unhandled exception handled by exception handling method
using FAULT CONTRACT.
It supports multithreading using Service behaviour class.
Q.17 How to find nth highest, odd numbers, even
numbers from integer array value in C# using LINQ?
Most of the time interviewer asked about to writes above query
to find out the second highest number, even numbers, and odd numbers from array
using LINQ. Here are the simple methods to find out:
int [] i = { 1, 2, 3, 4, 5, 6 };
To find 2nd highest number from above array:
var highestNums = (from n in i
orderby
n descending
select
n).Skip(1).Take(1);
On above query expression first
we take variable in from array order by number in descending and select all the
numbers, this is as simple as retrieving all the numbers from array.
The next step to bypass the number from list using SKIP
function (as second highest then skip first number from list). And the last to
get only that number in the result we used Take function (Take (1)) means it
will retrieve only one result, otherwise it gives all the result from the array
excluding one record.
To find even numbers from above array:
var evenNums = (from n in i
where (n % 2 == 0)
select
n);
On above expression it takes all the value from the array
and filters it with (%) modulus operator to get only those results which
reminder is zero by dividing the even number.
To find odd numbers from above array:
var oddNums = (from n in i
where (n % 2 != 0)
select
n);
On above expression it takes all the value from the array
and filters it with (%) modulus operator to get only those results which
reminder is not zero by dividing the even number.
I hope you enjoy the questions and answers!
Please fell free to give me your suggestion/feedback on same.
One more good news for all freshers student we are going to conduct vacation batch for free training cum live demo project session only for freshers, starting from June.
Q.18. How to delete duplicate rows from table?
A: here is explained, how can we delete the duplicate rows from the table where table has no primary key.
CREATE TABLE Employee(empid int,name varchar(20))
INSERT INTO Employee VALUES (1,'Arvind')
INSERT INTO Employee VALUES (1,'Arvind')
INSERT INTO Employee VALUES (2,'Pawan')
INSERT INTO Employee VALUES (2,'Pawan')
INSERT INTO Employee VALUES (2,'Pawan')
INSERT INTO Employee VALUES (3,'Ved')
INSERT INTO Employee VALUES (4,'RamChandra')
GO
--Check the number of records
SELECT * FROM Employee
--Delete duplicate records from the
table
;with cte
AS
(
SELECT ROW_NUMBER() OVER (Partition by empid ORDER BY name) as ID, empid, name FROM Employee
)
DELETE FROM cte WHERE ID>1
People who are interested, enroll yourself by sending your details on vedrajan@gmail.com, as :
name :
address:
contact:
email:
qualification:
location:
Cheers,
ved Pathak
Comments