SQL: Parameterized Queries

Instructor: David Gloag

David has over 40 years of industry experience in software development and information technology and a bachelor of computer science

SQL is a powerful tool for looking at information contained in a database. In this lesson, we'll take a look at SQL, what it is, what a query is, and what it means to parameterize a query.

Getting Your Hands on Information

Businesses access information every day. It's what makes them run. Walmart accesses revenue numbers to see how the day is progressing, Goldman Sachs accesses securities information to see how the markets are doing, and Netflix accesses download information to see what movies were streamed the day before. It's not hard to imagine. But how do they get at this information? And how do they select the specific pieces in question from the vast amounts of information available to them? The means vary depending on where the information is stored. If it's a database, then they use SQL, and in particular, a SQL query.

What is SQL?

SQL is a language. Specifically, it is a language used to access information in a database. Using a series of commands, SQL, or structured query language, performs various operations, such as searching, sorting, retrieving, and storing, to manipulate information in a database. SQL has been around for years. IBM developed it in the early 1970's, and it was released in 1979 by Oracle. Today, it has gained worldwide acceptance, standardized by both the American National Standards Institute (ANSI), and the International Organization of Standardization (ISO). As a result, many companies around the world use it, and others like Oracle, IBM, SyBase, Postgres, and Microsoft, integrate it as part of their product offerings.

What is an SQL Query?

In its simplest form, a query is a question. For example, you might query a person on how their day is going. Or, how the weather is. In computer terms, a query is a question you ask that you expect to be able to answer using the information in your possession. In SQL, that means the SELECT command. Let's look at an example. Say Starbucks wants to determine their sales total for all transactions they have on hand, and they have the following transaction information:

Date Amount
26-Sep-2016 4.00
27-Sep-2016 2.00
25-Sep-2016 1.00
27-Sep-2016 6.00
26-Sep-2016 5.00

Then the following SELECT command would return the value they were after:

SELECT SUM(Amount) AS Total FROM Transactions WHERE Date = '27-Sep-2016';

The result:

Total
8.00

Other, more significant queries, are also possible.

What is an SQL Parameterized Query?

A parameterized query is a query where variable information (parameters) are replaced by a symbol and filled with actual information at execution time. In the example above, the parameterized SELECT statement would look as follows:

SELECT SUM(Amount) AS Total FROM Transactions WHERE Date = @date;

To unlock this lesson you must be a Study.com Member.
Create your account

Register to view this lesson

Are you a student or a teacher?

Unlock Your Education

See for yourself why 30 million people use Study.com

Become a Study.com member and start learning now.
Become a Member  Back
What teachers are saying about Study.com
Try it risk-free for 30 days

Earning College Credit

Did you know… We have over 200 college courses that prepare you to earn credit by exam that is accepted by over 1,500 colleges and universities. You can test out of the first two years of college and save thousands off your degree. Anyone can earn credit-by-exam regardless of age or education level.

To learn more, visit our Earning Credit Page

Transferring credit to the school of your choice

Not sure what college you want to attend yet? Study.com has thousands of articles about every imaginable degree, area of study and career path that can help you find the school that's right for you.

Create an account to start this course today
Try it risk-free for 30 days!
Create an account
Support