SQL: Using Loop instead of Cursor

Sample 1:
~~~~~~
Declare @temp table
(
row_id int identity (1,1),
product varchar(50)
)

Declare @i int, @max int

Insert into #temp (product) Select product From products

set @max = @@rowcount
set @i = 1

While @i <= @max Begin Select product From #temp Where row_id = @i // Do your Processing here set @i = @i + 1 End Sample 2:
~~~~~~
DECLARE @Product VARCHAR(50)
DECLARE @ProductID INT -- I assume Product ID as primary Key

SELECT * INTO #Products FROM Products

WHILE EXISTS (SELECT * FROM #Products)
BEGIN
SET ROWCOUNT 1
SELECT @ProductID = ProductID, @Product = Product FROM #Products
SET ROWCOUNT 0

// Do your Processing here

DELETE #Products WHERE ProductID = @ProductID
END

Technical Aspects

Exceptions add significant overhead to your application. Do not use exceptions to control logic flow, and design your code to avoid exceptions where possible. For example, validate user input, and check for known conditions that can cause exceptions. Also, design your code to fail early to avoid unnecessary processing.

Exceptions are expensive considering the performance. So it is better to use conditional checks rather using exceptions.

The @@scope_identity() is used to get the identity value of the last update. As the trigger is not in the scope of a stored procedure, hence the last update identity value for trigger can be achieved by using @@identity()

N'123' - Here "N" denotes a unicode string or nvarchar string. This is used when the argument required is of unicode format.

Resource files ".resx" are compiled to ".resources" using "resgen" utility.
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 won't log the deletion of each row, instead it logs the deallocation of the data pages of the table, which makes it faster. Of course, TRUNCATE TABLE can be rolled back.

The ASP.NET State Server is a Windows service that runs on any machine where Framework is installed.

An assembly with culture information is automatically assumed to be a satellite assembly.

Struct is similar to Class, but Struct imposes less overhead. Hence Class is intended to represent complex datatypes.

Value types impose less overhead than reference types because they’re allocated on the stack, not the heap.

CLR uses heap that's called managed heap.

Hashtables implements Idictionary and hence cannot be XMLSerialized, but they can be BinarySerialized.

Joins are faster than Sub-queries.

Clustured index is automatically applied when primary key is assigned to a table.
Clustured index information is stored in the table itself, whereas non-Clustured information is stored outside the table.
Insert can be slower on clustured indexes. When a row is to be inserted between two rows, then first the rows are to be adjusted such that the new row can be accomodated between the two rows. Whereas in clustured index, the index information is stored apart from table and hence the row can be added at the end of table and index information is stored in place other than table.
Clustured index is used when large amount or rows are returned especially using comparison operators.
Non-clustured index is used when minimum rows (1 row) is to be returned.
Clustured index can be applied on composite key.
If clustured index is increased from 3 or 4 index on a table, then it will degrade the performance.
Clustured index on table increases the performance.
There can be only one clustured index on one table whereas there can be multiple non-clustured index on one table.

Overloading means having two methods with same name but different signature.

Overriding means having two methods with same name and signature but one in base class and other in derived class.

Boxing is conversion of value type (integer, string, …) to reference type (object). And Unboxing is vise-versa.

Overloading and Overriding are types of Polymorphism.

Application_BeginRequest is called on arrival of each request whereas Application_Start is called when the first request is arrived for the application.

One assembly can have one or more namespaces. Also, one namespace can span across multiple assemblies. You can create nested namespaces. If you are using VS.NET then the project name acts as the default namespace name.

The main difference between inheritance based programming and interfaces based programming is that - interfaces just specify signatures of properties and methods for a class. Your class "implements" the interface by providing implementation for various properties and methods. Unlike inheritance there is no "code" inherited from interfaces. Your class can implement one or more interfaces.

Exceptions are unpredictable errors during runtime whereas Errors are predictable.

Metadata is the complete way of describing what is in a .NET assembly. Digging into the metadata yields the types available in that assembly, viz. classes, interfaces, enums, structs, etc., and their containing namespaces, the name of each type, its visibility/scope, its base class, the interfaces it implemented, its methods and their scope, and each method’s parameters, type’s properties, and so on.

InstallUtil.exe is a .NET utility to install Windows Service.

Positive Thoughts

  • Always wrong persons teach the right lessons of life.
  • Knowing is not enough. You must take action.
  • When you focus on problems, you will have more problems. When you focus on possibilities, you will have more possibilities.
  • Don't let urself die before ur heart stops......
  • All that we are is the result of what we have thought. - Buddha
  • Treat yourself with mind and others with heart.
  • As you receive goodness from others, pass it on.
  • What would you attempt to do if you knew you would not fail?
  • Being focused in the moment allows you to release the fear of the future and the guilt of the past.
  • A successful relationship requires falling in love many times ----- with the same person.
  • Obstacles are those frightful things you see when you take your mind off your goals.
  • Vision is not enough, it must be combined with venture. It is not enough to stare up the steps, we must step up the stairs.
  • If you get up one more time than you fall, you will make it through.
  • The world becomes a better place the moment you act on an intention to serve another.
  • You can choose to think higher thoughts.
  • One must conquer one's own self, for difficult it is to conquer it. One who does so, is blessed in this world and also in the next. - Lord Mahavir
  • There are three sides to any argument: your side, my side and the right side.
  • Love is everywhere, but you must choose to see it.
  • We must believe in luck. For how else can we explain the success of those we don't like?
  • The only way to get what you want is to ask for it.
  • Self acceptance is the doorway to greatness.
  • You are not limited by the thoughts of others. Your only limitation is the thoughts you choose to think.
  • Power is only yours if you claim it.
  • Your ability to create positive thoughts is unlimited.
  • Faith and trust keep you in the flow of God's goodness and mercy.
  • We are all God's children and therefore worthy of healing.
  • You can be transformed by loving yourself.
  • You are capable of accomplishing great things through the power of your consciousness.
  • True happiness is only in the moment.
  • You are more than okay. You are great!
  • Your truth is valuable. Speak it.
  • Your goodness lies in the present moment. Accept it now!
  • The one sure ingredient to success is to never, never give up.
  • If you want to change the world change the way you think about the world.
  • This new day is your opportunity to achieve.
  • I trust that God wants me to be happy.
  • As you focus on what is good about people, you enable them to achieve it.
  • A rigid mind is very sure, but often wrong. A flexible mind is generally unsure, but often right.
  • Formulate and stamp indelibly on your mind a mental picture of yourself as succeeding. Hold this picture tenaciously. Never permit it to fade. Your mind will seek to develop the picture...Do not build up obstacles in your imagination.
  • U learn in life when u lose
  • We must believe in luck. For how else can we explain the success of those we don't like?
  • I is always capital.
  • When you listen to others you are listening to yourself.
  • Face your past without regret. Handle your present with confidence. Prepare for the future without fear.
  • A good example has twice the value of good advice.
  • A slip of the foot you may soon recover, but a slip of the tongue you may never get over.
  • Hope is the foundation of change. Encouragement is the fuel.
  • Do one's best today to prepare for tomorrow.
  • You can have everything in life that you want if you will just help enough other people get what they want.
  • The power of accurate observation is frequently called cynicism by those who don't have it.
  • Focus on the journey, not the destination. Joy is found not in finishing an activity but in doing it.
  • Don't worry that there's not enough time. Just get started and go from there. Don't worry that it won't be perfect. Just get going and give it your very best. Don't be concerned about what others may think. Just go ahead and do what you know is best, what you know is right for you.
  • Don't be discouraged when you encounter obstacles. Just work your way diligently through each one.
  • Don't give up when the first attempt does not work out. Just learn from your mistakes and get going again.
  • There will always be plenty of excuses for not taking action, yet to achieve you must choose to look beyond those excuses. Just go ahead and get it done.
  • The Law of Win/Win says, "Let's not do it your way or my way; let's do it the best way.
  • Change yourself, or increase your context/perspective, so that it's no longer a problem.
  • Failure leads to success unless you quit.
  • Ideas without action are worthless.
  • Courage is the thing. All goes if courage goes.
  • Whether you think that you can, or that you can't, you are usually right.
  • If God is within you who can be against you?
  • You learn in life when you loose.
  • You have to know how to accept rejection and reject acceptance.
  • A man can fail many times but he isn't a failure until he gives up.
  • Failure is only the opportunity to more intelligently try again.
  • First say to yourself what you would be; and then do what you have to do.
  • We are the echo of the future.
  • Just remember, when you think all is lost, the future remains.
  • The only place success comes before work is in the dictionary.
  • Success is the maximum utilization of the ability that you have.
  • Success is getting what you want; happiness is wanting what you get.
  • Don't limit your challenges - challenge your limits.
  • Courage is not the absence of fear, but rather the judgement that something else is more important than fear.
  • You must do the thing you think you cannot do.
  • Confidence comes not from always being right but from not fearing to be wrong.
  • I believe that one of life's greatest risks is never daring to risk.
  • Do not go where the path may lead, go instead where there is no path and leave a trail.
  • Men do not fail; they give up trying.
  • We are what our thoughts have made us; so take care about what you think. Words are secondary. Thoughts live; they travel far. -- Swami Vivekananda
  • He is able who thinks he is able. --Lord Buddha
  • Be not afraid of growing slowly, be afraid only of standing still. --Chinese Proverb
  • First they ignore you, then they laugh at you and then you win. -- Mahatma Gandhi
  • Beware of false knowledge; it is more dangerous than ignorance.
  • While one person hesitates because he feels inferior, the other is busy making mistakes and becoming superior.
  • God gives every bird its food, but He does not throw it into its nest.
  • People forget how fast you did a job - but they remember how well you did it.
  • The pessimist sees the difficulty in every opportunity; the optimist, the opportunity in every difficulty. -- L.P. Jacks
  • You can often find in rivers what you cannot find in oceans. . --Indian Proverb
  • Give a man a fish and you feed him for a day. Teach a man to fish and you feed him for a lifetime. --Chinese Proverb
  • A strong positive mental attitude will create more miracles than any wonder drug.
  • You can discover what your enemy fears most by observing the means he uses to frighten you.
  • It is better to be hated for what you are than to be loved for what you are not.
  • If you're afraid to let someone else see your weakness, take heart: Nobody's perfect.
  • How you view the world is your choice.
  • Courage is the thing. All goes if courage goes.
  • Everyone has a will to win but very few have the will to prepare to win.
  • The best and most beautiful things in the world cannot be seen or even touched. They must be felt with the heart. --Helen Keller
  • Study as if you were to live forever. Live as if you were to die tomorrow. --Mahatma Gandhi
  • Obstacles are those frightful things you see when you take your eyes off your goal.
  • You have to know how to accept rejection and reject acceptance.
  • Failure is only the opportunity to more intelligently try again.
  • A man can fail many times but he isn't a failure until he gives up.
  • Being focused in the moment allows you to release the fear of the future and the guilt of the past.
  • Everybody makes mistakes; that's why they put erasers on pencils.
  • The best way to cheer yourself is to try to cheer someone else up.
  • We don't see things as they are, we see things as we are.
  • When it is darkest, men see the stars.
  • Don't go through life, grow through life.
  • He who conquers others is strong; he who conquers himself is mighty. - Lao Tzu.