Creating calculated columns..

wyrd

Well-known member
Joined
Aug 23, 2002
Messages
1,408
Location
California
Using a DataTable in .NET, creating a calculated column is easy enough. But how can I create one in the database itself (using Transact Sql) when creating a table?
 
Thats easy as well.

CREATE TABLE myTable
(
Price decimal(9, 2) NULL,
Stock int NULL,
StockValue AS Price*Stock
)

Calculated columns dont have a datatype and you can use userdefined functions with parameters as well.
 
Back
Top