Wednesday, 13 March 2013

difference between stored procedures and functions ?

-> Procedure can return zero or n values whereas function can return one datatype value.
-> Returning a value is optional in Stored Procedure where as it is mandatory w.r.to a function.
-> Functions can be called from  procedure whereas procedures cannot be called from function.
-> Procedures can have both input/output parameters for it whereas functions can have only input parameters.
-> Exception can be handled by try-catch block in a procedure whereas try-catch block cannot be used in a function.
-> We can go for transaction management in procedure whereas we can't go in function.
-> Procedure allows select as well as DML(insert,delete,update) statement in it whereas function allows only select statement in it.

Monday, 11 March 2013

difference between truncate, delete and drop command in sql?

this is one of the most frequently asked question in interviews

The DELETE command is used to remove rows from a table and DELETE operation is temporary you need to either COMMIT or ROLLBACK the transaction to make the change permanent or to undo it. By using DELETE we can delete only selected rows as per our requirement.

TRUNCATE removes all rows from a table. The operation cannot be rolled back. TRUNCATE is faster and doesn't use as much undo space as a DELETE.
The DROP command removes a table and its related indexes and privileges from the database.The operation cannot be rolled back.
DELETE and TRUNCATE both are DML commands where as DROP is a DDL command.

Wednesday, 19 December 2012

What is the major difference b/w 32-bit and 64-bit processor ??

At any time processor can execute only one machine instruction, and that instruction length is 32 bits in 32-bit processor and 64 bits in 64-bit processor.

The memory addresses represented by a 32-bit processor is 2power32(2^32) where as 2power64(2^64) in case of 64-bit processor.since 64-bit processor has more memory address, it can even load entire program into memory and executes the program by reducing the overhead of Disk I/O cycles, thereby increasing the performance.

(if not entire program, 64-bit processor will have large "frame" size compared to 32-bit. so it can execute the program in less Disk I/O cycles) 

Cards Game Puzzle

Puzzle:- This puzzle is a game related one. Consider a game contains two participants(let is say player,comp) there are 21 cards in total and each participant can pick either 1 or 2 or 3 or 4 cards at a time. In every game first chance of picking cards is given to player and whoever takes the last card(here 21st card) will be the looser. solve the puzzle such that always comp should win the game.

Solution
if player picks x cards then computer should pick 5-x cards each round.
after four rounds 5*4 = 20 cards will be picked up then the player turn will come, as rule says he should pick atleast one card, so picks up the last card and looses the game.
this is the algorithm for which always computer will win the game.

Missing Ball Puzzle

This is one of the famous puzzles asked in interviews.

Puzzle: There are total hundred balls in a bag, numbered from 1..100(no two balls will have same number).From that bag one ball is stolen by a thief and you will be given that bag with remaining 99 balls. so you need to findout the missing ball in a better way?

Solution:

step1:- calculate the sum of hundred balls. use some of n numbers formula n*(n+1)/2.  i.e., ActualCount.

step2:- calculate the sum of remaining 99 balls.   i.e.,  ObtainedCount

step3:- missing ball number = ActualCount - ObtainedCount


If you have better solutions..please share them in comments!!