Search code examples
visual-studio-2012visual-studio-2013database-project

Is it possible to create a computed column in a Visual Studio database project?


Is it possible to create a computed column in a Visual Studio 2012 Database Project? There is a property called 'Computed column specification -> formula' but it is greyed out and it is not possible to enter a value in it.

Edit The computed column is also greyed out in VS 2013


Solution

  • You can add a computed column in the T-SQL pane. For example (field FullName below):

    CREATE TABLE [dbo].[Person] (
        [FirstName] VARCHAR(50) NOT NULL,
        [LastName] VARCHAR(50) NOT NULL,
        [FullName] AS ([FirstName] + ' ' + [LastName])
    );
    

    Once the column is defined in T-SQL, the "Formula" option in the properties will become editable. An option for "Is Persisted" will also appear.