II.1.6. Using SQLCMD to Create a Database
If you prefer the crisp picture of a black-and-white television over color, trust slide rules more than computers, and haven't traded in your vinyl LPs for those newfangled CDs, you'll probably be first in line to use the SQLCMD tool — a very helpful utility that allows both batch and interactive access to SQL Server. Here, we show you how to use it to create a new database, as well as run an existing SQL script.
Open a command prompt.
Choose Run from the Windows Start menu, and enter cmd. You can also choose ProgramsAccessoriesCommand Prompt from the Windows Start menu. When you see the friendly command prompt, it's time to launch SQLCMD.
Enter SQLCMD at the command prompt, passing in the proper parameters.
This can get a bit confusing. SQLCMD is rather picky about the exact syntax that it deigns appropriate to run. This isn't surprising when you realize that it supports more than two dozen parameters. Table 1-3 highlights a small group of key parameters.
Table II.1-3. Key SQLCMD Parameters Parameter Purpose S Specify the server that you want to connect to U Provide your username P Provide your password D Which database to use (if any) I The SQL script file (if any) If you get in hot water, you can always ask SQLCMD for help:
SQLCMD /?
Enter your SQL, ending ...
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.