?
Solved

Loops in SQL

Posted on 2011-09-08
2
Medium Priority
?
208 Views
Last Modified: 2012-05-12
Hello,

I am still trying to grasp some of the topics in SQL, and am wondering what loops are used for? I know how to construct a loop, but I just don't know in what case you would use one. If you could give me some real life examples with a description that would be great. Thanks.
0
Comment
Question by:erp1022
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 21

Accepted Solution

by:
JestersGrind earned 1200 total points
ID: 36505520
Generally loops should be avoid in SQL.  Database theory is based in set mathematics, thus SQL should use set based solutions as much as possible.  That being said the times to use loops are when it's necessary to execute thing row by row.  A common one that I run into is when I have a table of data to process and the stored procedure that processes the data only accepts single values, basically one record.  I would loop through my table and execute the procedure many times.  Not the most efficient way to do it.  Given more time, I would rather rewrite the called stored procedure to accept a table parameter or XML and process all the rows at once.  That's not always possible though.

Greg

0
 

Author Closing Comment

by:erp1022
ID: 36505651
Thanks!
0

Featured Post

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Long way back, we had to take help from third party tools in order to encrypt and decrypt data.  Gradually Microsoft understood the need for this feature and started to implement it by building functionality into SQL Server. Finally, with SQL 2008, …
If you have heard of RFC822 date formats, they can be quite a challenge in SQL Server. RFC822 is an Internet standard format for email message headers, including all dates within those headers. The RFC822 protocols are available in detail at:   ht…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question