ALTER TABLE [VCLib].[T_NEWS_BOX] ADD [type_] int NULL
GO

UPDATE [VCLib].[T_NEWS_BOX] SET [type_] = (select top 1 entityid from VCLib.T_ENTITIES where EntName = 'NEWS_BOX')
GO

ALTER TABLE [VCLib].[T_NEWS_BOX] ALTER COLUMN [type_] int NOT NULL
GO

ALTER TABLE [VCLib].[T_NEWS_BOX] ADD CONSTRAINT [FK_T_ENTITIES_T_NEWS_BOX_type_]
FOREIGN KEY([type_]) REFERENCES [VCLib].[T_ENTITIES] ([EntityID])
GO

