USE [DD_ECM]
GO

/****** Object:  Table [dbo].[TBDEX_OUT_REFERENCES]    Script Date: 07.12.2025 23:23:07 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

CREATE TABLE [dbo].[TBDEX_OUT_REFERENCES](
	[GUID] [bigint] IDENTITY(1,1) NOT NULL,
	[OUT_ID] [bigint] NOT NULL,
	[REFERENCE1] [nvarchar](150) NOT NULL,
	[REFERENCE2] [nvarchar](150) NULL,
	[REFERENCE3] [nvarchar](150) NULL,
	[REFERENCE4] [nvarchar](150) NULL,
	[REFERENCE5] [nvarchar](150) NULL,
	[EXTERNAL_REFERENCE1] [nvarchar](255) NULL,
	[EXTERNAL_REFERENCE2] [nvarchar](255) NULL,
	[EXTERNAL_REFERENCE3] [nvarchar](255) NULL,
	[EXTERNAL_REFERENCE4] [nvarchar](255) NULL,
	[EXTERNAL_REFERENCE5] [nvarchar](255) NULL,
	[EXPORT_NUMBER] [nvarchar](50) NOT NULL,
	[ADDED_WHO] [nvarchar](50) NOT NULL,
	[ADDED_WHEN] [datetime] NOT NULL,
	[CHANGED_WHO] [nvarchar](50) NULL,
	[CHANGED_WHEN] [datetime] NULL,
 CONSTRAINT [PK_TBDEX_OUT_REFERENCES] PRIMARY KEY CLUSTERED 
(
	[GUID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = ON, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 80, OPTIMIZE_FOR_SEQUENTIAL_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
GO

ALTER TABLE [dbo].[TBDEX_OUT_REFERENCES] ADD  CONSTRAINT [DF_TBDEX_OUT_REFERENCES_ADDED_WHO]  DEFAULT ('DEFAULT') FOR [ADDED_WHO]
GO

ALTER TABLE [dbo].[TBDEX_OUT_REFERENCES] ADD  CONSTRAINT [DF_TBDEX_OUT_REFERENCES_ADDED_WHEN]  DEFAULT (getdate()) FOR [ADDED_WHEN]
GO

ALTER TABLE [dbo].[TBDEX_OUT_REFERENCES]  WITH CHECK ADD  CONSTRAINT [FK_TBDEX_OUT_REFERENCES_TBDEX_OUT] FOREIGN KEY([OUT_ID])
REFERENCES [dbo].[TBDEX_OUT] ([GUID])
GO

ALTER TABLE [dbo].[TBDEX_OUT_REFERENCES] CHECK CONSTRAINT [FK_TBDEX_OUT_REFERENCES_TBDEX_OUT]
GO

CREATE UNIQUE NONCLUSTERED INDEX [UX_TBDEX_OUT_REFERENCES_OUT_ID_EXPORT_NUMBER] ON [dbo].[TBDEX_OUT_REFERENCES]
(
	[OUT_ID] ASC,
	[EXPORT_NUMBER] ASC
)
WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = ON, SORT_IN_TEMPDB = OFF, IGNORE_DUP_KEY = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON)
ON [PRIMARY]
GO

CREATE NONCLUSTERED INDEX [IX_TBDEX_OUT_REFERENCES_OUT_ID] ON [dbo].[TBDEX_OUT_REFERENCES]
(
	[OUT_ID] ASC,
	[GUID] DESC
)
WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = ON, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON)
ON [PRIMARY]
GO

EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'Link OUT_ID' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'TBDEX_OUT_REFERENCES', @level2type=N'CONSTRAINT',@level2name=N'FK_TBDEX_OUT_REFERENCES_TBDEX_OUT'
GO


