Login
Copyright

Structured Query Language: Manipulating Databases Using SQL

An error occurred trying to load this video.

Try refreshing the page, or contact customer support.

Coming up next: Data Warehousing and Data Mining: Information for Business Intelligence

You're on a roll. Keep up the good work!

Take Quiz Watch Next Lesson
 Replay
Your next lesson will play in 10 seconds
  • 0:05 Manipulating a Database
  • 0:50 Structured Query Language
  • 1:59 SQL Statements
  • 2:57 SQL Syntax
  • 5:16 SQL Operators
  • 6:12 Boolean Logic
Add to Add to Add to

Want to watch this again later?

Log in or sign up to add this lesson to a Custom Course.

Login or Sign up

Timeline
Autoplay
Autoplay
Create an account to start this course today
Try it free for 5 days!
Create An Account

Recommended Lessons and Courses for You

Lesson Transcript
Instructor: Paul Zandbergen

Paul has a PhD from the University of British Columbia and has taught Geographic Information Systems, statistics and computer programming for 15 years.

Describe how to manipulate a database using the logic of Structured Query Language. Learn the basic syntax to write database queries in SQL using the SELECT statement.

Manipulating a Database

One of the primary functions of a database management system (DBMS) is to be able to manipulate data. This means adding new data, changing the values of existing data and reorganizing the data. Another basic form of data manipulation is to retrieve specific information from the database.

For example, for a database of employees within an organization, you may want to find just the employees hired within the last year or those holding a certain position. In database terminology, this is called a query. The term 'query' means 'to search, to question or to find.' So, a database query is like asking a question of the database.

Structured Query Language

Database queries are usually constructed using SQL, or Structured Query Language. SQL is a standard computer language for accessing and manipulating a database. SQL is a type of programming language, which is a language used to write instructions for a computer. However, SQL is a very specialized programming language specifically designed to work with databases. Examples of more general programming languages are Java and Python. These can also be used to work with databases, but SQL has many built-in functions that make it very easy to perform database queries.

Since SQL is so widely used, it has become an official standard of the American National Standards Institute. While the standard itself keeps changing over time as technology changes, the fact that SQL is an official standard has the advantage that if you learn the basics of the language, you can apply this in any database management system. Even though SQL uses the term 'query' in its name, it can be used not only to query databases, but also to insert, update and delete data.

SQL Statements

Like any programming language, SQL uses statements. A statement is a specific instruction for the computer to do something. For example, SQL contains the CREATE statement. As you can probably guess, this statement is used to create a new database or a new table or a new user.

There are many different kinds of SQL statements. In the following, we'll focus on just one of them: the SELECT statement. This statement is used to perform a query on a database. If you are using an existing database in DBMS software, this is likely the first SQL statement you will use. And, unless you are a database administrator, it may be the only one you will use.

The SELECT statement is used to accomplish one of the following:

  • To select specific rows and/or specific columns from a single table
  • To perform arithmetic and logical operations on a single table
  • To select results from two or more associated tables

SQL Syntax

SQL uses a very specific syntax. Syntax defines the logic of a programming language. It is similar to the grammar of a regular spoken language. Unless you follow the proper syntax, the DBMS will not understand your SQL statement.

Here is the basic syntax of a SQL SELECT statement:


basic syntax


This is a generic version of the syntax. When you work with an actual database, you specify the field(s) and table(s) by their name and you provide the conditional expression. Think of the conditional expression as the question you want to ask.

Time for an example. Let's say you have the following table of employees:


Example table for a query
example table


Your question is, 'Which employees have a salary greater than $65,000?' You translate this into a database query by writing a SELECT statement. In database terms, you want to select just those records for which the salary is greater than $65,000.

Here is what your SQL statement is going to look like:


SQL statement


If you were to use this SQL statement in DBMS software, this is what your result would look like:


Table showing query results
example of results


Of the seven records in the table, only five meet the stated condition. How this result is represented depends on the specific software, but it is typically in the form of a new table or report.

You can perform additional tasks by using other SQL statements. For example, sorting the data can be accomplished by using the ORDER BY statement.


order by

Your result would be the same list as before, but in alphabetical order.

The examples so far have selected records as well as fields. In many cases, you may want to select specific records, but you want to keep all the fields. This can be accomplished using a wildcard symbol:


wildcard

The wildcard symbol (*) means that the name of the field can be anything. In other words, all fields are selected.

SQL Operators

You probably noticed the use of the greater than (>) symbol in the conditional expression. This works just as you might expect. For every record, the salary is compared to the value of 65,000. If the salary is greater than 65,000, the record is selected and becomes a part of the result.

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

Register for a free trial

Are you a student or a teacher?
I am a teacher
What is your educational goal?
 Back

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

Earning College Credit

Did you know… We have over 95 college courses that prepare you to earn credit by exam that is accepted by over 2,000 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 free for 5 days!
Create An Account
Support