DELETE TORDERSABISL WHERE TITEMID NOT IN (SELECT ITEMID FROM TITEM)
GO

IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_TORDERSABISL_TITEM]') AND parent_object_id = OBJECT_ID(N'[dbo].[TORDERSABISL]'))
ALTER TABLE [dbo].[TORDERSABISL]  WITH CHECK ADD  CONSTRAINT [FK_TORDERSABISL_TITEM] FOREIGN KEY([TITEMID])
REFERENCES [dbo].[TITEM] ([ITEMID])
GO

IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_TORDERSABISL_TITEM]') AND parent_object_id = OBJECT_ID(N'[dbo].[TORDERSABISL]'))
ALTER TABLE [dbo].[TORDERSABISL] CHECK CONSTRAINT [FK_TORDERSABISL_TITEM]
GO


