Create a Table with SQL Server 2019

Use SQL Server Management Studio to create tables visually

An SQL Server dialog box

Lifewire

Microsoft's SQL Server supports several different methods for creating new tables within a database. Many database developers prefer to manually script the SQL statements that create such objects, but the easier method relies on the GUI tools within SQL Server Management Studio.

The procedures outlined below govern Microsoft SQL Server Management Studio 2019, although procedures are similar for versions going back to 2012.

How to Create a Table Using SSMS

To create a table using the new-table wizard:

  1. From SMSS, within the Object Explorer, expand the tree for the relevant database. From the Tables node, right-click it and select New > Table.

    SMSS Add Table dialog box in SQL Server
     Lifewire
  2. From the New Table screen, enter the grid of information:

    • Column Name: Offer a unique name for the field.
    • Data Type: Select from the drop-down list the type of information that the field contains. Review documentation from Microsoft for a complete walk-through of these options.
    • Allow Nulls: Check this column if the column may remain null.
  3. As you complete each column in the list, modify the detail properties in the pane in the lower half of the window. In general, the most common properties you'll modify are the length (the maximum allowable size of the field) and a description (a plain-English definition of the field's intended purpose).

    sql server add field
  4. Use the Table Designer menu, or right-click on a specific column in the table designer, to further refine the table. Common options from the menu include:

    • Set Primary Key: Toggles whether the column constitutes a unique key value for the table.
    • Insert Column: Add a new column to the table.
    • Delete Column: Remove a column from the table.
    • Relationships: Establishes a foreign-key relationship to a different table.
    • Indexes/Keys: Sets unique properties or an index for the column.
    • Check Constraints: Sets rules governing acceptable values for the field. If the value doesn't fall within the constraints, the record won't save.
  5. Press Ctrl+S to save the table. You'll be prompted to offer a name for the table.

Creating Tables Using T-SQL

Microsoft's T-SQL supports data definition language capability to create, delete, or modify objects. If you're not deeply familiar with SQL, stick with the visual editor in SSMS.

Format
mla apa chicago
Your Citation
Chapple, Mike. "Create a Table with SQL Server 2019." ThoughtCo, Apr. 5, 2023, thoughtco.com/creating-tables-with-sql-server-2012-1019792. Chapple, Mike. (2023, April 5). Create a Table with SQL Server 2019. Retrieved from https://www.thoughtco.com/creating-tables-with-sql-server-2012-1019792 Chapple, Mike. "Create a Table with SQL Server 2019." ThoughtCo. https://www.thoughtco.com/creating-tables-with-sql-server-2012-1019792 (accessed March 19, 2024).