Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you add a computed column to a Table?

Tags:

tsql

ddl

How can I add a computed column to a table that already exists? S.O. has Computed Column Help - TSQL but no information about adding them.

like image 331
Chris Pfohl Avatar asked Jun 15 '12 21:06

Chris Pfohl


People also ask

How do you use a computed column in SQL?

Go to your database, right click on tables, select “New Table” option. Create all columns that you require and to mark any column as computed, select that column and go to column Properties window and write your formula for computed column.

What is a computed column?

A computed column in SQL Server is a virtual column that computes its values from an expression. We can use a constant value, function, value derived from other columns, non-computed column name, or their combinations. SQL Server does not store these virtual columns physically, so it does not require any storage.

How do you change a column to a computed column?

Create a new diagram, add your table, and choose to show the formula column in the diagram's table view. Change the columns formula to an empty string ('') or something equally innocuous (probably such that you don't change the column's datatype). Save the diagram (which should save the table). Alter your function.

How do you add a column to a table?

Add a column to the left or right Under Table Tools, on the Layout tab, do one of the following: To add a column to the left of the cell, click Insert Left in the Rows and Columns group. To add a column to the right of the cell, click Insert Right in the Rows and Columns group.


1 Answers

The syntax I was looking for is:

alter table TABLE_NAME add [column_name] as (**COLUMN-SQL**) 
like image 177
Chris Pfohl Avatar answered Sep 17 '22 22:09

Chris Pfohl