Computed columns are (by default) virtual columns not physically stored in the table : Computed Column « Table « SQL Server / T-SQL






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


1> -- Computed columns are (by default) virtual columns not physically stored in the table.
2> SET QUOTED_IDENTIFIER ON
3> GO
1>
2> CREATE TABLE orders
3>         (id                       INT NOT NULL,
4>          price                    MONEY NOT NULL,
5>          quantity                 INT NOT NULL,
6>          orderdate                DATETIME NOT NULL,
7>          total                    AS price * quantity PERSISTED,
8>          shippeddate              AS DATEADD (DAY, 7, orderdate))
9> GO
1>
2> insert into orders (id, price, quantity, orderdate)
3>             values (1, 100, 2, '1997.10.1')
4> GO

(1 rows affected)
1>
2> select * from orders
3> GO
id          price                 quantity    orderdate               total                 shippeddate
----------- --------------------- ----------- ----------------------- --------------------- -----------------------
          1              100.0000           2 1997-10-01 00:00:00.000              200.0000 1997-10-08 00:00:00.000

(1 rows affected)
1>
2> drop table orders
3> GO
           
       








Related examples in the same category

1.Add value from two columns as the computed column