SQL: Structured Query Language

Locating Objects in a Database

When astronomers want to find an object in the sky with a telescope, they can simply look through the eyepiece and scan around, or if they know where the object is relative to a brighter object, they can star hop to the location. With the help of some additional technology, they can use the RA and Dec coordinates to command the telescope to point to a precise location. But what do astronomers do when the images (and all the measurements that have been made using those images) are stored in a computer database? For this task, we need a way to talk to the database and ask it to search for and return the information we need. This is possible using the structured query language (SQL).

Decisions about how to design a database are very important. Before the Sloan Digital Sky Survey began capturing light from distant stars and galaxies in 1998, survey engineers had to make decisions about how the data from the survey would be organized. They organized the SDSS database into tables, each of which contains columns of related information. An SQL query is a set of instructions that accesses this information.

Let’s look at an example.

The following code calls up 10 random objects with spectra whose RA and Dec are in the range -0.1 to 0.1.

select top 10 * from photoObj

You can run this code by clicking Submit in the box below. You will see results in the same window.

Search

Results will appear here

What can an SQL query do?

The query we have used here is very simple, but others can be more complex. Queries may be written to select only objects from a specific location or region on the sky. The kind of information that you want to be returned (e.g., coordinates, apparent magnitude, object type, etc.,) is based on your search preferences; you can even request that the data be sorted in some way before being returned to you. Writing SQL queries is a skill that you build with practice (e.g., our Launch and Expedition activities).  If you would like to simply learn SQL on its own, the SkyServer website hosts an SQL tutorial.