Have you ever watched someone work their magic with Structured Query Language or SQL? After entering what appears to be a few simple statements, the screen fills with the very information you’re looking for. As you watch the flood of data streaming down the screen, you’re thinking that you could do the same if you only knew SQL too.
While knowing SQL is a good start, you’ll quickly discover that you need to know just as much – if not more – about the database used to store your data. Your success at using SQL effectively requires that you intimately understand the relationships between – and the details of – the tables that comprise your database.
Schema refers to the organization of data as described by the database structure including tables and the constraints that may be imposed on them. Visit this “Database Schema” page on Wikipedia for a comprehensive definition of “Schema” and more detailed information.
On a side note, I recently purchased and highly recommend “Pro SQL Server Relational Database Design and Implementation” by Louis Davidson and Jessica Moss (Apress). Although you don’t need a book like this to learn how to query a database, know that the schema (design) is the most critical element of your database. If you are planning to purchase or if you are considering options to plan and design your own, it is imperative that you understand what is entailed in a well designed relational database solution.
Retrieving data from a database requires you to know where that data is stored and how it is related to other data that co-exists in other (different) tables. SELECT and FROM are two key words that will allow you to retrieve data from any table in your database.
-- Comments begin with 2 (two) dashes and used to explain the code.
-- The simplest of SQL statements to retrieve data from a table follows:
This simple SQL statement will retrieve all of the data, rows and columns, from “tablename”. If you don’t know the name of the table where your data resides then it doesn’t matter how much – or how little – SQL you know.
Compared to other languages, SQL has relatively few keywords. This is not to say that SQL is simple. The combinations and levels of nesting that can occur within an SQL statement can be overwhelmingly complex at times.
Understanding SQL is imperative to writing queries effectively, understanding your database schema is imperative to writing effective queries. Note the difference!