Friday 28 December 2012

Commonly asked database Q&A

What is the difference between a “where” clause and a “having” clause?
“Where” is a kind of restriction statement. You use where clause to restrict all the data from DB.Where clause is using before result retrieving. But Having clause is using after retrieving the data.Having clause is a kind of filtering command.

What is bit data type and what’s the information that can be stored inside a bit column?
Bit data type is used to store Boolean information like 1 or 0 (true or false). Until SQL Server 6.5 bit data type could hold either a 1 or 0 and there was no support for NULL. But from SQL Server 7.0 onwards, bit data type can represent a third state, which is NULL.

What’s the difference between DELETE TABLE and TRUNCATE TABLE commands?
DELETE TABLE is a logged operation, so the deletion of each row gets logged in the transaction log, which makes it slow. TRUNCATE TABLE also deletes all the rows in a table, but it will not log the deletion of each row, instead it logs the de-allocation of the data pages of the table, which makes it faster. Of course, TRUNCATE TABLE can be rolled back.

 What is de-normalization and when would you go for it?
As the name indicates, de-normalization is the reverse process of normalization. It is the controlled introduction of redundancy in to the database design. It helps improve the query performance as the number of joins could be reduced.

What is a “constraint”?
A constraint allows you to apply simple referential integrity checks to a table. There are four primary types of constraints that are currently supported by SQL Server:
PRIMARY/UNIQUE – enforces uniqueness of a particular table column.
DEFAULT – specifies a default value for a column in case an insert operation does not provide one.
FOREIGN KEY – validates that every value in a column exists in a column of another table.
NOT NULL – constraint which does not allow values in the specific column to be null. And also, it is the only constraint which is not a table level constraint.

What’s the difference between a primary key and a unique key?
Both primary key and unique enforce uniqueness of the column on which they are defined. But by default primary key creates a clustered index on the column, where are unique creates a non-clustered index by default. Another major difference is that, primary key does not allow NULLs, but unique key allows one NULL only.

What is a “functional dependency”? How does it relate to database table design?
Functional dependency relates to how one object depends upon the other in the database. for example, procedure/function sp2 may be called by procedure sp1. Then we say that sp1 has functional dependency on sp2.

Why can a “group by” or “order by” clause expensive to process?
Processing of “group by” or “order by” clause often requires creation of Temporary tables to process the results of the query, which depending of the result set can be very expensive.

Source - GeekyFry

Monday 24 December 2012

Read/Write files from SD Card – PhoneGap/HTML/Javascript

Javascript functions to list out the files in SD card and show it in html div tag
 
Read files
 function BrowseFile()
{
window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, function(fs) {
var directoryReader = fs.root.createReader();
directoryReader.readEntries(function(entries) {
var i;
document.getElementById('dirList').innerhtml='';
var child="";
for (i=0; i<entries.length; i++) {
child=child+"<div>"+entries[i].toURI()+"</div>";
alert(entries[i].toURI());
}
document.getElementById('dirList').innerHTML = child;
}, function (error) {
alert(error.code);
})
}, function (error) {
alert(error.code);
});
} 
 
Create a file and write to it
function writeFile()
{
// root file system entry
var root = getFileSystemRoot();
// writes a file
write_file = function(writer)
{
var lineCount = 1;
// set the callbacks
writer.onwritestart = onFileEvent;
writer.onprogress = onFileEvent;
writer.onwrite = onFileWrite;
writer.onabort = onFileEvent;
writer.onerror = onFileError;
writer.onwriteend = function(event)
{
onFileEvent(event);
lineCount += 1;
if (lineCount <= 3)
{
// append a new line
writer.write('Line ' + lineCount + '.\r\n');
}
else {
alert(writer.fileName + ' length=' + writer.length + ', position=' + writer.position);
}
}
// append
writer.seek(writer.length);
// write to file
writer.write('Line ' + lineCount + '.\r\n');
},
// creates a FileWriter object
create_writer = function(fileEntry)
{
fileEntry.createWriter(write_file, onFileSystemError);
};
// create a file and write to it
root.getFile('bbgap2.txt', {create: true}, create_writer, onFileSystemError);
}

Reference links -
http://geekyfry.com/tech-it/smartphones/phonegap/reading-writing-files-from-sd-card-phonegaphtml5javascript/

Monday 19 November 2012

Speed comparison of JavaScript charting libraries


Choosing a charting component for any organization is a complex task because the selection will have to be made considering both the present and future needs of the organization. It requires a careful evaluation of requirements.
In this section, I have compared some of the popular charting components suitable for hybrid app development –


S No
Description
Charts
Advantage
Remark/Comment
1
Using <div> tag as placeholder for charts helps developer to adjust height/width eaisly into the HTML page
amCharts
  
Uses <div> tag
Highcharts
  
Uses <div> tag
RGraph

Uses <canvas> tag
Flot
  
Uses <div> tag
ZingCharts

Uses <canvas> tag
2
<div> tag is supported by all browsers whaeras <canvas> is a new HTML standard.
amCharts
  
All browser support
Highcharts
  
All browser support
RGraph

Only supported by HTML5 compliance browsers
Flot
  
All browser support
ZingCharts

Only supported by HTML5 compliance browsers
3
SVG scene graph is a old and stable way to represent graph/chart. SVG is like a "draw" program whereas HTML5 is a "paint" program and is a new concept.
amCharts
  
Uses SVG scene graph
Highcharts
  
Uses SVG scene graph
RGraph

Uses HTML5 Canvas
Flot

Unknown
ZingCharts

Uses HTML5 Canvas
4
Can eaisly change according to the landscape/potrait orientation of the device.
amCharts
  

Highcharts
  

RGraph

Difficult to achieve this functionality in RGraph
Flot


ZingCharts


5
Enables event handlers to be associated with objects
amCharts
  

Highcharts
  

RGraph

Not possible
Flot

Unknown
ZingCharts

Unknown
6
Includes meter charts
amCharts

Meter charts not supported
Highcharts
  

RGraph
  

Flot

Meter charts not supported
ZingCharts

Unknown
7
High quality.Nice visually.
amCharts
  

Highcharts


RGraph


Flot


ZingCharts
  

8
3D Charts
amCharts
  

Highcharts


RGraph


Flot


ZingCharts
  

9
Good Documentation and Online Support
amCharts
  

Highcharts
  

RGraph
  

Flot

Limited Support & documentation
ZingCharts
  

10
Build chart online with the help of Chart builder
amCharts


Highcharts


RGraph


Flot


ZingCharts
  


From the above comparisons it is quite obvious that each charting tool has its pros and cons. But, as per my view there is a competition between Highcharts and amCharts.
When I started with charting I found amCharts to be more documented and user friendly than Highchart, but if you check on the net, there is huge fan base for Highchart!
Think twice if you want meter charts, amCharts do not support meter charts and is a big disadvantage in this area. If you are looking for visuals, amCharts are smooth and nice with 3D chart support.

Reference links -
https://developers.google.com/chart/interactive/docs/gallery/controls#programmatic_change
http://bimeanalytics.com/blog/which-chart/