II.5.6. Altering a Table via SQLCMD

If you're not a fan of graphical utilities like the SQL Server Management Studio, never fear. The SQLCMD utility allows you to interact directly with your database until your heart's content by using a character-based interface.

Here's how to use this utility to make a table modification. For this example, we're renaming a table and then adding a new column.

  1. Open a command prompt.

    Choose StartRun and enter cmd. Alternatively, you can choose ProgramsAccessoriesCommand Prompt. When you see the friendly command prompt, it's time to launch SQLCMD.

  2. 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 2 dozen parameters. Table 5-1 highlights a small group of key parameters.

    Table II.5-1. Key SQLCMD Parameters
    ParameterPurpose
    SSpecify the server that you want to connect to
    UProvide your username
    PProvide your password
    dWhich database to use (if any)
    iThe SQL script file (if any)

    If you get in hot water, you can always ask SQLCMD for help:

    SQLCMD /?
  3. Enter your SQL, ending your ...

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.