|
Execute the following
script in Query Editor to demonstrate the creation of a computed column. InventoryListValue is the computed column. SQL Server 2005 doesn't store its value, instead, it computes the value each time it's read.
USE tempdb
GO
CREATE TABLE dbo.Product (
ProductID int identity(1,1) primary key
, ProductName char(30)
, QtyOnHand int
, UnitPrice money
, InventoryListValue AS QtyOnHand * UnitPrice
)
GO
INSERT dbo.Product(ProductName, QtyOnHand, UnitPrice) SELECT 'Ipod', 25, 300
INSERT dbo.Product(ProductName, QtyOnHand, UnitPrice) SELECT 'Iphone', 99, 500
INSERT dbo.Product(ProductName, QtyOnHand, UnitPrice) SELECT 'Dell laptop', 10, 900
GO
SELECT * from dbo.Product
GO
|