Microsoft Dot Net Master

Microsoft Dot Net Master
Microsoft Dot Net Master

Sunday, December 16, 2012

What is Index?


An  index  is a physical  structure  containing pointers  to  the data.  Indices are  created  in an
existing table to locate rows more quickly and efficiently. It is possible to create an index on
one or more columns of a table, and each  index  is given a name. The users cannot see the
indexes; they are just used to speed up queries. Effective indexes are one of the best ways
to  improve performance  in a database application. A table scan happens when there  is no
index available to help a query. In a table scan SQL Server examines every row in the table
to  satisfy  the  query  results.  Table  scans  are  sometimes  unavoidable,  but  on  large  tables,
scans have a terrific impact on performance.

What is View?


A simple view can be thought of as a subset of a table. It can be used for retrieving data, as
well  as  updating  or  deleting  rows.  Rows  updated  or  deleted  in  the  view  are  updated  or
deleted  in the table the view was created with.  It should also be noted that as data  in the
original table changes, so does data in the view, as views are the way to look at part of the
original table. The results of using a view are not permanently stored  in the database. The
data accessed through a view is actually constructed using standard T‐SQL select command
and can come from one to many different base tables or even other views.

What is Trigger?


A  trigger  is  a  SQL  procedure  that  initiates  an  action when  an  event  (INSERT,  DELETE  or
UPDATE)  occurs.  Triggers  are  stored  in  and managed  by  the  DBMS.  Triggers  are  used  to
maintain  the  referential  integrity of data by  changing  the data  in  a  systematic  fashion. A
trigger cannot be called or executed; DBMS automatically  fires  the  trigger as a  result of a
data  modification  to  the  associated  table.  Triggers  can  be  viewed  as  similar  to  stored
procedures  in  that  both  consist  of  procedural  logic  that  is  stored  at  the  database  level.
Stored procedures, however, are not event‐drive and are not attached to a specific table as
triggers are. Stored procedures are explicitly executed by invoking a CALL to the procedure
while  triggers  are  implicitly  executed.  In  addition,  triggers  can  also  execute  stored
procedures.

 Nested Trigger: A trigger can also contain INSERT, UPDATE and DELETE logic within itself, so
when  the  trigger  is  fired  because  of  data  modification  it  can  also  cause  another  data
modification,  thereby  firing another  trigger. A trigger  that contains data modification  logic
within itself is called a nested trigger.

What is Stored Procedure?


A stored procedure is a named group of SQL statements that have been previously created
and  stored  in  the  server  database.  Stored  procedures  accept  input  parameters  so  that  a
single procedure can be used over the network by several clients using different input data.
And when  the procedure  is modified, all clients automatically get  the new version. Stored
procedures  reduce  network  traffic  and  improve  performance.  Stored  procedures  can  be
used to help ensure the integrity of the database.
e.g.  sp_helpdb, sp_renamedb, sp_depends etc.

What are different normalization forms?


1NF: Eliminate Repeating Groups 
Make a separate table for each set of related attributes, and give each table a primary key.
Each field contains at most one value from its attribute domain.

2NF: Eliminate Redundant Data 
If an attribute depends on only part of a multi‐valued key, remove it to a separate table.

3NF: Eliminate Columns Not Dependent On Key 
If attributes do not contribute to a description of the key, remove them to a separate table.
All attributes must be directly dependent on the primary key.

BCNF: Boyce‐Codd Normal Form 
If there are non‐trivial dependencies between candidate key attributes, separate them out
into distinct tables.


4NF: Isolate Independent Multiple Relationships 
No table may contain two or more 1:n or n:m relationships that are not directly related.

5NF: Isolate Semantically Related Multiple Relationships
There may be practical constrains on information that justify separating logically related
many‐to‐many relationships.

ONF: Optimal Normal Form 
A model limited to only simple (elemental) facts, as expressed in Object Role Model
notation.

DKNF: Domain‐Key Normal Form
A model free from all modification anomalies is said to be in DKNF.

Remember, these normalization guidelines are cumulative. For a database to be in 3NF, it
must first fulfill all the criteria of a 2NF and 1NF database.

What is De‐normalization? 


De‐normalization is the process of attempting to optimize the performance of a database by
adding  redundant data.  It  is  sometimes necessary because  current DBMSs  implement  the
relational model poorly. A true relational DBMS would allow for a fully normalized database
at  the  logical  level,  while  providing  physical  storage  of  data  that  is  tuned  for  high
performance. De‐normalization  is a technique to move from higher to  lower normal forms
of database modeling in order to speed up database access.

What is Normalization?


Database normalization is a data design and organization process applied to data structures
based  on  rules  that  help  building  relational  databases.  In  relational  database  design,  the
process of organizing data  to minimize  redundancy  is  called normalization. Normalization
usually  involves  dividing  a  database  into  two  or  more  tables  and  defining  relationships
between  the  tables.  The  objective  is  to  isolate  data  so  that  additions,  deletions,  and
modifications of a field can be made in just one table and then propagated through the rest
of the database via the defined relationships.

What are the properties of the Relational tables?


Relational tables have six properties:
•  Values are atomic.
•  Column values are of the same kind.
•  Each row is unique.
•  The sequence of columns is insignificant.
•  The sequence of rows is insignificant.
•  Each column must have a unique name.

What is RDBMS?


Relational  Data  Base Management  Systems  (RDBMS)  are  database management  systems
that  maintain  data  records  and  indices  in  tables.  Relationships  may  be  created  and
maintained  across  and  among  the data  and  tables.  In  a  relational database,  relationships
between  data  items  are  expressed  by means  of  tables.  Interdependencies  among  these
tables are expressed by data  values  rather  than by pointers. This allows a high degree of
data  independence.  An  RDBMS  has  the  capability  to  recombine  the  data  items  from
different files, providing powerful tools for data usage.

Wednesday, December 12, 2012

What is the difference between Unit testing,Assembly testing,Integration Testing and Regression testing


Unit testing is also called as Component testing. Unit testing ensures that reliable program unit meets their requirements. Unit testing is normally conducted by programmer under the supervision of the project lead or the team Lead. Main objective of this testing is to test each unit in isolation and individually. This is done by knowing what the inputs to the unit are and what the expected outputs for the same. Unit testing is a white box activity. Unit test normally comes in the implementation phase of the project. 

For instance in the below figure we are trying to do unit testing on the customer class. So we create the object of Customer class assign “CustomerCode” and “Age” property and check for the response. For instance in this condition we tried to pass a non-numeric value to the “Age” property and the class threw an error saying “Age should be numeric”. So here the basic unit testing entity is your class.
Fig: Unit testing for sample Customer class

But unit testing is not limited to a component, object or function. So definition of a unit testing 
will depend on the approach. Below are some examples of unit testing:-

1)      1) Check points in UI like tab orders, error messages, look and feel etc.
2)      2) Class, object, component level testing has said previously.
3)      3) In case of functional programming can be a simple method or function.
4)      4) Logic testing for algorithms. Some projects can have some critical algorithm for instance some kind of custom sorting, security implementation etc. So that logic can be tested independently.

 But the general thumb rule of what is Unit in Unit testing is that the module self contained and by itself. 

Assembly testing goes one step ahead than unit testing. It demonstrates that can the modules interact in a correct, stable and proper manner as defined by the functional specifications provided by the client. Assembly testing is Black box testing style and also called as Integration testing. For instance in the above unit test of the “Customer” class, testing was done in isolation. But in actually the “Customer” class is not going to be stand alone rather it will be used more in conjunction with the “Product” class and also will have UI to do the same. So in short the “Customer” class will work with two more entity one is the “UI” and the other is the “Product” class. So normally assembly testing is done through UI but not necessarily.

Fig: Integration Testing

The above figure defines a simple scenario for integration testing. The same “Customer” class is now tested with the “UI” and “Product” to see if the interaction between them matches according to functional specifications. 

Regression testing ensures that application function properly even if there are changes or enhancements to system. For instance you change the “Product” class still you will run all the test cases for “Product” , “Customer” and “UI” just to make sure that any changes in “Product” class does not affect interaction with other entities. So you will see when testers do a regression testing they run all the scripts to ensure that nothing has been affected.

Ajax updatepanel example with triggers in asp.net


During work with our applications if we entered any values in textbox controls and click on a button in form we will see full postback of our page and we will lost all the controls values whatever we entered previously this happend because of postback. If we want to avoid this full postback of page and round trip to server we need to write much code instead of writing much code we can use ajax updatepanel control.
Ajax updatepanel will help us to avoid full postback of the page i.e., avoid refresh of the whole page content with postback and stop flickering of the page which is associated with a postback and allows only partial postbacks. By using Ajax updatepanel we can refresh only required part of page instead of refreshing whole page.

Ajax updatepanel contains property called UpdateMode this property is used to specify whether UpdatePanel is always refreshed during a partial render or if it refresh only when a particular trigger hit. By default updatepanel contains UpdateMode="Always" if we want to set it conditionally we need to change this property UpdateMode="Conditional"

Ajax updatepanel control contains two child tags those are ContentTemplate and Triggers.

ContentTemplate is used to hold the content of the page means suppose we designed page with some controls we will place controls inside of the ContentTemplate

Triggers we used in a situation like need to refresh updatepanel only whenever I click some button control in that situation I will define those controls with this Triggers child tag.

Our Sample update panel control will be like this

<asp:UpdatePanel ID="UpdatePanel2" runat="server"
 UpdateMode="Conditional">
 <ContentTemplate>
 <asp:Label ID="Label2" runat="server"
 ForeColor="red" />
……………………………………………………..
………………………………………………………
……………………………………………………….
 </ContentTemplate>
 <Triggers>
 <asp:AsyncPostBackTrigger ControlID="Button1"
 EventName="Click" />
</Triggers>
 </asp:UpdatePanel>
Now we will create one sample application with updatepanels for that first create application and design your aspx page will be likes this

<html xmlns="http://www.w3.org/1999/xhtml" >
 <head id="Head1" runat="server">
 <title>UpdatePanel Example in asp.net</title>
 </head>
 <body>
 <form id="form1" runat="server">
 <asp:ScriptManager ID="ScriptManager1" runat="server"/>
 <div>
 <asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional">
 <ContentTemplate>
 <fieldset style="width:30%">
 <legend>Update Panel-1</legend>
 <asp:Label ID="lbl1" runat="server" ForeColor="green"/><br />
 <asp:Button ID="btnUpdate1" runat="server" Text="Update Both Panels" OnClick="btnUpdate1_Click" />
 <asp:Button ID="btnUpdate2" runat="server" Text="Update This Panel" OnClick="btnUpdate2_Click" />
 </fieldset>
 </ContentTemplate>
 </asp:UpdatePanel>
 <asp:UpdatePanel ID="UpdatePanel2" runat="server" UpdateMode="Conditional">
 <ContentTemplate>
 <fieldset style="width:30%">
 <legend>Update Panel-2</legend>
  <asp:Label ID="lbl2" runat="server" ForeColor="red" />
  </fieldset>
 </ContentTemplate>
 <Triggers>
 <asp:AsyncPostBackTrigger ControlID="btnUpdate1" EventName="Click" />
 </Triggers>
 </asp:UpdatePanel>
 </div>
 </form>
 </body>
</html>
If you observe above code in UpdatePanel2 I defined Triggers property with btnUpdate1. HereUpdatePanel2 content will update only whenever we click on btnUpdate1 because we definedUpdatePanel2 property UpdateMode="Conditional" and we set AsyncPostBackTrigger property withbtnUpdate1

Write following code in code behind

C#.NET

protected void btnUpdate1_Click(object sender, EventArgs e)
{
lbl1.Text = DateTime.Now.ToLongTimeString();
lbl2.Text = DateTime.Now.ToLongTimeString();
}
protected void btnUpdate2_Click(object sender, EventArgs e)
{
lbl1.Text = DateTime.Now.ToLongTimeString();
lbl2.Text = DateTime.Now.ToLongTimeString();
}
VB Code


Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As ObjectByVal e As EventArgs)
End Sub
Protected Sub btnUpdate1_Click(ByVal sender As ObjectByVal e As EventArgs)
lbl1.Text = DateTime.Now.ToLongTimeString()
lbl2.Text = DateTime.Now.ToLongTimeString()
End Sub
Protected Sub btnUpdate2_Click(ByVal sender As ObjectByVal e As EventArgs)
lbl1.Text = DateTime.Now.ToLongTimeString()
lbl2.Text = DateTime.Now.ToLongTimeString()
End Sub
Demo
If you observe above sample whenever I click on button “Update Both Panels” it’s updating data in both updatepanels but if click on button “Update This Panel” it’s updating data in first updatepanel because in both updatepanels we defined condition UpdateMode= "Conditional" and set Triggers conditions because of that here updatepanels will update conditionally and in UpdatePanel2 we written AsyncPostBackTriggerproperty to update panel only whenver we click on btnUpdate1.