SQL Server/T-SQL Tutorial/Table/Computed Columns

Материал из SQL эксперт
Перейти к: навигация, поиск

Computed columns are (by default) virtual columns not physically stored in the table.

   <source lang="sql">

Their values are recalculated each time they are referenced in a query. CREATE TABLE orders

       (orderid INT NOT NULL,
       price MONEY NOT NULL,
       quantity INT NOT NULL,
       orderdate DATETIME NOT NULL,
       total AS price * quantity PERSISTED,
       shippeddate AS DATEADD (DAY, 7, orderdate))

GO drop table orders; GO</source>