Solved

Loops in SQL

Posted on 2011-09-08
2
203 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
2 Comments
 
LVL 21

Accepted Solution

by:
JestersGrind earned 300 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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Hi all, It is important and often overlooked to understand “Database properties”. Often we see questions about "log files" or "where is the database" and one of the easiest ways to get general information about your database is to use “Database p…
How to leverage one TLS certificate to encrypt Microsoft SQL traffic and Remote Desktop Services, versus creating multiple tickets for the same server.
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

759 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now