Database Concepts: Getting Started With Microsoft SQL Server 2014 Express
Database Concepts: Getting Started With Microsoft SQL Server 2014 Express
7th Edition
Online Appendix A
Getting Started with
Microsoft SQL Server 2014 Express
Database Concepts Getting Started with SQL Server 2014 Express Appendix A
All rights reserved. No part of this publication may be reproduced, stored in a retrieval system, or transmitted,
in any form or by any means, electronic, mechanical, photocopying, recording, or otherwise, without the prior
written permission of the publisher. Printed in the United States of America.
Appendix A — 10 9 8 7 6 5 4 3 2 1
A-2
Database Concepts Getting Started with SQL Server 2014 Express Appendix A
Chapter Objectives:
Microsoft SQL Server is an enterprise-class DBMS that has been around for many years. SQL Server
2005, including SQL Server 2005 Express Edition was released in November 2005. SQL Server 2008 and
SQL Server 2008 R2 were released in August 2008; SQL Server 2008 and SQL Server 2008 R2 also in-
cluded an Express version. SQL Server 2012 was released in March 2012. Now SQL Server 2014 Express
has been released and is available for use with this book. 1 The SQL Server Express Editions seem to be
designed to compete with Oracle’s MySQL (see Appendix C). MySQL is an open-source database that,
1
As this book goes to press, the current version of SQL Server Express Edition is SQL Server 2014 Express. No ser-
vice packs have been issued for SQL Server 2014. Always be sure you download and install the latest service pack
for whichever version of SQL Server or any other DBMS you are using.
A-3
Database Concepts Getting Started with SQL Server 2014 Express Appendix A
while not having as many features as SQL Server, has had the advantage of being available for free via
download over the Internet. It has become widely used and very popular as a DBMS, supporting Web
sites running the Apache Web server.
SQL Server Express is becoming increasingly popular. Microsoft releases various versions of SQL Server,
and while SQL Server Express is the least powerful version, it is intended for general use and can be
downloaded for free.
SQL Server 2014 Express is available in a basic package and in an advanced features package. The ver-
sion with advanced features is called SQL Server 2014 Express Advanced. Included in the advanced fea-
tures package is Microsoft’s GUI SQL Server management tool and support for SQL Server Reporting Ser-
vices. Both of these features are well worth having (otherwise you’ll need to download the management
tool separately), so download and install the version with the advanced features package. The screen
shots appearing in this book use SQL Server 2014 Express Advanced running in the Windows 7 operating
system.
By The Way
To install Microsoft SQL Server 2014, you will need to know whether you are running a 32-bit or 64-bit
operating system. Windows 8—and earlier versions of the Windows operating system—is available in
both 32-bit and 64-bit versions. To determine which version you have, click the Start button, right-click
Computer in the right hand column, and click Properties. Look at the value of System Type in the Sys-
tem information group.
The 32-bit versions of Microsoft programs (including, but not limited to, SQL Server 2014 Express) at the
download sites are designated as x86, while the 64-bit versions are designated as x64. The “x86” refers
to Intel processors that include “86” in the processor name (for example, the Intel 80486 CPU chip) and
related processors such as the Intel Pentium CPU chip (which would have been the 80586 if Intel hadn’t
switched to names instead of numbers for their product line).
For the purposes of this book, the most important reason to learn to use Microsoft SQL Server 2014 is
that SQL Server really handles SQL well. All the SQL results shown in Chapter 3 and Appendix E were cre-
ated in SQL Server 2014. All the SQL commands and keywords in Chapter 3 and Appendix E marked
“Does Not Work with Microsoft Access ANSI-89 SQL” will work with SQL Server.
As its title implies, this appendix is designed to get you started creating databases and running SQL com-
mands so that you can use a more robust SQL environment than that provided by Microsoft Access.
A-4
Database Concepts Getting Started with SQL Server 2014 Express Appendix A
The material in this appendix does not go beyond what is necessary to get you started. There are many
important SQL Server topics not covered here. Stored procedures and triggers are covered in Appendix
E. Backups and restores, and database security are covered in David M. Kroenke and David J. Auer, Data-
base Processing: Fundamentals, Design, and Implementation, 13th edition (Upper Saddle River, NJ: Pren-
tice Hall, 2014).
1. Microsoft Windows Installer 4.5. Before installing any of the SQL Server products, you must in-
stall Windows Installer 4.5 (http://www.microsoft.com/en-us/download/details.aspx?id=8483 ). This
version, or a later version should have been installed when you installed the Windows OS (Windows 7
and later), but we list this resource in case you need a separate installation).
2. Microsoft .NET Framework 3.5 Service Pack 1. This is an update to the Microsoft .NET Frame-
work 3.5 (http://www.microsoft.com/download/en/details.aspx?displaylang=en&id=22 ).
3. Microsoft .NET Framework 4.5.1. This is an updated version of the Microsoft .NET Framework.
(http://www.visualstudio.com/downloads/download-visual-studio-vs ).
4. Microsoft SQL Server 2014 Express Advanced. Note that Microsoft SQL Server 2014 Manage-
ment Studio is included in the download of Microsoft SQL Server 2014 Express Advanced. If you choose
to download the basic version of SQL Server 2014 Express, you must download and install this program
separately. Microsoft SQL Server 2014 Management Studio is the graphical management utility for SQL
Server 2014 in general and SQL Server 2014 Express edition in particular. SQL Server 2014 is a command
line–oriented program. SQL Server 2014 Management Studio makes it much easier to work with SQL
Server.
Be aware that SQL Server 2014 is an enterprise-class DBMSs and, as such, is much more complex than
Microsoft Access. Further, they do not include application development tools, such as form and report
generators. For more information on the Microsoft Express series of products, a good place to start is
www.microsoft.com/express.
A-5
Database Concepts Getting Started with SQL Server 2014 Express Appendix A
This appendix uses SQL Server 2014 – early versions of Microsoft SQL Server function similarly. To start
working with SQL Server 2014 Express in Windows 8 and 8.1 Update 1, double click the SQL Server Man-
agement Studio icon in the Start window (in the Windows 7 operating system, select Start | All Pro-
grams | Microsoft SQL Server 2014 | SQL Server Management Studio.) The Microsoft SQL Server Man-
agement Studio Connect to Server dialog box appears, as shown in Figure A-1.
By The Way
You can pin the Microsoft SQL Server Management Studio Express program icon to either or both the
Start Menu and the Taskbar. This makes it a lot easier to start the program if you are using it a lot.
To pin the program icon to either the Start Menu or the Taskbar, follow the command instructions
above to locate the SQL Server Management Studio Express program icon, and then right-click the pro-
gram icon. A shortcut menu will be displayed. Select either Pin to Start Menu or Pin to Taskbar.
If you use the default Windows Authentication method, you will be authenticated using your current
Windows username and password, so just click the Connect button. When you complete your login, the
Microsoft SQL Server Management Studio window appears, as shown in Figure A-2.
Using Windows
Authentication will
supply the current
user name and
password
A-6
Database Concepts Getting Started with SQL Server 2014 Express Appendix A
In the Microsoft SQL Server Management Studio, you should have an Object Explorer window on the
left side. The Object Explorer displays SQL Server 2014 objects (such as databases and tables) and the
folders (with labels such as Databases and Security) that are used to organize the presentation of the
objects. The folders are considered to be objects, and, therefore, the window contains an expandable
set of objects. In Figure A-2, the Databases folder has been expanded to show that it contains a folder
named System Databases and a database named Art-Course-Database. Also note the databases named
ReportServerSQLEXPRESS and ReportServerSQLEXPRESSTempDB—these are databases used by the
SQL Server 2014 Report Services engine that is provided as part of the SQL Server 2014 Express Ad-
vanced package.
A-7
Database Concepts Getting Started with SQL Server 2014 Express Appendix A
Right-click Data-
bases to display
the shortcut menu
A-8
Database Concepts Getting Started with SQL Server 2014 Express Appendix A
A-9
Database Concepts Getting Started with SQL Server 2014 Express Appendix A
By The Way
Using the Microsoft SQL Server Management Studio for Microsoft SQL Server 2014, we have to create
the Projects folder. In some previous versions of the Microsoft SQL Server Management Studio, the Pro-
jects folder is automatically created (along with the SQL Server Management Studio folder and the other
subfolders).
If you are using an earlier version of Microsoft SQL Server such as Microsoft SQL Server 2008 R2, you find
the Projects folder already created for you. You will still have to create a subfolder for each database.
The SQL statements to create the WPC database are shown in Figure 3-7, which is repeated as
Figure A-7 on the next page. These SQL Statements are SQL Server SQL commands, and we will use them
here. We will also use the SQL Server Management Studio as our text editor.
To create a new document for our SQL script, click the New Query button shown in Figure A-8. A new
tabbed document window, in this case named SQLQuery1.sql, is displayed to the right of the Object
Browser. The SQL Editor toolbar is also displayed, which contains tools useful when editing text. One of
Create a folder
named Projects,
the create subfold-
ers for each data-
base in the Pro-
jects folder
Figure A-6 — The Microsoft SQL Server Management Studio Folder in Windows Explorer
A-10
Database Concepts Getting Started with SQL Server 2014 Express Appendix A
Figure A-7 — The Figure 3-7 SQL Statements to Create the WPC Database Tables
A-11
Database Concepts Getting Started with SQL Server 2014 Express Appendix A
The
SQLQuery1.sql
tabbed document
window
The IntelliSense
Enabled button
these is the IntelliSense Enabled button, which may be useful to you as it provides some outlining and
auto-completion capabilities. However, you may also find it more confusing to see the notations and
auto-completion suggestions that are displayed (I know I often do!), and you can simply click the Intel-
liSense button to disable this feature. Also note the location of the Close button used to close the
tabbed document window.
• The text in Figure A-7 typed into the tabbed document window together with a header of com-
ments to document the file content—note the color coding.
• This text saved with the name DBC-e07-MSSQL-WPC-Create-Tables.sql (you can use a shorter
name if you prefer, such as just WPC-Create-Tables.sql). This was done by clicking the Save but-
ton shown in Figure A-8, browsing to the Projects folder, creating a subfolder named WPC
Scripts, and then naming and saving the file.
• The Available Databases drop-down list, which is used to select the active database—the one
that the script will be run against.
• The Parse button, which is used to test the SQL code before actually running it.
• The Execute button, which is used to actually run the SQL code in the document window.
Test your code until the parser doesn’t find any errors, save the script again, and then execute the
script. Figure A-10 shows the tables in the WPC database.
A-12
Database Concepts Getting Started with SQL Server 2014 Express Appendix A
Figure A-9 — The SQL Script to Create the WPC Database Tables
Output messages
are shown here—
either messages
that the commands
were successful or
appropriate error
messages
A-13
Database Concepts Getting Started with SQL Server 2014 Express Appendix A
By The Way
SQL Server is very sensitive about using SQL keywords as table or column names. Avoid keywords such
as name, date, and transaction. Use modified versions of such words whenever possible—ProjectName,
StartDate, ItemTransaction—or enclose the unmodified words in square brackets—[Name], [Date],
[Transaction]—if you must use them.
The SQL statements needed to insert data into the tables you have created are the same as the ones
shown in Figure 3-12, which are repeated in Figure A-11 on the next page. You also need to put this data
set into a script file, save it, be sure the WPC database is selected as the active database, and then run it
as an SQL script.
Now that we’ve created and populated the WPC database, we can run SQL queries against the data.
While scripts are good for large sets of SQL commands that need to be run together, most SQL queries
are run as single commands. To run a query, be sure the Databases folder is expanded in the Object
Browser so that you can see the database names. Click the New Query button in the Standard toolbar,
as shown in Figure A-8, to display a new tabbed SQL window along with the SQL Editor toolbar. Then
specify the database you want to query by selecting the database name in the Available Databases drop-
down list to select it.
By now you should be familiar with using the SQL query tabbed document window and running SQL
scripts. So, to create and run the SQL query, use the new SQL query window to:
The query results appear in a tabbed Results window below the query window in a spreadsheet-style
display, as shown in Figure A-12. You can adjust the size of the query window and the Results window,
and you can modify the column widths in the results display by using standard Windows drag-and-drop
techniques to help make more data visible. You can also have multiple queries open at the same time—
clicking the New Query button again opens another tabbed query window.
A-14
Database Concepts Getting Started with SQL Server 2014 Express Appendix A
Figure A-11 — The Figure 3-12 SQL Statements to Populate the WPC Database Tables
A-15
Database Concepts Getting Started with SQL Server 2014 Express Appendix A
/*********************************************************************************/
Figure A-11 — The Figure 3-12 SQL Statements to Populate the WPC Database Tables (Continued)
A-16
Database Concepts Getting Started with SQL Server 2014 Express Appendix A
For SQL Server 2014, you do not have to take any extra steps to install OBDC support. The ODBC Driver
11 for SQL Server is automatically installed and available for use, as shown in Figure 7-9.
To get access to SQL Server documentation, use SQL Server 2014 Books Online at http://msdn.mi-
crosoft.com/en-us/library/ms130214.aspx.
Key Terms
ReportServerSQLEXPRESS ReportServerSQLEXPRESSTempDB
SQL Server 2014 Express Advanced SQL Server 2014 Report Services
A-17
Database Concepts Getting Started with SQL Server 2014 Express Appendix A
Review Questions
A.2 What is the primary advantage of using SQL Server 2014 Express instead of Microsoft Access?
A.3 What is the set of Microsoft programs that are recommended as a necessary set of SQL Server
2014 Express Advanced software products? In what order should you install these products?
A.6 How do you specify the active database in SQL Server 2014?
A.7 What is an SQL script? What types of SQL statements and commands can you run more effi-
ciently as scripts?
A.9 What file extension should you use for SQL scripts?
A.11 How do you create and run an SQL query in SQL Server?
Exercises
A.12 If you haven’t already done so, download and install SQL Server 2014 Express Advanced as de-
scribed in the text. Use the default settings for the installation. Be sure that the Microsoft SQL
Server Management Studio is correctly installed.
A.13 If you haven’t already done so, work through the steps described in this appendix to create and
populate the WPC database.
A.14 Using SQL Server 2014 and the Microsoft SQL Server Management Studio, run the following SQL
queries in the “SQL for Relational Queries” section of Chapter 3:
A-18
Database Concepts Getting Started with SQL Server 2014 Express Appendix A
A.17 Complete exercise 3.64 using SQL Server 2014 and the Microsoft SQL Server Management Stu-
dio. Start the saved query name with MSSQL- and use the default .sql file extension. The saved
query name will be MSSQL-SQL-Query-AWE-3-3-E.sql.
A-19