ALTER TABLE [AKUZ].[T_POST] DROP CONSTRAINT [FK_T_V002_PROFILE_T_POST_V002Profile]
GO

ALTER TABLE [AKUZ].[T_PRESCRIPTION_OF_OUTCOME] DROP CONSTRAINT [FK_T_V002_PROFILE_T_PRESCRIPTION_OF_OUTCOME_NAZ_PMP]
GO

ALTER TABLE [AKUZ].[T_STAFF_DATA] DROP CONSTRAINT [FK_T_V002_PROFILE_T_STAFF_DATA_ProfilV002]
GO

ALTER TABLE [AKUZ].[T_STRUCTURE_BED] DROP CONSTRAINT [FK_T_V002_PROFILE_T_STRUCTURE_BED_V002Profile]
GO

ALTER TABLE [AKUZ].[T_V002_PROFILE] DROP CONSTRAINT [PK_T_V002_PROFILE]
GO

ALTER TABLE [AKUZ].[T_V002_PROFILE] ADD [V002ProfileID] uniqueidentifier NULL
GO

UPDATE [AKUZ].[T_V002_PROFILE] SET [V002ProfileID] = newid()
GO

ALTER TABLE [AKUZ].[T_V002_PROFILE] ALTER COLUMN [V002ProfileID] uniqueidentifier NOT NULL
GO

ALTER TABLE [AKUZ].[T_V002_PROFILE] ADD CONSTRAINT [PK_T_V002_PROFILE]
PRIMARY KEY CLUSTERED ([V002ProfileID]) ON [PRIMARY]
GO

exec sp_rename 'AKUZ.T_POST.V002Profile', 'V002ProfileOld', 'COLUMN'

ALTER TABLE [AKUZ].[T_POST] ADD [V002Profile] uniqueidentifier NULL
GO

ALTER TABLE [AKUZ].[T_POST] ADD CONSTRAINT [FK_T_V002_PROFILE_T_POST_V002Profile]
FOREIGN KEY([V002Profile]) REFERENCES [AKUZ].[T_V002_PROFILE] ([V002ProfileID])
GO

update mrv
set mrv.V002Profile = vpm.V002ProfileID
from [AKUZ].[T_POST] mrv
inner join AKUZ.T_V002_PROFILE vpm
    on vpm.Id = mrv.V002ProfileOld

alter table [AKUZ].[T_POST] drop column V002ProfileOld

exec sp_rename 'AKUZ.T_PRESCRIPTION_OF_OUTCOME.NAZ_PMP', 'NAZ_PMPOld', 'COLUMN'

ALTER TABLE [AKUZ].[T_PRESCRIPTION_OF_OUTCOME] ADD [NAZ_PMP] uniqueidentifier NULL
GO

ALTER TABLE [AKUZ].[T_PRESCRIPTION_OF_OUTCOME] ADD CONSTRAINT [FK_T_V002_PROFILE_T_PRESCRIPTION_OF_OUTCOME_NAZ_PMP]
FOREIGN KEY([NAZ_PMP]) REFERENCES [AKUZ].[T_V002_PROFILE] ([V002ProfileID])
GO

update mrv
set mrv.NAZ_PMP = vpm.V002ProfileID
from [AKUZ].[T_PRESCRIPTION_OF_OUTCOME] mrv
inner join AKUZ.T_V002_PROFILE vpm
    on vpm.Id = mrv.NAZ_PMPOld

alter table [AKUZ].[T_PRESCRIPTION_OF_OUTCOME] drop column NAZ_PMPOld

exec sp_rename 'AKUZ.T_STAFF_DATA.ProfilV002', 'ProfilV002Old', 'COLUMN'

ALTER TABLE [AKUZ].[T_STAFF_DATA] ADD [ProfilV002] uniqueidentifier NULL
GO

ALTER TABLE [AKUZ].[T_STAFF_DATA] ADD CONSTRAINT [FK_T_V002_PROFILE_T_STAFF_DATA_ProfilV002]
FOREIGN KEY([ProfilV002]) REFERENCES [AKUZ].[T_V002_PROFILE] ([V002ProfileID])
GO

update mrv
set mrv.ProfilV002 = vpm.V002ProfileID
from [AKUZ].[T_STAFF_DATA] mrv
inner join AKUZ.T_V002_PROFILE vpm
    on vpm.Id = mrv.ProfilV002Old

alter table [AKUZ].[T_STAFF_DATA] drop column ProfilV002Old

exec sp_rename 'AKUZ.T_STRUCTURE_BED.V002Profile', 'V002ProfileOld', 'COLUMN'

ALTER TABLE [AKUZ].[T_STRUCTURE_BED] ADD [V002Profile] uniqueidentifier NULL
GO

ALTER TABLE [AKUZ].[T_STRUCTURE_BED] ADD CONSTRAINT [FK_T_V002_PROFILE_T_STRUCTURE_BED_V002Profile]
FOREIGN KEY([V002Profile]) REFERENCES [AKUZ].[T_V002_PROFILE] ([V002ProfileID])
GO

update mrv
set mrv.V002Profile = vpm.V002ProfileID
from [AKUZ].[T_STRUCTURE_BED] mrv
inner join AKUZ.T_V002_PROFILE vpm
    on vpm.Id = mrv.V002ProfileOld

alter table [AKUZ].[T_STRUCTURE_BED] drop column V002ProfileOld

ALTER TABLE [AKUZ].[T_V002_PROFILE] ADD [IS_IDENT] int NULL
GO

ALTER TABLE [AKUZ].[T_V002_PROFILE] ADD [PARENT_ID] int NULL
GO

exec dbo.sp_AlterDropColumn '[AKUZ].[T_V002_PROFILE]' , 'Name', 1, 'varchar(512) NOT NULL'
GO