SQL From Nothing to Something – A Hands-On Beginning Tutorial Using SQL Server Express Edition
Why learn Structured Query Language (SQL)? One Simple reason: it’s arguably the most widely used data manipulation language. Database Administrators and Application Developers use it daily for storing and retrieving data. Even non-technical staff may use it for reporting and analysis. Anyone with access to databases or reporting tools will find knowledge of SQL essential. Plus, working knowledge of SQL looks good on a resume.
In this tutorial, you won’t merely read about SQL, you’ll actually write and execute SQL queries on your own computer. Don’t worry, it’s easy. You will need an internet connection and enough hard drive space to install the needed software (not much). This tutorial will use Microsoft’s SQL Server Express Edition. SQL Server is one of today’s leading database programs. The free Express Edition provides enough functionality to get anyone started with SQL. It’s probably the best place to start. To begin, type the following text into a search engine: “SQL Server Express 2008 Download” to download SQL Server Express Edition to your computer (follow the on-screen instructions).
After the file downloads, locate it on your computer and double-click it. This starts the installation. If prompted to run the file, do so. A variety of screens will open and close until the SQL Installation Center displays. Click “new installation” and follow the screens that appear. When prompted, enter an instance name of your choosing. One screen will ask for a user name and password. For the purposes of this tutorial, use your regular login information along with “Windows Authentication.” Unfortunately, the installation process involves waiting. Get a snack or take a lap around the block. If an error occurs during installation, type the error message into a search engine to find a solution. When installation completes, you’ll see a “complete” screen.
You’re now very close to writing actual SQL. Find and open the program called “SQL Server Management Studio” in the Microsoft SQL Server folder of your start menu programs. Management Studio (often called “SSMS”) provides an environment for writing SQL statements. When the program opens it will prompt you for a server name. Use the name you typed in for “instance name” during installation and make sure the “Authentication” box reads “Windows Authentication.” Then click “connect.”
Now you’re in the main Management Studio screen. You should see the name of your instance in the “Object Explorer” box and probably a lot of blank space. At this point you’re missing one vital piece, the most vital of all, and that’s data. You need to load data to write SQL. Since most people don’t have data lying around, you’re probably wondering where to get some. Luckily, Microsoft has made a sample database, called “AdventureWorks” freely available at the following website: msftdbprodsamples.codeplex.com.
Find the appropriate sample database package (likely SQL Server 2008R2 or SQL Server 2008, look for the version that you installed) and click to download an installation file. Once you have downloaded an executable file, locate the file and double click it to install the sample database. Follow the onscreen instructions and choose the same instance name you typed in during installation. Your database should now contain plenty of data. Verify this by clicking on “Databases” in the “Object Explorer” of Management Studio. You should see a list of AdventureWorks databases. Now we’re ready to write some SQL.
In the upper left corner, find a button called “new query” and click it. This opens a new window for writing SQL. Next, find a drop down box just below the “new query” button (it probably says “master”) and select “AdventureWorks.” This selects the database called “AdventureWorks” and any SQL you write will apply to this database.
Now click in the large blank space that opened up when you clicked “new query.” We will finally write some SQL and see some data. Type the following SQL statement into the query window:
SELECT *
FROM Sales. Individual
Now click the “Execute” button (just above the left side of the query window). Right below your query you should see columns of data appear. The SQL statement you entered asked the database to return everything (or “*”, which roughly translates as “everything”) from the Sales.Individual table. You have now officially typed SQL in your own database environment.
Let’s look at one more SQL example. What if you don’t want to see everything? Type the following into the query window:
SELECT CustomerID, ModifiedDate
FROM Sales.individual
This time when you click the “Execute” button only 2 rows of data appear. It should not surprise you that these columns correspond to the 2 rows in the SQL statement. In this case you’re seeing a section of the data. SQL allows you to see what you choose.
You are now ready to take your SQL learning to the next level. Try to find some free online tutorials by typing “SQL Tutorial” into any search engine. Many good SQL books also exist. Search Amazon reviews for recommendations. This will help you know what to buy, or what not to buy.
This short tutorial provided a tiny sample of the power of SQL. Don’t stop here. Keep learning and soon you’ll find yourself writing impressive SQL queries.
Tom Robbins has over 10 years of technical experience, including extensive use of SQL queries, programming, project management and business analysis.
