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
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
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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
ALTER TABLE dbo.tbl_Facility ADD FacilityID AS mainid
add FacilityID as [MainID]