Link to home
Start Free TrialLog in
Avatar of Glen_D
Glen_D

asked on

Adding Computed Column to an Existing Table

I have this table and need the FacilityID to be a computed column; yes I can drop and recreate but having insert issues with the computed column in place.  This table has all the data now but I need to change the FacilityID to the computed column...

FacilityID as MainID

Thx

CREATE TABLE [dbo].[tbl_Facility](
      [FacilityID] [int] NULL,
      [MainID] [int] IDENTITY(1,1) NOT NULL,
      [FACID] [int] NULL,
      [BldID] [int] NULL,
      [BldGrpID] [int] NULL,
      [RoomID] [int] NULL,
      [Facility_Name] [varchar](max) NULL,
      [Facility_Description] [varchar](max) NULL,
      [CenterID] [int] NULL,
      [Building_Nos] [varchar](max) NULL,
      [Rooms] [varchar](max) NULL,
      [Capability] [nvarchar](max) NULL,
 CONSTRAINT [PK_tbl_Facility2] PRIMARY KEY CLUSTERED
Avatar of chapmandew
chapmandew
Flag of United States of America image

alter table tbl_Facility
add FacilityID as [MainID]
ASKER CERTIFIED SOLUTION
Avatar of BrandonGalderisi
BrandonGalderisi
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
whoops...brandon is right, you'll need to drop the column first.
alter table [dbo].[tbl_Facility] drop column [FacilityID]
ALTER TABLE dbo.tbl_Facility ADD FacilityID  AS mainid