You work as a database developer at ABC.com. ABC.com has a SQL Server 2012 database
named SalesDB that has a table named Inventory.
The Inventory table has three columns named ProductID, InStore and InWarehouse. The
ProductID column is the primary key and is linked to the Products table. The InStore column
stores the quantity of a product that is held at ABC.com’s retail shop, while the InWarehouse
column stores the quantity of a product that is held at ABC.com’s warehouse.
You need to add a computed column that is the sum of values in the InStore and InWarehoue
columns for each product.
What Transact SQL statement would accomplish this task?
A.
ALTER TABLE Inventory
ADD TotalProducts AS (InStore + InWarehouse)
B.
ALTER TABLE Inventory
ADD TotalProducts int SPARSE NOT NULL
C.
ALTER TABLE Inventory
ADD TotalProducts AS SUM (ALL) OVER (GROUP BY InStore, InWarehouse)
D.
DROP TABLE Inventory
GO
CREATE TABLE Inventory
(
ProductID int NOT NULL PRIMARY KEY,
InStore int NOT NULL,
InWarehouse int NOT NULL,
TotalProducts AS SUM (InStore, InWarehouse)
)
Explanation:
Ref: http://www.kodyaz.com/articles/sql-server-computed-column-calculated-column-sample.aspx
a
it should be
ALTER TABLE Inventory
ADD TotalProducts AS (InStore + InWarehouse) PERSISTED
since it is a computed column