-->

Saturday, September 20, 2014

Implementing Batches in SQL Server and Guidelines

As a database developer, you might need to execute more than one SQL statement to perform a task. For example, when a new employee joins AdventureWorks, Inc., you need to insert the employee details in the database. The details of the employees are stored in more than one table. Therefore, you need to execute an insert statement into store the details in each table. In such a case, you can send all the SQL statements together to the SQL Server to be executed as a unit. This helps in reducing the network traffic.

Creating Batches

A batch is a group of SQL statements submitted together to the SQL Server for execution. While executing batches, the SQL Server compiles the statements of a batch into a single executable unit called an execution plan. This helps in saving execution time.

Consider an example. You have to execute 10 statements and you are executing them one by one by sending 10 requests. This process takes time if your queries are in queue. All statements together in a batch, then the execution process becomes faster as all the statements are sent to the server together.

To create a batch, you can write multiple SQL statements followed by the keyword GO at the end, as shown in the following listing:
<T-SQL Statement1>
<T-SQL Statement2>
<T-SQL Statement3>
…. . .
GO

GO is a command that specifies the end of the batch and sends the SQL statements to an instance of the SQL Server.

Consider an example. If you want to store the details of new employees in the Adventure Works database, you can create the following batch:

INSERT INTO [AdventureWorks]. [Person]. [Contact]
VALUES (0, null, ‘Robert’, ‘J’ ‘Langdon’, NULL
,’rbl@adventure-works.com’, 0, ‘1 (11) 500 555-0172’
,’9E685955-ACD0-4218-AD7F-60DDF224C452’, ‘2a31OEw=’ , NULL
, newid( ), GETDATE ( ) )
INSERT INTO [AdventureWorks]. [HumanResources] . [Employee]
VALUES (‘AS01AS25R2E365W’, 19978, ‘robert1’, 16, ‘Tool Designer’,
‘1972-05-15’, ‘S’, ‘M’, ‘1996-07-31’, 0, 16, 20, 1, newid ( ) ,

When a batch is submitted to the SQL Server, it is compiled to create an execution plan. If any compilation error occurs, such as a syntax error, the execution plan is not created. Therefore, none of the statements in the batch is executed. However, after the execution plan is created, if a run-time error occurs, the execution of the batch stops. In such a case, the statements executed before the statement that encountered the run-time error are not affected.

Using Variables

While creating batches, you might need to save some values temporarily during the execution time. For example, you might need to store some intermediate values of calculations. To store the intermediate values, you can declare variables and assign values to them. You can declare a variable by using the DECLARE statement. The syntax of the DECLARE statement is:

DECLARE @variable_name data_type

Variables that are declare in a batch and can be used in any statement inside the batch are called local variables.
The following code declares a variable, @Rate, and assigns the maximum value of the Rate column from the EmployeePayHistory table to the variable:

DECLARE @Rate int
SELECT @Rate = max (Rate)
FROM HumanResources.EmployeePayHistory
GO
In the preceding example, the @Rate variable is declardd and used to store the maximum value of the Rate column. The max aggregate function is used to retrieve the maximum pay rate from the EmployeePayHistory table. The GO keyword is used to send all the statements together to the SQL Server.

Displaying User-Defined Messages

At times, you need to display user-defined messages or values of variables when the batch is executed. For this, you can use the PRINT statement, as shown in the following batch.
The following code displays the value of the rate variable by using the PRINT statement.

DECLARE @Rate int
SELECT @Rate = max (Rate)
FROM HumanResources.EmployeePayHistory
PRINT @Rate
GO
You can also use comment entries in batches to write a description of the code. This will help understand the purpose of the code. A comment entry can be written in two ways:

  • Multiple line comment entries enclosed within /* and */
  • Single line comment entry starting with – (double hyphens).

Guidelines to Create Batches

While crating batches, you need to consider the following guidelines:

  • You cannot combine statements, such as CREATE DEFAULT, CRATE FUNCTION, CREATE PROCEDURE, CREATE RULE, CREATE TRIGGER, and CREATE VIEW with other statements while creating a batch. Any statement that follows the create statement is interpreted as part of the definition.
  • You can use the EXECUTE statement in a batch when it is not the first statement of the batch, otherwise the EXECUTE statement works implicitly.
In addition, you need to consider the following restrictions:
  • You cannot bind rules and defaults to columns and use them in the same batch.
  • You cannot define and use the CHECK constraint in the same batch.
  • You cannot drop objects and recreate them in the same batch.
  • You cannot alter a table by adding a column and then refer to the new columns in the batch created earlier.


How to add jQuery to Web Pages: MVC

Programmer must include jQuery library on the web pages (views in case of MVC) to be execute all the functions/event/triggers written for that page in jQuery.  This article will lists all the options may be used to use jQuery on the pages.

To include jQuery there are two options which are basically used:
  • Include jQuery from google
  • Download and then add a reference on your page. (www.jQuery.com)

All the js files have two versions and can be downloaded through the website given above:
  • Development version:  uncompressed and readable, used for testing purpose
  • Production version: compressed and not readable, used on live sites.

@Scripts.Render(“http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js”)

In earlier article, we have studied about layout files and a simple view file that is used to render styles/scripts on the pages in MVC. So to include jQuery or any other file on the page we have two ways i.e.
  • Add reference on view: adding a reference on the view individually will only enable jQuery for that page. If you want to use it on another page then you have to add it on that page also.
  • Add reference on layout: as we all know, layout file is the basic structure for all the pages including that layout. So adding a reference on layout can be used for all the pages following that layout.

Earlier article was about to use selectors on the page but without adding this reference, you can’t use those. In next article we will discuss about jQuery syntaxes.

Graph Introduction

Graph is a non-linear data structure which is a collection of nodes also called as vertices and edges also called as arcs. So, if 'G' is a Graph mathematically it is represented as, G=(V,E) where 'V' is the non empty set of vertices 'E' is the set of edges. The edge if it exists in the graph connects any two nodes only. There may be more than one edge connecting the same nodes. If the edges in a graph show direction then such edges are called as directed edges and the graphs containing such directed edges are called as directed graphs or simply digraphs. If the graph contains undirected edges (represented by straight lines) then it is called as undirected graph or simply graph.

 undirected graph

Set of vertices, V={A,B,C,D,E,F,G}
Set of edges, E={AB,AD,AF,BC, CE, DE, EG, FG}

In undirected graph the edge AB is similar to BA. Only one representation is considered. But in a directed graph the edge AB means, the edge starts from A and ends in B.
Directed Graph or digraph:
Directed Graph or digraph

Set of vertices, V={A,B,C,D,E,F,G}
Set of edges, E={AB,AD,CB,DE,EC,EG,FG,FA}
Scenario: A person moves from pilani to Jaipur by road. From Jaipur he reaches Delhi via Bharatpur. The person comes back to pilani via chandigrah.
How many places the person has visited? How much distance he has covered? How much time he takes to make a tip?
To answer all these questions it is necessary to go through the scenario many a times. If the same scenario is represented pictorially then answering the questions will be very easy. That is what the major benefit of graph is. See the following representation.

The above representation is a graph from which we can instantly say the person visited 4 places from pilani. If we mark the edges by means of either distance or time required to reach then the graph becomes weighted graph. See the following graph where the edges are marked with distances in kilometers.
weighted digraph

 From the above weighted graph we can easily say that the person has traveled 710 kilometers. If the edges are labeled with time as weight we can easily calculate the time required to cover the places. In the above graph there exists route from Pilani to Jaipur then vice-versa is also true. So, in undirected graph an edge is a two-way edge. But in case of digraph the edge if exists represents one-way.
Consider the following undirected graph:

Set of vertices, V={1,2,3,4,5,6}
Set of edges, E={12,14,16,23,35,45,56}, Number of edges=7
Degree of any vertex is total number of incident edges. So, in the graph degree of vertex 1 is 3, 2 is 2, 3 is 2, 4 is 2, 5 is 3 and vertex 6 is 2. Sum of degree of all vertices of graph is 14. The sum is always even. Number of edges in the graph is equal to 7. Therefore we can derive a relation between number of edges in a graph and sum of degree of vertices of graph. The relation is:
Number of edges in graph = 1/2 (Sum of degree of vertices)

      
Number of edges in graph


where m is number of edges of a graph, d(V)The same relation holds true for digraph also. In a digraph degree of a vertex is equal to sum of in degree and out degree.
In degree of a vertex is equal total number of edges entering into the vertex and out degree is equal to total number of edges going out of the vertex.
In the above graph there exists an edge from vertex 1 to 2. There is no direct edge existing from 1 to 3. But it is possible to move to 3 from 1 via 2. It is called as path. In a directed graph if the path terminates in a start node then it is cycle. There are 3 paths from node 1 to node 5. They are 1-2-3-5, 1-4-5 and 1-6-5. The path 1-2-3-5 is a collection of paths 1-2, 2-3 and 3-5. In a graph if two nodes are directly connected then there exists a direct path. If there exists an edge from one vertex 'i' to other vertex 'j' then node 'i' and 'j' are called as adjacent nodes. From the above graph we can list the adjacent nodes of each vertex as:
Graph Introduction

Wednesday, September 17, 2014

Types of Java Programs

Java is a programming language, by which we can design a new program or a software. It have many features, such as

  • Object Oriented Language
  • Support Cross Platform
  • Platform independent
  • Strongly typed language
  • Machine Dependent(JVM- Java Virtual Machine)
  • Use Reference in place of pointer
So you can make a new application in it. Java Support four types of application such as
  1. Console Based Application(Core Java)
  2. Client Based Application (Applet, Swings)
  3. Web Based Application (Applet, Servlet, JSP)
  4. Mobile Based Application (Android)
1. Console Application- It also known as command based application. In which we can work only with non-GUI application. Suppose we want to create a new folder in system then what to do in DOS(console based). First of all we write a command for this, like mkdir. If you solve same problem in window(GUI) then do not need to write command for this, simply use mouse pointer and make a new folder.

Diagrammatic view of console window

Diagrammatic view of console window


2. Client based application : That application, which is install on client machine. That application create for single person or a organization. Also known as off line application. Client application design in java is very easy through applet and swings. Through the client application user use pointing device rather then command. In the client application user can put any input by the user interface. 

Diagrammatic view of client based application(GUI)

Diagrammatic view of client based application(GUI)

3. Web Based Application:  These application run on web browser. For this types of application we create a web pages, you can select any language for making web pages like jsp, html, asp, php etc. Here we select servlet and JSP for designing the web pages. Servlet is a class file which is compiled by the servlet engine and JSP is a extension of servlet. For making easier we use JSP for dynamic web pages.

Diagrammatic view of web based application(GUI)

Diagrammatic view of web based application(GUI)
4. Mobile Based Application : These application run on mobile platform, in current market java has already launched android platform for mobile application. In the later article i will discussed more about java-mobile(android ).

Diagrammatic view of Mobile based application(GUI)

Diagrammatic view of Mobile based application(GUI)




Wednesday, September 10, 2014

How to Bind DropDownList with Enum MVC

Earlier article was about to bind DropDownList with simple select list of type selectlistitems. These select list may by any type of list either from database or temporary for that view only. In this article we will create an enum, then create a select list through that enum and finally will bind that to drop-down list.

Create an Enum like I have, named OptionType

enum OptionTypes
{
value1,
value2,
value3,
value4
}

After creating enum, write a class that will work like a helper to create select list for that enum:

public static class EnumHelper
{
// Get the value of the description attribute if the   
// enum has one, otherwise use the value.  
public static string GetDescription<TEnum>(this TEnum value)
{
var fleid = value.GetType().GetField(value.ToString());

if (fleid != null)
{
var attributes = (DescriptionAttribute[])fleid.GetCustomAttributes(typeof(DescriptionAttribute), false);

if (attributes.Length > 0)
{
return attributes[0].Description;
}
}

return value.ToString();
}

/// <summary>
/// Build a select list for an enum
/// </summary>
public static SelectList SelectListFor<T>() where T : struct
{
Type t = typeof(T);
return !t.IsEnum ? null
: new SelectList(CreateSelectList(t), "Value", "Text");
}

/// <summary>
/// Build a select list for an enum with a particular value selected 
/// </summary>
public static SelectList SelectListFor<T>(T selected) where T : struct
{
Type t = typeof(T);
return !t.IsEnum ? null
: new SelectList(CreateSelectList(t), "Text", "Value", selected.ToString());
}

private static IEnumerable<SelectListItem> CreateSelectList(Type t)
{
return Enum.GetValues(t)
  .Cast<Enum>()
  .Select(e => new SelectListItem { Value = e.ToString(), Text = e.GetDescription()                            });
}
}

Go to your controller and write the line as I have:

ViewBag.values = EnumHelper.SelectListFor<OptionTypes>();

Open your view page and write

@Html.DropDownList("values");

Run this view in browser and check, your drop-down list has been bind. This will create a simple list named “values” as specified as parameter. If we want to create a drop-down list for a model then:

@Html.DropDownListFor(model => model.property, (IEnumerable<SelectListItem>)ViewBag.values, new { html parameters })

This will bind this drop-down list as strongly with the property of the model.

Wednesday, September 3, 2014

Student Information Project in PHP

Introduction

Student information management system is a software application to  maintain the records related to student information , Fees status , marks and attendance.

Objective of the project

The main objective of application is to automate the existing system manually maintain the record of student information ,marks , attendance and student search to be computerized. So searching  will be faster.

Applications

This software covers following area

  1.     It  is very  useful for schools and colleges.
  2.    All record is computerized to we can use it for colleges.

Hardware and Software requirements

1. Dual core pc for server machine.
2. XAMPP for server machine

Future Scope


  1. Can be used for ERP Application

Project Snap Shot

Home page of online student information system project in php

Student Search in PHP

Student result in php

How to Download the project

Mail to me : narenkumar851@gmail.com

Project contains

  1. Project Report
  2. Project Code
  3. Project PPT

Online result showing project in ASP.NET

Introduction

This is the web application, in which you can get result of your all semester exam. After completing the exam you will get total result via this application. The main objective of this application is to get the result from any where, Suppose you are  a student, and  you loss your mark sheet when you go for interview. Before taking interview you can get result via college website.

Hardware and Software requirement

Hardware : Dual Core PC for Server machine, where you setup your project.
Software : IIS Web Server, DOTNET framework 4.0, SQL Server 2008.

How to run the application on client machine

Step-1 : Open this website in visual studio 2010
Step-2 : Run the application via ctrl+f5
Step-3 : Search the result via SPN Number, which is include in database
Step-4 : Insert new record via admin panel.

Project nap Screen


Home screen show the links for navigate the application. After enter the SPN number into the project you can enter into the result page, which is shown above.

Download the project

mail to me :  narenkumar851@gmail.com

Project contains some resources

1. Project Source code
2. Project report
3. Project PPT
© Copyright 2013 Computer Programming | All Right Reserved