IF OBJECT_ID(N'dbo._hdc_PZ_PuvodniVC', N'U') IS NULL
 CREATE TABLE dbo._hdc_PZ_PuvodniVC (
  ID int IDENTITY(1, 1) NOT NULL,
  IDPohybZbozi int NOT NULL,
  IDDoklad int NULL,
  IDZboSklad int NULL,
  VyrCis nvarchar(100) COLLATE Czech_CI_AS NOT NULL,
  IDVyrCis int NOT NULL,
  Mnozstvi numeric(19, 6) NOT NULL,
  Sarze NVARCHAR(100) NULL,
  PaletovyList NVARCHAR(100) NULL,
  IDUmisteni INT NULL,
  Autor nvarchar(128) COLLATE Czech_CI_AS CONSTRAINT DF___hdc_PZ_PuvodniVC__Autor DEFAULT suser_sname() NOT NULL,
  DatPorizeni datetime CONSTRAINT DF___hdc_PZ_PuvodniVC__DatPorizeni DEFAULT getdate() NOT NULL,
  BlokovaniEditoru smallint NULL,
  CONSTRAINT PK___hdc_PZ_PuvodniVC__ID PRIMARY KEY CLUSTERED (ID DESC) WITH (PAD_INDEX = OFF, IGNORE_DUP_KEY = OFF, STATISTICS_NORECOMPUTE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON)
 )


/* 9.9.2024 */
IF COL_LENGTH(N'dbo._hdc_PZ_PuvodniVC', N'Sarze') IS NULL ALTER TABLE dbo._hdc_PZ_PuvodniVC ADD Sarze NVARCHAR(100) NULL
IF COL_LENGTH(N'dbo._hdc_PZ_PuvodniVC', N'PaletovyList') IS NULL ALTER TABLE dbo._hdc_PZ_PuvodniVC ADD PaletovyList NVARCHAR(100) NULL
IF COL_LENGTH(N'dbo._hdc_PZ_PuvodniVC', N'IDUmisteni') IS NULL ALTER TABLE dbo._hdc_PZ_PuvodniVC ADD IDUmisteni INT NULL
IF COL_LENGTH(N'dbo._hdc_PZ_PuvodniVC', N'IDZboSklad') IS NULL ALTER TABLE dbo._hdc_PZ_PuvodniVC ADD IDZboSklad INT NULL
IF COL_LENGTH(N'dbo._hdc_PZ_PuvodniVC', N'IDDoklad') IS NULL ALTER TABLE dbo._hdc_PZ_PuvodniVC ADD IDDoklad INT NULL

/* 13.11.2023 */
IF COL_LENGTH(N'dbo._hdc_PZ_PuvodniVC', N'Zmenil') IS NOT NULL ALTER TABLE dbo._hdc_PZ_PuvodniVC DROP COLUMN Zmenil
IF COL_LENGTH(N'dbo._hdc_PZ_PuvodniVC', N'DatZmeny') IS NOT NULL ALTER TABLE dbo._hdc_PZ_PuvodniVC DROP COLUMN DatZmeny



IF NOT EXISTS(SELECT 1 FROM sys.indexes WHERE object_id=OBJECT_ID('dbo._hdc_PZ_PuvodniVC') AND name=N'EI__hdc_PZ_PuvodniVC__IDPohybZbozi')
 CREATE NONCLUSTERED INDEX EI__hdc_PZ_PuvodniVC__IDPohybZbozi ON dbo._hdc_PZ_PuvodniVC (IDPohybZbozi)
  WITH ( PAD_INDEX = OFF, DROP_EXISTING = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON)

IF NOT EXISTS(SELECT 1 FROM sys.indexes WHERE object_id=OBJECT_ID('dbo._hdc_PZ_PuvodniVC') AND name=N'EI__hdc_PZ_PuvodniVC__IDVyrCis')
 CREATE NONCLUSTERED INDEX EI__hdc_PZ_PuvodniVC__IDVyrCis ON dbo._hdc_PZ_PuvodniVC (IDVyrCis)
  WITH ( PAD_INDEX = OFF, DROP_EXISTING = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON)

IF NOT EXISTS(SELECT 1 FROM sys.indexes WHERE object_id=OBJECT_ID('dbo._hdc_PZ_PuvodniVC') AND name=N'EI__hdc_PZ_PuvodniVC__IDDoklad')
 CREATE NONCLUSTERED INDEX EI__hdc_PZ_PuvodniVC__IDDoklad ON dbo._hdc_PZ_PuvodniVC (IDDoklad)
  WITH ( PAD_INDEX = OFF, DROP_EXISTING = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON)
