C#
What is C#?
C#
is an object oriented, type safe and managed language that is compiled by .Net
framework to generate Microsoft Intermediate Language.
What are the types of
comment in C# with examples?
Single
line
Eg:
//This is a Single line comment
ii.
Multiple line (/* */)
Eg:
/*This is a multiple line comment
We
are in line 2
Last
line of comment*/
iii.
XML Comments (///).
Eg:
///
<summary>
/// Set error message for multilingual language.
///
</summary>
Can multiple catch
blocks be executed?
No,
Multiple catch blocks can’t be executed. Once the proper catch code executed,
the control is transferred to the finally block and then the code that follows
the finally block gets executed.
What is the difference
between public, static and void?
All
these are access modifiers in C#. Public declared variables or methods are
accessible anywhere in the application. Static declared variables or methods
are globally accessible without creating an instance of the class. The compiler
stores the address of the method as the entry point and uses this information
to begin execution before any objects are created. And Void is a type modifier
that states that the method or variable does not return any value.
What is an
object?
An
object is an instance of a class through which we access the methods of that
class. “New” keyword is used to create an object. A class that creates an
object in memory will contain the information about the methods, variables and
behavior of that class.
Constructors?
A
constructor is a member function in a class that has the same name as its
class. The constructor is automatically invoked whenever an object class is
created. It constructs the values of data members while initializing the class.
What is Jagged Arrays?
The
array which has elements of type array is called jagged array. The elements can
be of different dimensions and sizes. We can also call jagged array as Array of
arrays.
What is the difference
between ref & out parameters?
An
argument passed as ref must be initialized before passing to the method whereas
out parameter needs not to be initialized before passing to a method.
What is the use of
using statement in C#?
The
using block is used to obtain a resource and use it and then automatically
dispose of when the execution of block completed.
What is
serialization?
When
we want to transport an object through network then we have to convert the
object into a stream of bytes. The process of converting an object into a stream
of bytes is called Serialization. For an object to be serializable, it should
inherit ISerialize Interface.
De-serialization
is the reverse process of creating an object from a stream of bytes.
Can “this” be used
within a static method?
We
can’t use ‘This’ in a static method because we can only use static
variables/methods in a static method.
What is difference
between constants and read-only?
Constant
variables are declared and initialized at compile time. The value can’t be
changed after wards. Read-only variables will be initialized only from the
Static constructor of the class. Read only is used only when we want to assign
the value at run time.
What is an interface
class?
Interface
is an abstract class which has only public abstract methods and the methods
only have the declaration and not the definition. These abstract methods must
be implemented in the inherited classes.
What are value types
and reference types?
Value
types are stored in the Stack whereas reference types stored on heap.
Value
types:
int, enum , byte, decimal, double, float, long
Reference
Types:
string , class, interface, object.
What are Custom Control and User Control?
What are Custom Control and User Control?
Custom
Controls are controls generated as compiled code (Dlls), those are easier to
use and can be added to toolbox. Developers can drag and drop controls to their
web forms. Attributes can be set at design time. We can easily add custom
controls to Multiple Applications (If Shared Dlls), If they are private then we
can copy to dll to bin directory of web application and then add reference and
can use them.
User
Controls are very much similar to ASP include files, and are easy to create.
User controls can’t be placed in the toolbox and dragged – dropped from it.
They have their design and code behind. The file extension for user controls is
ascx.
What are sealed
classes in C#?
We
create sealed classes when we want to restrict the class to be inherited.
Sealed modifier used to prevent derivation from a class. If we forcefully
specify a sealed class as base class then a compile-time error occurs.
What is method
overloading?
Method
overloading is creating multiple methods with the same name with unique signatures
in the same class. When we compile, the compiler uses overload resolution to
determine the specific method to be invoke.
What is the
difference between Array and Arraylist?
In
an array, we can have items of the same type only. The size of the array is
fixed. An arraylist is similar to an array but it doesn’t have a fixed size.
Can a private virtual
method be overridden?
No,
because they are not accessible outside the class.
Describe the
accessibility modifier “protected internal”.
Protected
Internal variables/methods are accessible within the same assembly and also
from the classes that are derived from this parent class.
What are the
differences between System.String and
System.Text.StringBuilder classes?
System.Text.StringBuilder classes?
System.String
is immutable. When we modify the value of a string variable then a new memory
is allocated to the new value and the previous memory allocation released.
System.StringBuilder was designed to have concept of a mutable string where a
variety of operations can be performed without allocation separate memory
location for the modified string.
What’s the difference
between the System.Array.CopyTo() and System.Array.Clone() ?
Using
Clone() method, we creates a new array object containing all the elements in
the original array and using CopyTo() method, all the elements of existing
array copies into another existing array. Both the methods perform a shallow
copy.
How can we sort the
elements of the array in descending order?
Using
Sort() methods followed by Reverse() method.
24)
Write down the C# syntax to catch exception?
To
catch an exception, we use try catch blocks. Catch block can have parameter of
system.Exception type.
Eg:
try
{
GetAllData();
}
catch(Exception
ex)
{
}
In
the above example, we can omit the parameter from catch statement.
What’s the difference
between an interface and abstract class?
Interfaces
have all the methods having only declaration but no definition. In an abstract
class, we can have some concrete methods. In an interface class, all the
methods are public. An abstract class may have private methods.
What is the
difference between Finalize() and Dispose() methods?
Dispose()
is called when we want for an object to release any unmanaged resources with
them. On the other hand Finalize() is used for the same purpose but it doesn’t
assure the garbage collection of an object.
What are circular
references?
Circular
reference is situation in which two or more resources are interdependent on
each other causes the lock condition and make the resources unusable.
What are generics in
C#.NET?
Generics
are used to make reusable code classes to decrease the code redundancy,
increase type safety and performance. Using generics, we can create collection
classes. To create generic collection, System.Collections.Generic namespace
should be used instead of classes such as ArrayList in the System.Collections
namespace. Generics promotes the usage of parameterized types.
What is an object
pool in .NET?
An
object pool is a container having objects ready to be used. It tracks the
object that is currently in use, total number of objects in the pool. This
reduces the overhead of creating and re-creating objects.
List down the
commonly used types of exceptions in .Net?
ArgumentException,
ArgumentNullException , ArgumentOutOfRangeException, ArithmeticException,
DivideByZeroException ,OverflowException , IndexOutOfRangeException
,InvalidCastException ,InvalidOperationException , IOEndOfStreamException ,
NullReferenceException , OutOfMemoryException , StackOverflowException etc.
What are Custom
Exceptions?
Sometimes
there are some errors that need to be handeled as per user requirements. Custom
exceptions are used for them and are used defined exceptions.
What are
delegates?
Delegates
are same are function pointers in C++ but the only difference is that they are
type safe unlike function pointers. Delegates are required because they can be
used to write much more generic type safe functions.
How do you inherit a
class into other class in C#?
Colon
is used as inheritance operator in C#. Just place a colon and then the class
name.
public class DerivedClass : BaseClass
34)
What is the base class in .net from which all the classes are derived from?
System.Object
What is the
difference between method overriding and method overloading?
In
method overriding, we change the method definition in the derived class that
changes the method behavior. Method overloading is creating a method with the
same name within the same class having different signatures.
What are the
different ways a method can be overloaded?
Methods
can be overloaded using different data types for parameter, different order of
parameters, and different number of parameters.
Why can’t you specify
the accessibility modifier for methods inside the interface?
In
an interface, we have virtual methods that do not have method definition. All
the methods are there to be overridden in the derived class. That’s why they
all are public.
How can we set class
to be inherited, but prevent the method from being over-ridden?
Declare
the class as public and make the method sealed to prevent it from being
overridden.
What happens if the
inherited interfaces have conflicting method names?
Implement
is up to you as the method is inside your own class. There might be problem
when the methods from different interfaces expect different data, but as far as
compiler cares you’re okay.
What is the
difference between a Struct and a Class?
Structs
are value-type variables and classes are reference types. Structs stored on the
stack, causes additional overhead but faster retrieval. Structs cannot be
inherited.
How to use nullable
types in .Net?
Value
types can take either their normal values or a null value. Such types are
called nullable types.
Int?
someID = null;
If(someID.HasVAlue)
{
}
How we can create an
array with non-default values?
We
can create an array with non-default values using Enumerable.Repeat.
What is difference
between is and as operators in c#?
“is”
operator is used to check the compatibility of an object with a given type and
it returns the result as Boolean.
“as”
operator is used for casting of object to a type or a class.
What’s a multicast
delegate?
A
delegate having multiple handlers assigned to it is called multicast delegate.
Each handler is assigned to a method.
What are indexers in C# .NET?
Indexers
are known as smart arrays in C#. It allows the instances of a class to be
indexed in the same way as array.
Eg:
public
int this[int index] // Indexer
declaration
What is difference
between the “throw” and “throw ex” in .NET?
“Throw”
statement preserves original error stack whereas “throw ex” have the stack
trace from their throw point. It is always advised to use “throw” because it
provides more accurate error information.
What are C#
attributes and its significance?
C#
provides developers a way to define declarative tags on certain entities eg.
Class, method etc. are called attributes. The attribute’s information can be
retrieved at runtime using Reflection.
How to implement
singleton design pattern in C#?
In
singleton pattern, a class can only have one instance and provides access point
to it globally.
Eg:
Public
sealed class Singleton
{
Private
static readonly Singleton _instance = new Singleton();
}
What is the
difference between directcast and ctype?
DirectCast
is used to convert the type of an object that requires the run-time type to be
the same as the specified type in DirectCast.
Ctype
is used for conversion where the conversion is defined between the expression
and the type.
Is C# code is managed
or unmanaged code?
C#
is managed code because Common language runtime can compile C# code to Intermediate
language
ASP.Net
What is ASP.Net?
It
is a framework developed by Microsoft on which we can develop new generation
web sites using web forms(aspx), MVC, HTML, Javascript, CSS etc. Its successor
of Microsoft Active Server Pages(ASP). Currently there is ASP.NET 4.0, which is
used to develop web sites. There are various page extensions provided by
Microsoft that are being used for web site development. Eg: aspx, asmx, ascx,
ashx, cs, vb, html, xml etc.
What is the difference
between Server.Transfer and Response.Redirect?
In
Server.Transfer page processing transfers from one page to the other page
without making a round-trip back to the client’s browser. This provides a faster response with a little
less overhead on the server. The clients
url history list or current url Server does not update in case of
Server.Transfer.
Response.Redirect
is used to redirect the user’s browser to another page or site. It performs trip back to the client where the
client’s browser is redirected to the new page.
The user’s browser history list is updated to reflect the new address.
From which base class all
Web Forms are inherited?
Page
class.
What are the different validators in ASP.NET?
1. Required field Validator
2. Range Validator
3. Compare Validator
4. Custom Validator
5. Regular expression Validator
6. Summary Validator
Which validator control
you use if you need to make sure the values in two different controls matched?
Compare
Validator control.
What is ViewState?
ViewState
is used to retain the state of server-side objects between page post backs.
Where the viewstate is
stored after the page postback?
ViewState
is stored in a hidden field on the page at client side. ViewState is transported to the client and
back to the server, and is not stored on the server or any other external
source.
How long the items in
ViewState exists?
They
exist for the life of the current page.
What are the different
Session state management options available in ASP.NET?
1. In-Process
2. Out-of-Process.
In-Process
stores the session in memory on the web server.
Out-of-Process
Session state management stores data in an external server. The external server may be either a SQL
Server or a State Server. All objects
stored in session are required to be serializable for Out-of-Process state
management.
How you can add an event
handler?
Using the Attributes property of server side
control.
e.g.
[csharp]
btnSubmit.Attributes.Add(“onMouseOver”,”JavascriptCode();”)
[/csharp]
What is caching?
Caching
is a technique used to increase performance by keeping frequently accessed data
or files in memory. The request for a cached file/data will be accessed from
cache instead of actual location of that file.
What are the different types of caching?
ASP.NET
has 3 kinds of caching :
1. Output Caching,
2. Fragment Caching,
3. Data Caching.
15.
Which type if caching will be used if we want to cache the portion of a page
instead of whole page?
Fragment
Caching: It caches the portion of the page generated by the request. For that,
we can create user controls with the below code:
[xml]
<%@
OutputCache Duration=”120″ VaryByParam=”CategoryID;SelectedID”%>
[/xml]
List the events in page life cycle.
1) Page_PreInit
2)
Page_Init
3)
Page_InitComplete
4)
Page_PreLoad
5)
Page_Load
6)
Page_LoadComplete
7)
Page_PreRender
8)Render
Can we have a web application running without web.Config file?
Yes
Is it possible to create web application with both webforms and mvc?
Yes.
We have to include below mvc assembly references in the web forms application
to create hybrid application.
[csharp]
System.Web.Mvc
System.Web.Razor
System.ComponentModel.DataAnnotations
[/csharp]
Can we add code files of different languages in App_Code folder?
No. The code files must be in same language
to be kept in App_code folder.
What is Protected Configuration?
It
is a feature used to secure connection string information.
Write code to send e-mail from an ASP.NET application?
[csharp]
MailMessage
mailMess = new MailMessage ();
mailMess.From
= “abc@gmail.com”;
mailMess.To
= “xyz@gmail.com”;
mailMess.Subject
= “Test email”;
mailMess.Body
= “Hi This is a test mail.”;
SmtpMail.SmtpServer
= “localhost”;
SmtpMail.Send
(mailMess);
[/csharp]
MailMessage
and SmtpMail are classes defined System.Web.Mail namespace.
How can we prevent
browser from caching an ASPX page?
We can SetNoStore on HttpCachePolicy object
exposed by the Response object’s Cache property:
[csharp]
Response.Cache.SetNoStore
();
Response.Write
(DateTime.Now.ToLongTimeString ());
[/csharp]
What is the good practice
to implement validations in aspx page?
Client-side
validation is the best way to validate data of a web page. It reduces the
network traffic and saves server resources.
What are the event
handlers that we can have in Global.asax file?
Application
Events: Application_Start , Application_End, Application_AcquireRequestState,
Application_AuthenticateRequest, Application_AuthorizeRequest,
Application_BeginRequest, Application_Disposed,
Application_EndRequest, Application_Error,
Application_PostRequestHandlerExecute, Application_PreRequestHandlerExecute,
Application_PreSendRequestContent,
Application_PreSendRequestHeaders, Application_ReleaseRequestState,
Application_ResolveRequestCache, Application_UpdateRequestCache
Session
Events: Session_Start,Session_End
Which protocol is used to
call a Web service?
HTTP
Protocol
Can we have multiple web
config files for an asp.net application?
Yes.
What is the difference
between web config and machine config?
Web
config file is specific to a web application where as machine config is
specific to a machine or server. There can be multiple web config files into an
application where as we can have only one machine config file on a server.
Explain role based
security ?
Role Based Security used to implement
security based on roles assigned to user groups in the organization.
Then
we can allow or deny users based on their role in the organization. Windows
defines several built-in groups, including Administrators, Users, and Guests.
[xml]
<AUTHORIZATION><
authorization >
<
allow roles=”Domain_Name\Administrators” / > < !– Allow Administrators in domain. —
>
<
deny users=”*” / > < !– Deny anyone
else. — >
<
/authorization >
[/xml]
What is Cross Page
Posting?
When
we click submit button on a web page, the page post the data to the same page.
The technique in which we post the data to different pages is called Cross Page
posting. This can be achieved by setting POSTBACKURL property of the button that causes the postback.
Findcontrol method of PreviousPage can be used to get the posted values on the
page to which the page has been posted.
How can we apply Themes
to an asp.net application?
We
can specify the theme in web.config file. Below is the code example to apply
theme:
[xml]
<configuration>
<system.web>
<pages
theme=”Windows7″ />
</system.web>
</configuration>
[/xml]
What is RedirectPermanent
in ASP.Net?
RedirectPermanent Performs a permanent
redirection from the requested URL to the specified URL. Once the redirection
is done, it also returns 301 Moved Permanently responses.
What is MVC?
MVC
is a framework used to create web applications. The web application base builds
on Model-View-Controller pattern which
separates the application logic from UI, and the input and events from the user
will be controlled by the Controller.
Explain the working of
passport authentication.
First
of all it checks passport authentication cookie. If the cookie is not available
then the application redirects the user to Passport Sign on page. Passport
service authenticates the user details on sign on page and if valid then stores
the authenticated cookie on client machine and then redirect the user to
requested page
What are the advantages
of Passport authentication?
All
the websites can be accessed using single login credentials. So no need to
remember login credentials for each web site.
Users
can maintain his/ her information in a single location.
What are the asp.net
Security Controls?
• <asp:Login>: Provides a
standard login capability that allows the users to enter their credentials
• <asp:LoginName>: Allows you
to display the name of the logged-in user
• <asp:LoginStatus>: Displays
whether the user is authenticated or not
• <asp:LoginView>: Provides
various login views depending on the selected template
• <asp:PasswordRecovery>: email the users their lost password
How do you register
JavaScript for webcontrols ?
We
can register javascript for controls using <CONTROL -name>Attribtues.Add(scriptname,scripttext)
method.
In which event are the
controls fully loaded?
Page
load event.
what is boxing and
unboxing?
Boxing
is assigning a value type to reference type variable.
Unboxing
is reverse of boxing ie. Assigning reference type variable to value type
variable.
Differentiate strong
typing and weak typing
In
strong typing, the data types of variable are checked at compile time. On the
other hand, in case of weak typing the variable data types are checked at
runtime. In case of strong typing, there is no chance of compilation error.
Scripts use weak typing and hence issues arises at runtime.
How we can force all the
validation controls to run?
The
Page.Validate() method is used to force all the validation controls to run and
to perform validation.
List all templates of the
Repeater control.
• ItemTemplate
• AlternatingltemTemplate
• SeparatorTemplate
• HeaderTemplate
• FooterTemplate
List the major built-in
objects in ASP.NET?
• Application
• Request
• Response
• Server
• Session
• Context
• Trace
What is the appSettings
Section in the web.config file?
The
appSettings block in web config file sets the user-defined values for the whole
application.
For
example, in the following code snippet, the specified ConnectionString section
is used throughout the project for database connection:
[csharp]
<em><configuration>
<appSettings>
<add
key=”ConnectionString” value=”server=local; pwd=password; database=default”
/>
</appSettings></em>
[/csharp]
Which data type does the
RangeValidator control support?
The
data types supported by the RangeValidator control are Integer, Double, String,
Currency, and Date.
What is the difference
between an HtmlInputCheckBox control and anHtmlInputRadioButton control?
In
HtmlInputCheckBoxcontrol, multiple item selection is possible whereas in
HtmlInputRadioButton controls, we can select only single item from the group of
items.
Which namespaces are
necessary to create a localized application?
System.Globalization
System.Resources
What are the different
types of cookies in ASP.NET?
Session
Cookie – Resides on the client machine for a single session until the user does
not log out.
Persistent
Cookie – Resides on a user’s machine for a period specified for its expiry,
such as 10 days, one month, and never.
What is the file
extension of web service?
Web
services have file extension .asmx..
What are the components
of ADO.NET?
The
components of ADO.Net are Dataset, Data Reader, Data Adaptor, Command,
connection.
What is the difference
between ExecuteScalar and ExecuteNonQuery?
ExecuteScalar
returns output value where as ExecuteNonQuery does not return any value but the
number of rows affected by the query. ExecuteScalar used for fetching a single
value and ExecuteNonQuery used to execute Insert and Update statements.
What does the Orientation
property do in a Menu control?
Orientation
property of the Menu control sets the display of menu on a Web page to vertical
or horizontal.
Originally
the orientation is set to vertical.
2.
Differentiate between:
a.)Client-side and server-side validations in Web pages.
-
Client-side validations happends at the client's side with the help of
JavaScript and VBScript. This happens before the Web page is sent to the
server.
-
Server-side validations occurs place at the server side.
b.)Authentication and authorization.
-
Authentication is the process of verifyng the identity of a user using some
credentials like username and password while authorization determines the parts
of the system to which a particular identity has access.
-
Authentication is required before authorization.
For
e.g. If an employee authenticates himself with his credentials on a system,
authorization will determine if he has the control over just publishing the
content or also editing it.
What does the .WebPart
file do?
It
explains the settings of a Web Parts control that can be included to a
specified zone on a Web page.
b.)
How would you enable impersonation in the web.config file?
In
order to enable the impersonation in the web.confing file, take the following
steps:
-
Include the <identity> element in the web.config file.
-
Set the impersonate attribute to true as shown below:
<identity
impersonate = "true" />
Differentiate between a
page theme and a global theme?
-
Page theme applies to a particular web pages of the project. It is stored
inside a subfolder of the App_Themes folder.
-
Global theme applies to all the web applications on the web server. It is
stored inside the Themes folder on a Web server.
Differentiate between a
HyperLink control and a LinkButton control.
-
A HyperLink control does not have the Click and Command events while the
LinkButton control has them, which can be handled in the code-behind file of
the Web page.
How do Cookies work? Give an example of their abuse.
-
The server directs the browser to put some files in a cookie. All the cookies
are then sent for the domain in each request.
-
An example of cookie abuse could be a case where a large cookie is stored
affecting the network traffic.
What are Custom User Controls in ASP.NET?
-
These are the controls defined by developers and work similart to other web
server controls.
-
They are a mixture of custom behavior and predefined behavior.
What are the HTML server
controls in ASP.NET?
-
HTML server controls are similar to the standard HTML elements like those used
in HTML pages.
-
They expose properties and events for programatical use.
-
To make these controls programmatically accessible, we specify that the HTML
controls act as a server control by adding the runat="server"
attribute.
What are the various types of Cookies in ASP.NET?
There
exist two types of cookies in ASP.NET
-
Session Cookie - It resides on the machine of the client for a single session
and works until the user logs out of the session.
-
Persistent Cookie - It resides on the machine of a user for a specified period.
This period can be set up manually by the user.
·
Explain Culture and
UICulture values.
-
Culture value determines the functions like Date and Currency used to format
data and numbers in a Web page.
-
UICulture value determines the resources like strings or images loaded in a Web
application for a Web page.
What is Global.asax file used for?
It
executes application-level events and sets application-level variables.
Explain ASP.NET Web
Forms.
-
Web Forms are an extremely important part of ASP.NET.
-
They are the User Interface (UI) elements which provide the desired look and
feel to your web applications.
-
Web Forms provide properties, methods, and events for the controls that are
placed onto them.
·
What is event bubbling?
What is event bubbling?
-
When child control send events to parent it is termed as event bubbling.
-
Server controls like Data grid, Data List, and Repeater can have other child
controls inside them.
Differentiate between:
·
Namespace and Assembly.
-
Namespace is a naming convenience for logical design-time while an assembly
establishes the name scope for types at run time.
·
b.) Early binding and late binding.
Early
binding means calling a non-virtual method that is decided at a compile time
while Late binding refers to calling a virtual method that is decided at a
runtime.
What are the different kinds of assemblies?
There
can be two types of assemblies.
·
Static assemblies -
-
They are stored on disk in portable executable files.
-
It includes .NET Framework types like interfaces and classes, resources for the
assembly (bitmaps, JPEG files, resource files etc.).
·
ii.) Dynamic assemblies -
-
They are not saved on disk before execution rather they run directly from
memory.
-
They can be saved to disk after they have been executed.
Differentiate between Structure and Class.
-
Structures are value type while Classes are reference type.
-
Structures can not have constructor or destructors while Classes can have them.
-
Structures do not support Inheritance while Classes do support Inheritance.
Explain ViewState.
-
It is a .Net mechanism to store the posted data among post backs.
-
It allows the state of objects to be stored in a hidden field on the page,
saved on client side and transported back to server whenever required.
What are the various types of Authentication?
There
are 3 types of Authentication namely Windows, Forms and Passport
Authentication.
- Windows authentication - It
uses the security features integrated in Windows NT and Windows XP OS to
authenticate and authorize Web application users.
- Forms authentication - It
allows you to create your own list of users and validate their identity when
they visit the Web site.
- Passport authentication - It
uses the Microsoft centralized authentication provider to identify users.
Passport allows users to use a single identity across multiple Web
applications. Passport SDK needs to be installed to use Passport authentication
in your Web application.
Explain Server-side scripting and Client-side scripting.
-
Server side scripting - All the script are executed by the server and
interpreted as needed.
-
Client side scripting means that the script will be executed immediately in the
browser such as form field validation, email validation, etc. It is usaullay
carrried out in VBScript or JavaScript.
What is garbage collection?
It
is a system where a run-time component takes responsibility for managing the
lifetime of objects and the heap memory that they occupy.
Explain serialization and deserialization.
-
Serialization is the process of converting an object into a stream of bytes.
-
Deserialization is the process of creating an object from a stream of bytes.
Both
these processes are usually used to transport objects.
What are the various session state management options provided by ASP.NET?
-
ASP.NET provides two session state management options - In-Process and
Out-of-Process state management.
-
In-Process stores the session in memory on the web server.
-
Out-of-Process stores data in an external data source. This data source may be
a SQL Server or a State Server service. Out-of-Process state management needs
all objects stored in session to be serializable.
ASP.NET
interview questions - Jan 04, 2011 at 05:16 PM by Rahul
Describe
how Passport authentication works.
ASP.NET
application with Passport authentication implemented checks the user’s machine
for a current passport authentication cookie. If it is not available, ASP.NET
directs the user to a Passport sign-on page. The Passport service authenticates
the user, stores an authentication cookie on the user’s computer and direct the
user to the requested page.
Explain the steps to be followed to use Passport authentication.
1.
Install the Passport SDK.
2.
Set the application’s authentication mode to Passport in Web.config.
3.
Set authorization to deny unauthenticated users.
3.
Use the PassportAuthentication_OnAuthenticate event to access the user’s
Passport profile to identify and authorize the user.
4.
Implement a sign-out procedure to remove Passport cookies from the user’s
machine.
Explain
the advantages of Passport authentication.
User
doesn’t have to remember separate user names and passwords for various Web
sites
User
can maintain his or her profile information in a single location.
Passport
authentication also avail access to various Microsoft services, such as
Passport Express Purchase.
What
is caching?
Caching
is the technique of storing frequently used items in memory so that they can be
accessed more quickly.
By
caching the response, the request is served from the response already stored in
memory.
It’s
important to choose the items to cache wisely as Caching incurs overhead.
A
Web form that is frequently used and does not contain data that frequently
changes is good for caching.
A
cached web form freezes form’s server-side content and changes to that content
do not appear until the cache is refreshed.
Advanced
Asp.net interview questions
ASP.NET
practice test
Explain
the use of duration attribute of @OutputCache page directive.
The
@OutputCache directive’s Duration attribute determines how long the page is
cached.
If
the duration attribute is set to 60 seconds, the Web form is cached for 60
seconds; the server loads the response in memory and retains that response for
60 seconds.
Any
requests during that time receive the cached response.
Once
the cache duration has expired, the next request generates a new response and
cached for another 60 seconds.
________________________________________
ASP.NET
interview test - (20 questions) new
ASP.NET
interview test for experienced - (19 questions)
Sql
Server (25 questions)
Explain how a web application works.
Answer:
A
web application resides in the server and serves the client's requests over
internet. The client access the web page using browser from his machine. When a
client makes a request, it receives the result in the form of HTML which are
interpreted and displayed by the browser.
A
web application on the server side runs under the management of Microsoft
Internet Information Services (IIS). IIS passes the request received from
client to the application. The application returns the requested result in the
form of HTML to IIS, which in turn, sends the result to the client.
· Explain the advantages of ASP.NET.
Answer:
Following
are the advantages of ASP.NET.
Web
application exists in compiled form on the server so the execution speed is
faster as compared to the interpreted scripts.
ASP.NET
makes development simpler and easier to maintain with an event-driven,
server-side programming model.
Being
part of .Framework, it has access to all the features of .Net Framework.
Content
and program logic are separated which reduces the inconveniences of program
maintenance.
ASP.NET
makes for easy deployment. There is no need to register components because the
configuration information is built-in.
To
develop program logic, a developer can choose to write their code in more than
25 .Net languages including VB.Net, C#, JScript.Net etc.
Introduction
of view state helps in maintaining state of the controls automatically between
the postbacks events.
ASP.NET
offers built-in security features through windows authentication or other
authentication methods.
Integrated
with ADO.NET.
Built-in
caching features.
·
Explain the different parts that constitute ASP.NET application.
Answer:
Content,
program logic and configuration file constitute an ASP.NET application.
Content
files
Content
files include static text, images and can include elements from database.
Program
logic
Program
logic files exist as DLL file on the server that responds to the user actions.
Configuration
file
Configuration
file offers various settings that determine how the application runs on the
server.
Describe the sequence of action takes place on the server when ASP.NET application starts first time
Answer:
Following
are the sequences:
IIS
starts ASP.NET worker process - worker process loads assembly in the memory -
IIS sends the request to the assembly - the assembly composes a response using
program logic - IIS returns the response to the user in the form of HTML.
Explain the components of web form in ASP.NET
Answer:
Server
controls
The
server controls are Hypertext Markup Language (HTML) elements that include a
runat=server attribute. They provide automatic state management and server-side
events and respond to the user events by executing event handler on the server.
HTML
controls
These
controls also respond to the user events but the events processing happen on
the client machine.
Data
controls
Data
controls allow to connect to the database, execute command and retrieve data
from database.
System
components
System
components provide access to system-level events that occur on the server.
Describe in brief .NET Framework and its components.
Answer:
.NET
Framework provides platform for developing windows and web software. ASP.NET is
a part of .Net framework and can access all features implemented within it that
was formerly available only through windows API. .NET Framework sits in between
our application programs and operating system.
The
.Net Framework has two main components:
.Net
Framework Class Library: It provides common types such as data types and object
types that can be shared by all .Net compliant language.
The
Common language Runtime: It provides services like type safety, security, code
execution, thread management, interoperability services.
What is an Assembly? Explain its parts
Answer:
An
assembly exists as a .DLL or .EXE that contains MSIL code that is executed by
CLR. An assembly contains interface and classes, it can also contain other
resources like bitmaps, files etc. It carries version details which are used by
the CLR during execution. Two assemblies of the same name but with different
versions can run side-by-side enabling applications that depend on a specific
version to use assembly of that version. An assembly is the unit on which
permissions are granted. It can be private or global. A private assembly is
used only by the application to which it belongs, but the global assembly can
be used by any application in the system.
The
four parts of an assembly are:
Assembly
Manifest - It contains name, version, culture, and information about referenced
assemblies.
Type
metadata - It contains information about types defined in the assembly.
MSIL
- MSIL code.
Resources
- Files such as BMP or JPG file or any other files required by application.
Define Common Type System.
Answer:
.Net
allows developers to write program logic in at least 25 languages. The classes
written in one language can be used by other languages in .Net. This service of
.Net is possible through CTS which ensure the rules related to data types that
all language must follow. It provides set of types that are used by all .NET
languages and ensures .NET language type compatibility.
Define Virtual folder.
Answer:
It
is the folder that contains web applications. The folder that has been
published as virtual folder by IIS can only contain web applications.
Describe the Events in the Life Cycle of a Web Application
Answer:
A
web application starts when a browser requests a page of the application first
time. The request is received by the IIS which then starts ASP.NET worker
process (aspnet_wp.exe). The worker process then allocates a process space to
the assembly and loads it. An application_start event occurs followed by
Session_start. The request is then processed by the ASP.NET engine and sends
back response in the form of HTML. The user receives the response in the form
of page.
The
page can be submitted to the server for further processing. The page submitting
triggers postback event that causes the browser to send the page data, also
called as view state to the server. When server receives view state, it creates
new instance of the web form. The data is then restored from the view state to
the control of the web form in Page_Init event.
The
data in the control is then available in the Page_load event of the web form.
The cached event is then handled and finally the event that caused the postback
is processed. The web form is then destroyed. When the user stops using the
application, Session_end event occurs and session ends. The default session
time is 20 minutes. The application ends when no user accessing the application
and this triggers Application_End event. Finally all the resources of the
application are reclaimed by the Garbage collector.
What are the ways of preserving data on a Web Form in ASP.NET?
Answer:
ASP.NET
has introduced view state to preserve data between postback events. View state
can't avail data to other web form in an application. To provide data to other
forms, you need to save data in a state variable in the application or session
objects.
Define application state variable and session state variable.
Answer:
These
objects provide two levels of scope:
Application State
Data
stored in the application object can be shared by all the sessions of the
application. Application object stores data in the key value pair.
Session State
Session
State stores session-specific information and the information is visible within
the session only. ASP.NET creates unique sessionId for each session of the
application. SessionIDs are maintained either by an HTTP cookie or a modified
URL, as set in the application’s configuration settings. By default, SessionID
values are stored in a cookie.
Describe the application event handlers in ASP.NET
Answer:
Following
are the application event handlers:
Application_Start:
This event occurs when the first user visits a page of the application.
Application_End:
This event occurs when there are no more users of the application.
Application_BeginRequest:
This occurs at the beginning of each request to the server.
Application_EndRequest:
occurs at the end of each request to the server.
Session_Start:
This event occurs every time when any new user visits.
Session_End:
occurs when the users stop requesting pages and their session times out.
What are the Web Form Events available in ASP.NET?
Answer:
Page_Init
Page_Load
Page_PreRender
Page_Unload
Page_Disposed
Page_Error
Page_AbortTransaction
Page_CommitTransaction
Page_DataBinding
Describe the Server Control Events of ASP.NET.
Answer:
ASP.NET
offers many server controls like button, textbox, DropDownList etc. Each
control can respond to the user's actions using events and event handler
mechanism.
There
are three types of server control events:
Postback events
This
events sends the web page to the server for processing. Web page sends data
back to the same page on the server.
Cached events
These
events are processed when a postback event occurs.
Validation events
These
events occur just before a page is posted back to the server.
How do you change the session time-out value?
Answer:
The
session time-out value is specified in the web.config file within sessionstate
element. You can change the session time-out setting by changing value of
timeout attribute of sessionstate element in web.config file.
Describe how ASP.NET maintains process isolation for each Web application
Answer:
In
ASP.NET, when IIS receives a request, IIS uses aspnet_isapi.dll to call the
ASP.NET worker process (aspnet_wp.exe). The ASP.NET worker process loads the
Web application's assembly, allocating one process space, called the
application domain, for each application. This is the how ASP.NET maintains
process isolation for each Web application.
Define namespace.
Answer:
Namespaces
are the way to organize programming code. It removes the chances of name conflict.
It is quite possible to have one name for an item accidentally in large
projects those results into conflict. By organizing your code into namespaces,
you reduce the chance of these conflicts. You can create namespaces by
enclosing a class in a Namespace...End Namespace block.
You
can use namespaces outside your project by referring them using References
dialog box. You can use Imports or using statement to the code file to access
members of the namespaces in code.
What are the options in ASP.NET to maintain state?
Answer:
Client-side
state management
This
maintains information on the client’s machine using Cookies, View State, and
Query Strings.
Cookies
A
cookie is a small text file on the client machine either in the client’s file
system or memory of client browser session. Cookies are not good for sensitive
data. Moreover, Cookies can be disabled on the browser. Thus, you can’t rely on
cookies for state management.
View State
Each
page and each control on the page has View State property. This property allows
automatic retention of page and controls state between each trip to server.
This means control value is maintained between page postbacks. Viewstate is
implemented using _VIEWSTATE, a hidden form field which gets created
automatically on each page. You can’t transmit data to other page using view
state.
Querystring
Query
strings can maintain limited state information. Data can be passed from one
page to another with the URL but you can send limited size of data with the
URL. Most browsers allow a limit of 255 characters on URL length.
Server-side state management
This
kind of mechanism retains state in the server.
Application State
The
data stored in the application object can be shared by all the sessions of the
application. Application object stores data in the key value pair.
Session State
Session
State stores session-specific information and the information is visible within
the session only. ASP.NET creates unique sessionId for each session of the
application. SessionIDs are maintained either by an HTTP cookie or a modified
URL, as set in the application’s configuration settings. By default, SessionID
values are stored in a cookie.
Database
Database
can be used to store large state information. Database support is used in
combination with cookies or session state.
Explain the difference between Server control and HTML control.
Answer:
Server
events
Server
control events are handled in the server whereas HTML control events are
handled in the page.
State
management
Server
controls can maintain data across requests using view state whereas HTML
controls have no such mechanism to store data between requests.
Browser
detection
Server
controls can detect browser automatically and adapt display of control
accordingly whereas HTML controls can’t detect browser automatically.
Properties
Server
controls contain properties whereas HTML controls have attributes only.
What are the validation controls available in ASP.NET?
Answer:
ASP.NET
validation controls are:
RequiredFieldValidator:
This validates controls if controls contain data.
CompareValidator:
This allows checking if data of one control match with other control.
RangeValidator:
This verifies if entered data is between two values.
RegularExpressionValidator:
This checks if entered data matches a specific format.
CustomValidator:
Validate the data entered using a client-side script or a server-side code.
ValidationSummary:
This allows developer to display errors in one place.
Define the steps to set up validation control.
Answer:
Following
are the steps to set up validation control
Drag
a validation control on a web form.
Set
the ControlToValidate property to the control to be validated.
If
you are using CompareValidator, you have to specify the ControlToCompare
property.
Specify
the error message you want to display using ErrorMessage property.
You
can use ValidationSummary control to show errors at one place.
What are the navigation ways between pages available in ASP.NET?
Answer:
Ways
to navigate between pages are:
Hyperlink
control
Response.Redirect
method
Server.Transfer
method
Server.Execute
method
Window.Open
script method
How do you open a page in a new window?
Answer:
To
open a page in a new window, you have to use client script using onclick="window.open()"
attribute of HTML control.
Define authentication and authorization.
Answer:
Authorization:
The process of granting access privileges to resources or tasks within an
application.
Authentication:
The process of validating the identity of a user.
Define caching.
Answer:
Caching
is the technique of storing frequently used items in memory so that they can be
accessed more quickly. Caching technique allows to store/cache page output or
application data on the client on the server. The cached information is used to
serve subsequent requests that avoid the overhead of recreating the same
information. This enhances performance when same information is requested many
times by the user.
Define cookie.
Answer:
A
cookie is a small file on the client computer that a web application uses to
maintain current session information. Cookies are used to identity a user in a
future session.
What is delegate?
Answer:
A
delegate acts like a strongly type function pointer. Delegates can invoke the
methods that they reference without making explicit calls to those methods. It
is type safe since it holds reference of only those methods that match its
signature. Unlike other classes, the delegate class has a signature. Delegates
are used to implement event programming model in .NET application. Delegates
enable the methods that listen for an event, to be abstract.
Explain Exception handling in .Net.
Answer:
Exceptions
or errors are unusual occurrences that happen within the logic of an
application. The CLR has provided structured way to deal with exceptions using
Try/Catch block. ASP.NET supports some facilities to handling exceptions using
events suck as Page_Error and Application_Error.
What is impersonation?
Answer:
Impersonation
means delegating one user identity to another user. In ASP.NET, the anonymous
users impersonate the ASPNET user account by default. You can use
<identity> element of web.config file to impersonate user. E.g.
<identity impersonate="true"/>
What is managed code in .Net?
Answer:
The
code that runs under the guidance of common language runtime (CLR) is called
managed code. The versioning and registration problem which are formally
handled by the windows programming are solved in .Net with the introduction of
managed code. The managed code contains all the versioning and type information
that the CLR use to run the application.
What are Merge modules?
Answer:
Merge
modules are the deployment projects for the shared components. If the
components are already installed, the modules merge the changes rather than
unnecessarily overwrite them. When the components are no longer in use, they
are removed safely from the server using Merge modules facility.
What is Satellite assembly?
Answer:
Satellite
assembly is a kind of assembly that includes localized resources for an
application. Each satellite assembly contains the resources for one culture.
Define secured sockets layer.
Answer:
Secured
Socket Layer (SSL) ensures a secured web application by encrypting the data sent
over internet. When an application is using SSL facility, the server generates
an encryption key for the session and page is encrypted before it sent. The
client browse uses this encryption key to decrypt the requested Web page.
Define session in ASP.NET.
Answer:
A
session starts when the browser first request a resources from within the
application. The session gets terminated when either browser closed down or
session time out has been attained. The default time out for the session is 20
minutes.
Define Tracing.
Answer:
Tracing
is the way to maintain events in an application. It is useful while the
application is in debugging or in the testing phase. The trace class in the
code is used to diagnose problem. You can use trace messages to your project to
monitor events in the released version of the application. The trace class is
found in the System.Diagnostics namespace. ASP.NET introduces tracing that
enables you to write debug statements in your code, which still remain in the
code even after when it is deployed to production servers.
Define View State.
Answer:
ASP.NET
preserves data between postback events using view state. You can save a lot of
coding using view state in the web form. ViewState serialize the state of
objects and store in a hidden field on the page. It retains the state of
server-side objects between postbacks. It represents the status of the page
when submitted to the server. By default, view state is maintained for each
page. If you do not want to maintain the ViewState, include the directive
<%@ Page EnableViewState="false" %> at the top of an .aspx page
or add the attribute EnableViewState="false" to any control.
ViewState exist for the life of the current page.
What is application domain?
Answer:
It
is the process space within which ASP.NET application runs. Every application
has its own process space which isolates it from other application. If one of
the application domains throws error it does not affect the other application
domains.
List down the sequence of methods called during the page load.
Answer:
Init()
- Initializes the page.
Load()
- Loads the page in the server memory.
PreRender()
- the brief moment before the page is displayed to the user as HTML
Unload()
- runs just after page finishes loading.
What is the importance of Global.asax in ASP.NET?
Answer:
The
Global.asax is used to implement application and session level events.
Define MSIL.
Answer:
MSIL
is the Microsoft Intermediate Language. All .Net languages' executable exists
as MSIL which gets converted into machine specific language using JIT compiler
just before execution.
Response.Redirect vs Server.Transfer
Answer:
Server.Transfer
is only applicable for aspx files. It transfers page processing to another page
without making round-trip back to the client's browser. Since no round trips,
it offers faster response and doesn't update client url history list.
Response.Redirect
is used to redirect to another page or site. This performs a trip back to the
client where the client’s browser is redirected to the new page.
Explain Session state management options in ASP.NET.
Answer:
ASP.NET
provides In-Process and Out-of-Process state management. In-Process stores the
session in memory on the web server. Out-of-Process Session state management
stores data in an external data source such as SQL Server or a State Server
service. Out-of-Process state management requires that all objects stored in
session are serializable.
How to turn off cookies for a page?
Answer:
Cookie.Discard
Property when true, instructs the client application not to save the Cookie on
the user's hard disk when a session ends.
How can you ensure a permanent cookie?
Answer:
Setting
Expires property to MinValue and restrict cookie to get expired.
What is AutoPostback?
Answer:
AutoPostBack
automatically posts the page back to the server when state of the control is
changed.
Explain login control and form authentication.
Answer:
Login
controls encapsulate all the features offered by Forms authentication. Login
controls internally use FormsAuthentication class to implement security by
prompting for user credentials validating them.
What is the use of Web.config file?
Answer:
Following
are the setting you can incorporate in web.config file.
Database
connections
Error
Page setting
Session
States
Error
Handling
Security
Trace
setting
Culture
specific setting
Explain in what order a destructors is called.
Answer:
Destructors
are called in reverse order of constructors. Destructor of most derived class
is called followed by its parent's destructor and so on till the topmost class
in the hierarchy.
What is break mode? What are the options to step through code?
Answer:
Break
mode lets you to observe code line to line in order to locate error. VS.NET
provides following option to step through code.
Step
Into
Step
Over
Step
Out
Run
To Cursor
Set
Next Statement
Explain how to retrieve property settings from XML .config file.
Answer:
Create
an instance of AppSettingsReader class, use GetValue method by passing the name
of the property and the type expected. Assign the result to the appropriate
variable.
Explain Global Assembly Cache.
Answer:
Global
Assembly Cache is the place holder for shared assembly. If an assembly is
installed to the Global Assembly Cache, the assembly can be accessed by
multiple applications. In order to install an assembly to the GAC, the assembly
must have to be signed with strong name.
Explain Managed code an Un-managed code.
Answer:
Managed
code runs under the safe supervision of common language runtime. Managed code
carries metadata that is used by common language runtime to offer service like
memory management, code access security, and cross-language accessibility.
Unmanaged
code doesn't follow CLR conventions and thus, can't take the advantages of
.Framework.
What is side-by-side execution?
Answer:
This
means multiple version of same assembly to run on the same computer. This
feature enables to deploy multiple versions of the component.
Define Resource Files.
Answer:
Resource
files contains non-executable data like strings, images etc that are used by an
application and deployed along with it. You can changes these data without
recompiling the whole application.
Define Globalization and Localization.
Answer:
Globalization
is the process of creating multilingual application by defining culture
specific features like currency, date and time format, calendar and other
issues. Localization is the process of accommodating cultural differences in an
application.
What is reflection?
Answer:
Reflection
is a mechanism through which types defined in the metadata of each module can
be accessed. The System.Reflection namespaces contains classes that can be used
to define the types for an assembly.
Define Satellite Assemblies.
Answer:
Satellite
Assemblies are the special kinds of assemblies that exist as DLL and contain
culturespecific resources in a binary format. They store compiled localized application
resources. They can be created using the AL utility and can be deployed even
after deployment of the application. Satellite Assemblies encapsulate resources
into binary format and thus makes resources lighter and consume lesser space on
the disk.
What is CAS?
Answer:
CAS
is very important part of .Net security system which verifies if particular
piece of code is allowed to run. It also determines if piece of code have
access rights to run particular resource. .NET security system applies these
features using code groups and permissions. Each assembly of an application is
the part of code group with associated permissions.
Explain Automatic Memory Management in .NET.
Answer:
Automatic
memory management in .Net is through garbage collector which is incredibly
efficient in releasing resources when no longer in use.
What
is the difference between login controls and Forms authentication?
Latest
answer: Forms authentication can be easily implemented using login controls
without writing any code. Login control performs functions like prompting for
user credentials, validating them and issuing authentication just as the
FormsAuthentication class...............
Read
answer
What is Fragment Caching in ASP.NET?
Latest
answer: Fragment caching refers to the caching of individual user controls
within a Web Form. Each user control can have independent cache durations and
implementations of how the caching behavior is to be applied.............
Read
answer
What is partial classess in .net?
Latest
answer: Partial classes allow us to divide the class definition into multiple
files (physically). Logically, all the partial classes are treated as a single
file by the compiler............
Read
answer
Explain how to pass a querystring from an .asp page to aspx page.
Latest
answer: FromHTMLinasppage:<ahref="abc.aspx?qstring1=test">Test
Query String</a>
From
server side code: <%response.redirect
"webform1.aspx?id=11"%>...............
Read
answer
SQL Interview Questions
1. What is DBMS ?
Database
management system is a collection of programs that enables user to store , retrieve
, update and delete information from a database .
2. What is RDBMS ?
Relational
Database Management system (RDBMS) is a database management system (DBMS) that
is based on the relational model . Data from relational database can be
accessed or reassembled in many different ways without having to reorganize the
database tables . Data from relational database can be accessed using a API ,
Structured Query Language (SQL)
3. What is SQL ?
Structured
Query Language(SQL) is a language designed specifically for communicating with
databases. SQL is an ANSI (American National Standards Institute) standard .
4.
What are the different type of Sql's?
Frequently
asked SQL Interview Questions
1.
DDL
– Data Definition Language
DDL
is used to define the structure that holds the data. For example. table
2.
DML
– Data Manipulation Language
DML
is used for manipulation of the data itself. Typical operations are
Insert,Delete,Update and retrieving the data from the table 3. DCL– Data
Control Language DCL is used to control the visibility of data like granting
database access and set privileges to create table etc.
5. What are the Advantages of SQL
1.
SQL is not a proprietary language used by specific database vendors. Almost
every major DBMS supports SQL, so learning this one language will enable
programmer to interact with any database like ORACLE, SQL ,MYSQL etc.
2.
SQL is easy to learn. The statements are all made up of descriptive English
words, and there aren't that many of them.
3.
SQL is actually a very powerful language and by using its language elements you
can perform very complex and sophisticated database operations.
6. what is a field in a database ?
A
field is an area within a record reserved for a specific piece of data.
Examples: Employee Name , Employee ID etc
7. What is a Record in a database ?
A
record is the collection of values / fields of a specific entity: i.e. a
Employee , Salary etc
8. What is a Table in a database ?
A
table is a collection of records of a specific type. For example, employee
table , salary table etc
1.
Atomicity
In
this , a transaction consists of many steps. When all the steps in the
transaction go completed it get reflected in DB or if any step fails, all the
transactions are rolled back.
2.
Consistency
The
database will move from one consistent state to another if the transaction
succeeds and remain in the original state if the transaction fails.
3.
Isolation
Every
transaction should operate as if it is the only transaction in the system
4.
Durability
Once
a transaction has completed successfully, the updated rows/records must be
available for all other transactions on a permanent basis
11. What is a Database Lock?
Database
lock tell a transaction if the data item in questions is currently being used
by other transactions.
12. What are the type of locks?
1.
Shared Lock
When
a shared lock is applied on data item, other transactions can only read the
item, but cant write into it.
2.
Exclusive Lock
When
a exclusive lock is applied on data item, other transactions cant read or write
into the data item.
13. What are the different type of normalization?
Frequently
asked SQL Interview Questions
In
database design , we start with one single table, with all possible columns.
Lot of redundant data would be present since it’s a single table. The process
of removing the redundant data, by splitting up the table in a well defined
fashion is called normalization.
1.
First Normal Form (1NF)
A
relation is said to be in first normal form if and only if all underlying
domains contain atomic values only. After 1NF , we can still have redundant
data
2.
Second Normal Form (2NF)
A
relation is said to be in 2NF if and only if it is in 1NF and every non key
attribute is fully dependent on the primary key. After 2NF , we can still have
redundant data
3.
Third Normal Form (3NF)
A
relation is said to be in 3NF if and only if it is in 2NF and every non key
attribute is non-transitively dependent on the primary key
14. What is a primary key?
Frequently
asked SQL Interview Questions
A
primary key is a column whose values uniquely identify every row in a table.
Primary key values can never be reused. If a row is deleted from the table, its
primary key may not be assigned to any new rows in the future. In the examples
given below “Employee_ID” field is the primary key .
1.
To define a field as primary key, following conditions had to be met :
2.
No two rows can have the same primary key value.
3.
Every row must have a primary key value
4.
Primary key field cannot be null
5.
Values in primary key columns can never be modified or updated
16. What is a Composite Primary Key ?
A
Composite primary key is a set of columns whose values uniquely identify every
row in a table. For example , in the table given above , if
"Employee_ID" and "Employee Name" together uniquely
identifies a row its called a Composite Primary Key . In this case , both the
columns will be represented as primary key .
17. What is a Foreign Key ?
Frequently
asked SQL Interview Questions
When
a "one" table's primary key field is added to a related
"many" table in order to create the common field which relates the
two tables, it is called a foreign key in the "many" table. In the
example given below , salary of an employee is stored in salary table . Relation
is established via foreign key column “Employee_ID_Ref” which refers
“Employee_ID” field in Employee table .
18. What is a Unique Key ?
Unique
key is same as primary with difference being existence of null . Unique key
field allows one value as NULL value
19. Define SQL Insert Statement?
Frequently
asked SQL Interview Questions
SQL
INSERT statement is used to add rows to a table. For a full row insert , SQL
Query should start with “insert into “ statement followed by table name and
values command followed by the values that need to be inserted into the table
.Insert can be used in several ways:
1.
To insert a single complete row
2.
To insert a single partial row
20. Define SQL Update Statement?
Frequently
asked SQL Interview Questions
SQL
Update is used to update data in a row or set of rows specified in the filter
condition .
The
basic format of an SQL UPDATE statement is ,Update command followed by table to
be updated and SET command followed by column names and their new values
followed by filter condition that determines which rows should be updated
21. Define SQL Delete Statement?
SQL
Delete is used to delete a row or set of rows specified in the filter condition
.The basic format of an SQL DELETE statement is ,DELETE FROM command followed
by table name followed by filter condition that determines which rows should be
updated
16. What is a Composite Primary Key ?
A
Composite primary key is a set of columns whose values uniquely identify every
row in a table. For example , in the table given above , if
"Employee_ID" and "Employee Name" together uniquely
identifies a row its called a Composite Primary Key . In this case , both the
columns will be represented as primary key .
17. What is a Foreign Key ?
Frequently
asked SQL Interview Questions
When
a "one" table's primary key field is added to a related
"many" table in order to create the common field which relates the
two tables, it is called a foreign key in the "many" table. In the
example given below , salary of an employee is stored in salary table .
Relation is established via foreign key column “Employee_ID_Ref” which refers
“Employee_ID” field in Employee table .
18. What is a Unique Key ?
Unique
key is same as primary with difference being existence of null . Unique key
field allows one value as NULL value
19. Define SQL Insert Statement?
Frequently
asked SQL Interview Questions
SQL
INSERT statement is used to add rows to a table. For a full row insert , SQL
Query should start with “insert into “ statement followed by table name and
values command followed by the values that need to be inserted into the table
.Insert can be used in several ways:
1.
To insert a single complete row
2.
To insert a single partial row
20. Define SQL Update Statement?
Frequently
asked SQL Interview Questions
SQL
Update is used to update data in a row or set of rows specified in the filter
condition .
The
basic format of an SQL UPDATE statement is ,Update command followed by table to
be updated and SET command followed by column names and their new values
followed by filter condition that determines which rows should be updated
21. Define SQL Delete Statement?
SQL
Delete is used to delete a row or set of rows specified in the filter condition
.The basic format of an SQL DELETE statement is ,DELETE FROM command followed
by table name followed by filter condition that determines which rows should be
updated
23. Define Join and explain different type of joins?
Frequently
asked SQL Interview Questions
In
order to avoid data duplication , data is stored in related tables . Join
keyword is used to fetch data from related table. Join return rows when there
is at least one match in both tables . Type of joins are
Right
Join
Return
all rows from the right table, even if there are no matches in the left table .
Outer
Join
Left
Join
Return
all rows from the left table, even if there are no matches in the right table .
Full
Join
Return
rows when there is a match in one of the tables .
24. What is Self-Join?
Self-join
is query used to join a table to itself. Aliases should be used for the same
table comparison.
25. What is Cross Join?
Cross
Join will return all records where each row from the first table is combined with
each row from the second table.
26. What is a view?
Frequently
asked SQL Interview Questions
Views
are virtual tables. Unlike tables that contain data, views simply contain
queries that dynamically retrieve data when used.
27. What is a materialized view?
Materialized
views is also a view but are disk based . Materialized views get updated on
specific duration, base upon the interval specified in the query definition. We
can index materialized view.
28. What are the advantages and disadvantages of views in a
database?
Advantages:
1.
Views doesn't store data in a physical location.
2.
View can be use to hide some of the columns from the table
3.
Views can provide Access Restriction, since data insertion , update and
deletion is not possible on the view.
Disadvantages:
1.
When a table is dropped , associated view become irrelevant.
2.
Since view are created when a query requesting data from view is triggered, its
bit slow
3.
When views are created for large tables, it occupy more memory .
30. What are the advantages a stored procedure?
Stored
Procedures are precomplied and stored in database. This enable the database to
execute the queries much faster. Since many queries can be included in a stored
procedure, round trip time t o execute multiple queries from source code to
database and back is avoided.
31. What is a trigger?
Database
are set of commands that get executed when an event(Before Insert,After
Insert,On Update,On delete of a row) occurs on a table,views.
32. Explain the difference between DELETE , TRUNCATE and DROP
commands?
Once
delete operation is performed Commit and Rollback can be performed to retrieve
data. But after truncate statement, Commit and Rollback rollback statement cant
be performed. Where condition can be used along with delete statement but it
cant be used with truncate statement. Drop command is used to drop the table or
keys like primary,foreign from a table.
33. What is the difference between Cluster and Non cluster Index?
A
clustered index reorders the way records in the table are physically stored.
There can be only one clustered index per table. It make data retrieval faster.
A non clustered index does not alter the way it was stored but creates a
complete separate object within the table. As a result insert and update
command will be faster.
34. What is Union, minus and Interact commands?
MINUS
operator is used to return rows from the first query but not from the second
query. INTERSECT operator is used to return rows returned by both the queries.
2. What is RDBMS ?
3. What is SQL ?
5. What are the Advantages of SQL
No comments:
Post a Comment