Creating Your First Table in Microsoft SQL Server

  • 2/15/2013

Understanding computed columns

Not only can you insert data directly into columns, but you can also derive columns from other columns. These columns are known as computed columns. Typically, computed columns will extend or enhance the data that is stored in traditional columns.

Add a computed column using SSMS

  1. Ensure that SSMS is open and you are connected to your server.

  2. Expand the Databases folder.

  3. Expand the SBSChp4SSMS database.

  4. Expand the Tables folder.

  5. Right-click the HumanResources.Employee table and select Design.

  6. Under Gender, in the next row, type FullName and press the Tab key.

  7. In the Column Properties section at the bottom of the table designer screen, locate and expand the Computed Column Specification property.

  8. In the Formula property, type LastName+’, ’+FirstName.

  9. Click Save.

Add a computed column using T-SQL

  1. Open the query editor in SSMS.

  2. In the query editor, enter and execute the following T-SQL code:

    --Use this code to add the Gender column to the Employee table
    ALTER TABLE HumanResources.Employee
         ADD FullName           AS LastName+', '+FirstName;