Creating a computed column in SQL Server 2008

前端 未结 2 2059
轮回少年
轮回少年 2020-12-17 09:15

I have a SQL Server 2008 database. This database has a Table called \"Book\". \"Book\" has the following properties:

  • ID (int)
  • Title (nvarchar(256))
相关标签:
2条回答
  • 2020-12-17 09:26

    You can define the column in your CREATE TABLE as:

    AgeInMinutes as (DATEDIFF(minute, PublishDate, GETDATE())

    Alternatively, just do

    ALTER TABLE Book
    ADD AgeInMinutes as (DATEDIFF(minute, PublishDate, GETDATE())
    
    0 讨论(0)
  • Modify computed column through SSMS. Right click on table and select Design then click on computed column then see in column properties there is one option like. Computed column specification there you can alter COMPUTED COLUMN.

    0 讨论(0)
提交回复
热议问题