IF OBJECT_ID(N'dbo._TabVyroba_TestoVyroba', N'U') IS NULL
 CREATE TABLE dbo._TabVyroba_TestoVyroba (
  ID int IDENTITY(1, 1) NOT NULL,
  IdPHIdent int NULL,
  IDPrikaz int NULL,
  IDDokladVydejMat int NULL,
  IDStrojPek INT NULL,
  IDKmenZbozi int NULL,
  SkupZbo NVARCHAR(3) NULL,
  RegCis NVARCHAR(30) NULL,
  MoukaHmot NUMERIC(10,2) NOT NULL DEFAULT 0.0,
  MoukaSilo TINYINT NULL,
  VodaLitry NUMERIC(10,2) NOT NULL DEFAULT 0.0,
  VodaPridavek NUMERIC(10,2) NOT NULL DEFAULT 0.0,
  Viskozita TINYINT NOT NULL DEFAULT 0,
  Viskozita2 TINYINT NOT NULL DEFAULT 0,
  DatPriprava DATETIME NULL,
  VyrobniDen DATETIME,
  Smena TINYINT,
  DatVypousteni DATETIME NULL,
  Spotrebovano numeric(10, 6) DEFAULT 0.0 NOT NULL,
  DatPorizeni datetime DEFAULT getdate() NOT NULL,
  DatPorizeni_H AS datepart(hour,[DatPorizeni]),
  DatPorizeni_N AS datepart(minute,[DatPorizeni]),
  DatPorizeni_D AS datepart(day,[DatPorizeni]),
  DatPorizeni_T AS datepart(week,[DatPorizeni]),
  DatPorizeni_M AS datepart(month,[DatPorizeni]),
  DatPorizeni_Q AS datepart(quarter,[DatPorizeni]),
  DatPorizeni_Y AS datepart(year,[DatPorizeni]),
  DatPriprava_X AS CONVERT(datetime, CONVERT(int, CONVERT(float, DatPriprava))),
  CONSTRAINT PK__TabVyroba_TestoVyroba PRIMARY KEY CLUSTERED (ID DESC) WITH ( PAD_INDEX = OFF, IGNORE_DUP_KEY = OFF, STATISTICS_NORECOMPUTE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON)
 )


/* 10.12.2023 */
IF COL_LENGTH(N'dbo._TabVyroba_TestoVyroba', N'IDStrojPek') IS NULL ALTER TABLE dbo._TabVyroba_TestoVyroba ADD IDStrojPek INT NULL
IF COL_LENGTH(N'dbo._TabVyroba_TestoVyroba', N'MoukaHmot') IS NULL ALTER TABLE dbo._TabVyroba_TestoVyroba ADD MoukaHmot NUMERIC(10,2) NOT NULL DEFAULT 0.0
IF COL_LENGTH(N'dbo._TabVyroba_TestoVyroba', N'MoukaSilo') IS NULL ALTER TABLE dbo._TabVyroba_TestoVyroba ADD MoukaSilo TINYINT NULL
IF COL_LENGTH(N'dbo._TabVyroba_TestoVyroba', N'VodaLitry') IS NULL ALTER TABLE dbo._TabVyroba_TestoVyroba ADD VodaLitry NUMERIC(10,2) NOT NULL DEFAULT 0.0
IF COL_LENGTH(N'dbo._TabVyroba_TestoVyroba', N'VodaPridavek') IS NULL ALTER TABLE dbo._TabVyroba_TestoVyroba ADD VodaPridavek NUMERIC(10,2) NOT NULL DEFAULT 0.0
IF COL_LENGTH(N'dbo._TabVyroba_TestoVyroba', N'Viskozita') IS NULL ALTER TABLE dbo._TabVyroba_TestoVyroba ADD Viskozita TINYINT NULL
IF COL_LENGTH(N'dbo._TabVyroba_TestoVyroba', N'Viskozita2') IS NULL ALTER TABLE dbo._TabVyroba_TestoVyroba ADD Viskozita2 TINYINT NULL
IF COL_LENGTH(N'dbo._TabVyroba_TestoVyroba', N'DatPriprava') IS NULL ALTER TABLE dbo._TabVyroba_TestoVyroba ADD DatPriprava DATETIME NULL
IF COL_LENGTH(N'dbo._TabVyroba_TestoVyroba', N'DatVypousteni') IS NULL ALTER TABLE dbo._TabVyroba_TestoVyroba ADD DatVypousteni DATETIME NULL
IF COL_LENGTH(N'dbo._TabVyroba_TestoVyroba', N'DatPriprava_X') IS NULL ALTER TABLE dbo._TabVyroba_TestoVyroba ADD DatPriprava_X AS CONVERT(datetime, CONVERT(int, CONVERT(float, DatPriprava)))

/* 11.12.2023 */
IF COL_LENGTH(N'dbo._TabVyroba_TestoVyroba', N'VyrobniDen') IS NULL ALTER TABLE dbo._TabVyroba_TestoVyroba ADD VyrobniDen DATETIME
IF COL_LENGTH(N'dbo._TabVyroba_TestoVyroba', N'Smena') IS NULL ALTER TABLE dbo._TabVyroba_TestoVyroba ADD Smena TINYINT

/* 20.3.2024 */
IF COL_LENGTH(N'dbo._TabVyroba_TestoVyroba', N'IDPrikaz') IS NULL ALTER TABLE dbo._TabVyroba_TestoVyroba ADD IDPrikaz INT NULL
IF COL_LENGTH(N'dbo._TabVyroba_TestoVyroba', N'IDDokladVydejMat') IS NULL ALTER TABLE dbo._TabVyroba_TestoVyroba ADD IDDokladVydejMat INT NULL




DROP INDEX IF EXISTS EI_TabVyroba_TestoVyroba_IdPH ON dbo._TabVyroba_TestoVyroba
 CREATE NONCLUSTERED INDEX EI_TabVyroba_TestoVyroba_IdPH ON dbo._TabVyroba_TestoVyroba (IdPHIdent)
  WITH ( PAD_INDEX = OFF, DROP_EXISTING = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON)

DROP INDEX IF EXISTS EI_TabVyroba_TestoVyroba_IdKmen ON dbo._TabVyroba_TestoVyroba
 CREATE NONCLUSTERED INDEX EI_TabVyroba_TestoVyroba_IdKmen ON dbo._TabVyroba_TestoVyroba (IDKmenZbozi)
  WITH ( PAD_INDEX = OFF, DROP_EXISTING = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON)

DROP INDEX IF EXISTS EI_TabVyroba_TestoVyroba_IdStroj ON dbo._TabVyroba_TestoVyroba
DROP INDEX IF EXISTS EI_TabVyroba_TestoVyroba_IdStrojPek ON dbo._TabVyroba_TestoVyroba
 CREATE NONCLUSTERED INDEX EI_TabVyroba_TestoVyroba_IdStrojPek ON dbo._TabVyroba_TestoVyroba (IDStrojPek)
  WITH ( PAD_INDEX = OFF, DROP_EXISTING = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON)

DROP INDEX IF EXISTS EI_TabVyroba_TestoVyroba_MoukaSilo ON dbo._TabVyroba_TestoVyroba
 CREATE NONCLUSTERED INDEX EI_TabVyroba_TestoVyroba_MoukaSilo ON dbo._TabVyroba_TestoVyroba (MoukaSilo)
  WITH ( PAD_INDEX = OFF, DROP_EXISTING = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON)
