-- переносим категорию по стоимости из типа работы по ТУ в работу по ТУ
declare @table_name nvarchar(50)
declare @strSQL nvarchar(1024)

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

if @strSQL<>''  exec (@strSQL)
GO
alter table TCWorkTypes drop column CostID
GO
alter table TCSpecItems add CostID int
GO

ALTER TABLE TCSpecItems
	ADD FOREIGN KEY (CostID)
	REFERENCES TCWorkTypeCosts(ID)	
GO

alter table ConsumingObjects alter column Name nvarchar(300) NOT NULL
GO
alter table TCApplicationInstallations alter column Name nvarchar(300) NOT NULL
GO
alter table TCSpecs alter column TCTariff decimal(18,2)
alter table TCSpecItemCosts alter column CostSum decimal(18,2)
alter table TCSpecItemCosts alter column CostMaterial decimal(18,2)
alter table TCSpecItemCosts alter column CostMechanical decimal(18,2)
alter table TCWorkTypeCosts alter column CostSum decimal(18,2)
alter table TCWorkTypeCosts alter column CostMaterial decimal(18,2)
alter table TCWorkTypeCosts alter column CostMechanical decimal(18,2)
GO