Cursors in SQL Server

First thing first. Usage of Cursors is not encouraged in SQL Server as they are slow. You may go with WHILE loop if you need to iterate through a recordset.

Cursor is a database object to retrieve data from a result set one row at a time, instead of the T-SQL commands that operate on all the rows in the result set at one time.So this is a row by row operation instead of a set based operation.

SQL Server Cursor Components:
cursors include following components:

DECLARE statements – Declare variables used in the code block
SET\SELECT statements – Initialize the variables to a specific value
DECLARE CURSOR statement – Populate the cursor with values that will be evaluated

OPEN statement – Open the cursor to begin data processing
FETCH NEXT statements – Assign the specific values from the cursor to the variables
NOTE – This logic is used for the initial population before the WHILE statement and then again during each loop in the process as a portion of the WHILE statement
WHILE statement – Condition to begin and continue data processing
BEGIN…END statement – Start and end of the code block

CLOSE statement – Releases the current data and associated locks, but permits the cursor to be re-opened
DEALLOCATE statement – Destroys the cursor

Below is an example of a static cursor.

DECLARE @name varchar(50)
DECLARE @salary int
SELECT EmpID,EmpName,Salary from ContractEmployee
OPEN cur_emp

FETCH NEXT FROM cur_emp INTO @Id,@name,@salary
–FETCH ABSOLUTE 3 FROM cur_emp INTO @Id,@name,@salary

WHILE @@Fetch_status = 0
PRINT ‘ID : ‘+ convert(varchar(20),@Id)+’, Name : ‘+@name+ ‘, Salary : ‘+convert(varchar(20),@salary)
–FETCH RELATIVE 3 FROM cur_emp INTO @Id,@name,@salary
FETCH NEXT FROM cur_emp INTO @Id,@name,@salary

CLOSE cur_emp

Contact Us if you have any questions on cursors.



Understanding Indexes in SQL Server

Indexes in SQL Server are created on columns in tables or views. The index provides a faster way to look up data based on the values in those columns.
For example, if you create an index on the primary key and then search for a row of data based on one of the primary key values, SQL Server first finds that value in the index, and then uses the index to quickly locate the entire row of data. Without the index, a table scan would have to be performed in order to locate the row, which can have a significant effect on performance.

An index is made up of a set of pages (index nodes) that are organized in a B-tree structure. This structure is hierarchical in nature, with the root node at the top of the hierarchy and the leaf nodes at the bottom

When a query is issued against an indexed column, the query engine starts at the root node and navigates down through the intermediate nodes, with each layer of the intermediate level more granular than the one above. The query engine continues down through the index nodes until it reaches the leaf node.

For example, if you’re searching for the value 123 in an indexed column, the query engine would first look in the root level to determine which page to reference in the top intermediate level. In this example, the first page points the values 1-100, and the second page, the values 101-200, so the query engine would go to the second page on that level. The query engine would then determine that it must go to the third page at the next intermediate level. From there, the query engine would navigate to the leaf node for
value 123. The leaf node will contain either the entire row of data or a pointer to that row, depending on whether the index is clustered or nonclustered.

Indexes in SQL Server 2012:
Clustered Indexes:

A clustered index can be compared to a dictionary, where data is stored in a sorted form. If the data is in sorted form, then you can search for any word very quickly. So essentially A clustered index is table itself in a sorted order based on some column(s).

A clustered index stores the actual data rows at the leaf level of the index.An important characteristic of the clustered index is that the indexed values are sorted in either ascending or descending order. As a result, there can be only one clustered index on a table or view.A table that has no clustered index is referred to as a heap.

Nonclustered Indexes:

You can compare nonclusted index with the index pages given at the end of each book. They actually don’t store the data, but point you to the place where the actual data is. You can have multiple non clustered indexes on a table. And of course, the more Non clustered indexes you create on a table, the more storage they take.
Unlike a clustered indexed, the leaf nodes of a nonclustered index contain only pointers to the actual data rows, rather than contain the data rows themselves. A row locator’s structure depends on whether it points to a clustered table or to a heap. If referencing a clustered table, the row locator points to the clustered index, using the value from the clustered index to navigate to the correct data row. If referencing a heap, the row locator points to the actual data row.

Covering Index:
A non-clustered index that contains all the information needed to satisfy a query is known as a covering index.They enable the database administrator to add information to the non-clustered index data pages and avoid having to look up the row in the clustered index.
An index can contain more than one column, as long as the index doesn’t exceed the 900-byte limit in a clustered index key and 1700 bytes for nonclustered index key (In sql 2016).
–Example showing 900 bytes limit
create table IndexLimit(Empid int, EmpDesc varchar(1000))
create clustered index idx on IndexLimit(Empid,EmpDesc)
–Insert Fails
insert into IndexLimit values(12,replicate(‘a’,1000))
–Insert Succeeds
insert into IndexLimit values(12,replicate(‘a’,896))

As beneficial as indexes can be, they must be designed carefully. Because they can take up significant disk space, you don’t want to implement more indexes than necessary. In addition, indexes are automatically updated when the data rows themselves are updated, which can lead to additional overhead and can affect performance.

You should consider the following guidelines when planning your indexing strategy:

For tables that are heavily updated, use as few columns as possible in the index, and don’t over-index the tables.
If a table contains a lot of data but data modifications are low, use as many indexes as necessary to improve query performance. However,use indexes judiciously on small tables because the query engine might take longer to navigate the index than to perform a table scan.
For clustered indexes, try to keep the length of the indexed columns as short as possible. Ideally, try to implement your clustered indexes on unique columns that do not permit null values. This is why the primary key is often used for the table’s clustered index, although query considerations should also be taken into account when determining which columns should participate in the clustered index.
The uniqueness of values in a column affects index performance. In general, the more duplicate values you have in a column, the more poorly the index performs. On the other hand, the more unique each value, the better the performance. When possible, implement unique indexes.
For composite indexes, take into consideration the order of the columns in the index definition. Columns that will be used in comparison expressions in the WHERE clause (such as WHERE FirstName = ‘Charlie’) should be listed first. Subsequent columns should be listed based on the uniqueness of their values, with the most unique listed first.


Tips to get out most from your online computer training.

Dear Students,

Taking online courses can be very convenient for many people. However, online learning requires time management skills, self-discipline, willpower, and strong motivation, as it may be challenging for online learners to successfully complete their online software courses. Below are 10 important point, We, at RedBush technologies, ask students to think and understand. I hope all the fraternity will be benefitted from it.

  1. Understand online learning practices and expectations.
    The first thing you need to realize is that online software courses are not an easier way to learn, but rather a more convenient one. To successfully learn online, you need to dedicate a significant amount of your time, consistently attend the program, be concentrated while studying, and fully commit to your learning process, just as you would do for a regular course. You should also have in mind that when you take an online course, you may be expected to:


  • Fully commit yourself and participate in theVirtual classroom as required.
  • Be, or be willing to become, tech-savvy.
  • Work with others effectively.
  • Complete your learning tasks and assignments on time.
  • Be self-disciplined.
    If you are not able or willing to do all of the above, you will probably not be a very happy online learner.
  1. Make sure that you have reliable internet access. Technology glitches happen all the time. Imagine you are working in the middle of the night and your computer crashes. To avoid mishaps, ensure that you save your work repeatedly and backup regularly using cloud storage, for example Dropbox or Google Documents, in order to be able to access your previous work from your smart phone or tablet, if needed. Furthermore, ensure that you not only have a backup of your online course material and assignments, but also you have saved your instructor’s or trainer’s contact information in your cell phone or in your email. A reliable internet access will also give you the opportunity to check in, stay current with your eLearning course, and deal with sudden schedule changes.
  2. Have a dedicated study space.
    Whether you decide to study in your office or in your living room, ensure that this place is quiet, organized, distraction-free, and available for use at any time. Your study environment should be one of your main concerns when you are an online learner, so make sure that it enables your study routine. Furthermore, ask your friends, relatives, and colleagues to respect your “work mode” and consider turning off your phone and logging off of all social networks when studying; you will want to be neither interrupted nor distracted.
  3. Identify your learning objectives and goals. 
    To stay on track with your online course, make sure that you always keep in mind what you hope to accomplish by the end of it. The learning objective and goals of the eLearning course can be an excellent road map during online learning; read carefully your online course requirements, create notes that are closely related to your objectives, and make sure that you review them thoroughly every time you start an assignment, so that you stay focused on your goals. Finally, consider starting with the most difficult tasks, as this will improve both the effectiveness of your study and your performance.
  4. Build a study plan.
    An study plan is critical to online learning. Here are some tips to help you build it:


  • Plan ahead. 
    Never wait until the day before an assignment due date to start working on it. It will stress you and stress will prevent you from effectively completing the online task. Furthermore, knowing when all of your assignments are due until the end of the eLearning course will facilitate your time management; for instance, if you are going on vacation in the middle of the eLearning course, you can study ahead.
  • Have an effective calendar system. 
    Online learning needs structure; create a study calendar that will help you remember all important dates, like exams, or deadlines for submitting your assignments. You can save your calendar in your computer or in your mobile device, or you can even create a wall planner, which you can mark up and check every time you study.
  • Create to-do lists. 
    At the start of each week, make a to-do list of the tasks you need to complete by the end of the week. This is an excellent way to prioritize your study plan and stay on track with your studying.
  • Set time limits. 
    Before you start studying, estimate how much time each task will take to complete, whether it is a specific assignment or simply reading a chapter. Try to stick to your time limits, as this will help you develop your self-discipline. Furthermore, when you realize that despite your best efforts you cannot concentrate, consider stopping for an hour or for the night; it is better to wait until you are able to start afresh than to waste your time trying to focus.
  • Stay on schedule. 
    Finally, stick to your study plan. Procrastination is the worst enemy of online learners, so make sure that you stay organized and you are not falling behind in your online class. If you are having difficulties submitting your assignments on time, contact your online course instructor and let them know, so that they can help you create a consistent study routine.
  1. Ask for help when you need it.
    While it may be constructive to look for answers to your online course-related questions independently, hesitating to contact your online trainer when you are stuck may be problematic. If you don’t ask for help when necessary, you may end up falling behind, which may lower your self-esteem, as you may not be able to keep up with the online course. Build a relationship with your online instructor and avoid misunderstandings by contacting them regularly and informing them who you are, and how you could use their help. By asking your online instructors to clarify problems, you will also help them not only to evaluate learners’ level of understanding of the online material, but also to get an idea of the overall effectiveness of the online course. Finally, due to the open nature of online courses, by asking a question, you also help at the same time your virtual classmates, in case they are having similar difficulties. Keep in mind that if you don’t ask for help when you need it, your online instructor may never know that something is wrong.
  2. Review, revise, repeat. 
    Regular revisions of the things you have already studied will not only improve yourmemory , but they will also help you better understand what you are learning. Create your own flash cards for your key notes and quiz yourself on the key concepts of the online course. Furthermore, consider having one or more study partners; working in groupswill offer you alternative views of difficult concepts, motivation to achieve better results, and help in completing your online assignments more quickly by reviewing what you have learned. Share your study notes and habits with your virtual classmates and support each other throughout the online learning process.
  3. Take study breaks.
    Your performance will decrease if your are feeling tired or frustrated while studying. Integrate some personal time into your study routine and you will be able to work more effectively on your online course goals. When taking a break, make sure that you get away from your study space; you need to have a change of scenery. A mild physical activity, such as a walk around the block, will help you maintain balance, renew energy, and go back to studying with a clear mind.
  4. Participate in online discussions. 
    Online learning doesn’t necessarily mean learning in isolation. Connecting with your virtual classmates on social mediaor your online course’s forum will enhance tremendously your eLearning experience, especially if you are an introvert and visual barriers hinder you in expressing yourself. Participate actively in online discussions and group activities, suggest study tricks, offer your input on the eLearning course, and engage in new ideas. Just ensure that you are mindful of your online tone; be respectful when you disagree with other members of your online group, and always write in complete and clear sentences to avoid misunderstandings and tone mishaps.
  5. Stay motivated. 
    Finally, don’t underestimate the effort needed to fully commit to your online course. To make sure that you stay motivated and engaged in your online learning experience, consider following these tips:


  • Feel free to create your study routine at your own comfortable pace.
  • Decorate your study space with inspirational quotes and pictures.
  • Never forget the reason why you took this online course.
  • Accept that you will have productive and less productive days.
  • Have healthy snacks nearby to boost your energy.
  • Reward yourself every time you complete a challenging task.
  • Make sure that you take some time for yourself from time to time.
  • Stay positive and keep your chin up.

Follow these study tips for online learners and you will be able to make your online learning a fun and enjoyable online Learning experience.

Thank You




Why do you need to learn SQL Server,MSBI,.Net, isJava and C/C++?

SQL Server is a database management system which is used for various data relational purposes. The primary function is to store and retrieve data which is requested by any other software. The application can work on another computer connected via the internet.

In this digital era, computer and applications are becoming more sophisticated than ever due to the introduction of several platforms and technologies like iOS, Android, and Windows. The world is getting new smartphone apps with all the rising startups and programming is the future.

The front ends are a bit simple when compared to highly complex nature of the back-end platforms. There are many chances of implementation and integrations errors which is why it is mandatory to get a system that satisfies the ACID properties of the management system.

The databases are crucial for every single organization irrespective of their size. To ensure the smooth running of clients, customers, operations, and investors, the database needs a reliable system.

The future of technology is SQL, MSBI, Net, and C/C++. There are many career options for students all over the world. If you want a good job, that pays well and tests your skills at every single step. If you want a job that showcases your capabilities to the greatest extent, then you need to find a training institute near you. There are training institutes in Gurgaon for all the programs.

The demand for all round testers who have technical knowledge is unfathomable. With the growth of this sector, everyone wants to get their hands on the job. If you’re looking to build your career, then you can take online training where you can interact with experts. If you want your career to shine in leaps and bounds, then you need to learn SQL database testing. Every single organization is on the constant look out for SQL certified technicians.

Forget the competition, focus your goal on the top skills required for the job. Make your career shine brighter than ever by taking an SQL course so that you can be an SQL certified person. Get your career in shape by learning SQL, NET, JAVA, C, and C++.