/***** Object:  Table [dbo].[T_PARAMETER_GROUP] *****/
CREATE TABLE [dbo].[T_PARAMETER_GROUP](
	[ParameterGroupID] uniqueidentifier NOT NULL,
	[Name] varchar(255) NOT NULL,
	[ParametrOrder] int NOT NULL
) ON [PRIMARY]
GO

ALTER TABLE [dbo].[T_PARAMETER_GROUP] WITH NOCHECK ADD CONSTRAINT [PK_T_PARAMETER_GROUP]
PRIMARY KEY CLUSTERED ([ParameterGroupID]) ON [PRIMARY]
GO
              

ALTER TABLE [dbo].[T_PLAN_PARAMETER] ADD [ParameterGroup] uniqueidentifier
GO
ALTER TABLE [dbo].[T_PLAN_PARAMETER] WITH NOCHECK ADD CONSTRAINT [FK_T_PARAMETER_GROUP_T_PLAN_PARAMETER_ParameterGroup] FOREIGN KEY ([ParameterGroup]) REFERENCES [dbo].[T_PARAMETER_GROUP] ([ParameterGroupID])
GO

delete from T_LIMIT_VALUE

IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_T_PLAN_PARAMETR_T_LIMIT_VALUE_PLANPARAMETER]') AND parent_object_id = OBJECT_ID(N'[dbo].[T_LIMIT_VALUE]'))
ALTER TABLE [dbo].[T_LIMIT_VALUE] DROP CONSTRAINT [FK_T_PLAN_PARAMETR_T_LIMIT_VALUE_PLANPARAMETER]

alter table T_LIMIT_VALUE drop column PlanParameter

ALTER TABLE [dbo].[T_LIMIT_VALUE] ADD [ParameterGroup] uniqueidentifier NOT NULL
GO

ALTER TABLE [dbo].[T_LIMIT_VALUE] WITH NOCHECK ADD CONSTRAINT [FK_T_PARAMETER_GROUP_T_LIMIT_VALUE_ParameterGroup] FOREIGN KEY ([ParameterGroup]) REFERENCES [dbo].[T_PARAMETER_GROUP] ([ParameterGroupID])
GO

