Results 1 to 5 of 5

Thread: Adding Columns

  1. #1
    Join Date
    Dec 2003
    Posts
    44

    Unanswered: Adding Columns

    What is the SQL syntax for adding a column to an already created DB table?

  2. #2
    Join Date
    Jan 2004
    Posts
    9
    ALTER TABLE <your table> ADD <your column> <column definition>

    e.g.
    ALTER TABLE tbl ADD col VARCHAR(20) NULL

  3. #3
    Join Date
    Dec 2003
    Posts
    44
    Originally posted by waspfish
    ALTER TABLE <your table> ADD <your column> <column definition>

    e.g.
    ALTER TABLE tbl ADD col VARCHAR(20) NULL
    What is with the "NULL"?

    And, another question, how would you edit the name of an existing column?

  4. #4
    Join Date
    Dec 2003
    Posts
    454
    Open SQL Server Books Online and search the keywords of "ALTER TABLE" in the tab Index. You can get more information about modifications of a table definition by altering, adding, or dropping columns and constraints, or by disabling or enabling constraints and triggers.

  5. #5
    Join Date
    Jun 2003
    Location
    Ohio
    Posts
    12,592
    Provided Answers: 1
    ...or you can do it the lazy, cheating way:

    1) Open the table and make the changes you want.
    2) Click the "Save changes script" button in the icon bar.
    3) Copy the resulting script.
    4) Close your table WITHOUT saving changes.

    blindman
    If it's not practically useful, then it's practically useless.

    blindman
    www.chess.com: "sqlblindman"
    www.LobsterShot.blogspot.com

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •