Creating a computed column in SQL Server 2008

前端 未结 2 2063
轮回少年
轮回少年 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())
    

提交回复
热议问题