IF COL_LENGTH('TBDD_MODULES','DB_VERSION') IS NULL
BEGIN
ALTER TABLE TBDD_MODULES
    ADD [DB_VERSION] VARCHAR(10) NOT NULL DEFAULT '1.0.0.0'

END
GO
UPDATE TBDD_MODULES SET DB_VERSION = '2.0.0.16' where NAME = 'Global-Indexer' 
GO
IF OBJECT_ID('TBDD_USER_DOKTYPE', 'U') IS  NULL
BEGIN
	CREATE TABLE [dbo].[TBDD_USER_DOKTYPE](
		[GUID] [int] IDENTITY(1,1) NOT NULL,
		[DOCTYPE_ID] [int] NOT NULL,
		[USER_ID] [int] NOT NULL,
		[ADDED_WHO] [varchar](50) NOT NULL,
		[ADDED_WHEN] [datetime] NULL,
		[CHANGED_WHEN] [datetime] NULL,
	 CONSTRAINT [PKTBDD_USER_DOKTYPE] PRIMARY KEY CLUSTERED 
	(
		[GUID] ASC
	)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
	) ON [PRIMARY];
	ALTER TABLE [dbo].[TBDD_USER_DOKTYPE] ADD  DEFAULT ('Digital Data') FOR [ADDED_WHO];
	ALTER TABLE [dbo].[TBDD_USER_DOKTYPE] ADD  DEFAULT (getdate()) FOR [ADDED_WHEN];
	ALTER TABLE [dbo].[TBDD_USER_DOKTYPE]  WITH CHECK ADD  CONSTRAINT [FK_TBDD_USER_DOKTYPE_DOCTYPE_ID] FOREIGN KEY([DOCTYPE_ID])
	REFERENCES [dbo].[TBDD_DOKUMENTART] ([GUID]);
	ALTER TABLE [dbo].[TBDD_USER_DOKTYPE] CHECK CONSTRAINT [FK_TBDD_USER_DOKTYPE_DOCTYPE_ID];
	ALTER TABLE [dbo].[TBDD_USER_DOKTYPE]  WITH CHECK ADD  CONSTRAINT [FK_TBDD_USER_DOKTYPE_USER_ID] FOREIGN KEY([USER_ID])
	REFERENCES [dbo].[TBDD_USER] ([GUID]);
	ALTER TABLE [dbo].[TBDD_USER_DOKTYPE] CHECK CONSTRAINT [FK_TBDD_USER_DOKTYPE_USER_ID];
END



