-- переименовать Delineations
EXEC sp_rename 'Delineations', 'DelineationItems' 
GO

-- в рамках изменения ссылок в DelineationItems и DelineationSides
declare @table_name nvarchar(50)
declare @strSQL nvarchar(1024)

set @table_name=N'DelineationItems'
set @strSQL=''
select @strSQL = @strSQL + ' ALTER TABLE ' + @table_name + ' DROP CONSTRAINT '+ object_name(FK_Tab.id) 
from sysobjects FK_Tab 
where (xtype = 'F' or xtype = 'pk') AND object_id(@table_name)=parent_obj 

if @strSQL<>''  exec (@strSQL)
GO

declare @table_name nvarchar(50)
declare @strSQL nvarchar(1024)

set @table_name=N'DelineationSides'
set @strSQL=''
select @strSQL = @strSQL + ' ALTER TABLE ' + @table_name + ' DROP CONSTRAINT '+ object_name(FK_Tab.id) 
from sysobjects FK_Tab 
where (xtype = 'F' or xtype = 'pk') AND object_id(@table_name)=parent_obj 

if @strSQL<>''  exec (@strSQL)
GO

-- создать новую Delineations
CREATE TABLE Delineations
(
	DelineationID		int identity(1,1),
	DelineationBorder	nvarchar(200),
	DelineationDate		datetime,
	Pmax				float,
	PmaxFromSpec		bit,	
	SpecNumber			nvarchar(50),
	PmaxFromContract	bit,
	ContractNumber		nvarchar(50),
	PmaxFromNet			bit,
	PRIMARY KEY (DelineationID)
)
GO
-- создать заполнить новую Delineations
SET IDENTITY_INSERT Delineations ON

INSERT INTO Delineations (DelineationID,DelineationBorder,DelineationDate)
SELECT ID, DelineationBorder, DelineationDate
FROM ConsumingObjects
WHERE Exists (select 1 from DelineationItems where DelineationItems.ConsumingObjectID = ConsumingObjects.ID)

SET IDENTITY_INSERT Delineations OFF
GO

alter table ConsumingObjects add DelineationID int
GO
-- создать на неё ссылки из ConsumingObjects
UPDATE ConsumingObjects
SET DelineationID = ID
WHERE Exists (select 1 from DelineationItems where DelineationItems.ConsumingObjectID = ConsumingObjects.ID)
GO

-- убрать лишние поля из ConsumingObjects
alter table ConsumingObjects drop column DelineationBorder
alter table ConsumingObjects drop column DelineationDate
GO

-- перекинуть на неё ссылки из DelineationItems
EXEC sp_rename 'DelineationItems.ConsumingObjectID', 'DelineationID', 'COLUMN' 
GO
alter table DelineationItems add PRIMARY KEY (DelineationID, ItemNum)
GO
-- перекинуть на неё ссылки из DelineationSides
EXEC sp_rename 'DelineationSides.ConsumingObjectID', 'DelineationID', 'COLUMN' 
GO
alter table DelineationSides add PRIMARY KEY (DelineationID, ItemNum)
GO