[ Home ]

Cover of SQL Cover of SQL Tricks Cover of SQL Short Course Cover of SQL Visual QuickStart Guide 3rd Edition

Creating the Sample Database in Microsoft SQL Server 2008 Express Edition

To create books in Microsoft SQL Server 2008 Express Edition:

  1. On the Windows desktop, choose Start > All Programs > Microsoft SQL Server 2008 > SQL Server Management Studio.

    Microsoft SQL Server Management Studio opens.

  2. In the Connect to Server dialog box, select the server and authentication mode, and then click Connect.

    Connect to Server
  3. In Object Explorer (the left pane), navigate to the Databases folder of the server that you’re using.

    If Object Explorer isn’t visible, choose View > Object Explorer (or press F8).

  4. Right-click the Databases folder and choose New Database.

    The New Database dialog box opens.

    New Database
  5. On the General page, type books in the Database Name field, and then click OK. (You can use the General, Options, and Filegroups pages to specify other database settings, but the default settings work fine for the sample database.)

    SQL Server creates the database books and closes the New Database dialog box.

    General page
  6. In Object Explorer, expand the Databases folder and select the database books.

    New Query
  7. Choose File > Open > File (or press Ctrl+O), navigate to and select the file books_sqlserver.sql, and then click Open.

    The file’s contents appear in a new tab in the right pane.

    SQL query file contents
  8. Choose Query > Execute (or press F5).

    SQL Server Management Studio displays the results in the bottom pane. Ignore the messages about nonexistent tables — they’re caused by the script’s DROP TABLE statements, which you’ll need to rerun books_sqlserver.sql later to restore the tables to their original states.

    SQL query results
  9. To run SQL scripts and interactive statements against books, see “Microsoft SQL Server” in Chapter 1 of SQL or SQL Tricks, or in Appendix B of SQL Short Course or SQL Crash Course for Beginners.

Tip