II.1.7. Scripting Your Database

When your database is set up and configured just the way you like, SQL Server offers a handy feature — scripting — that lets you re-create and then configure the database much more quickly in the future. Here's how you can take advantage of scripting:

  1. Launch the SQL Server Management Studio.

  2. Connect to the appropriate SQL Server instance.

  3. Expand the connection's entry in the Object Explorer view.

  4. Expand the Databases folder.

  5. Right-click the database you want to script and choose Script Database AsCREATE ToNew Query Editor Window.

    You can also select to save the results to a file or the Clipboard. For this example, we show you the script in a query window, which you can see in Figure 1-8. In reality, you probably want to save the script to a file.

    You can use the script any time you want to rebuild your database. This is especially helpful when you're experimenting with new databases.

What's especially nice about scripting is that you can use it for all sorts of administrative tasks, not just creating new databases.

Don't be afraid to experiment with scripting. In fact, after you start taking advantage of scripts, you'll probably find that your overall productivity ...

Get Microsoft® SQL Server™ 2008 All-In-One Desk Reference For Dummies® now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.