IF OBJECT_ID(N'dbo._TabVyroba_Palety', N'U') IS NULL
 CREATE TABLE dbo._TabVyroba_Palety (
  ID int IDENTITY(1, 1) NOT NULL,
  Typ tinyint DEFAULT 0 NOT NULL,
  CisloPalety nvarchar(50) NOT NULL,
  Sarze nvarchar(30) NULL,
  CisloOrg int NULL,
  IDPrikaz int NULL,
  IDKmen int NULL,
  IDStroj int NULL,
  IDVyrCisPrikaz int NULL,
  IDPlanRozpis INT NULL,
  DatPlan datetime NULL,
  HodinaPlan smallint NULL,
  DatZahajeni datetime NULL,
  DatUkonceni datetime NULL,
  Mnozstvi int DEFAULT 0 NOT NULL,
  MnozstviKA smallint DEFAULT 0 NOT NULL,
  MnozstviPlneKA smallint DEFAULT 0 NOT NULL,
  MnoztviPosledniKA smallint DEFAULT 0 NOT NULL,
  KusuVKA smallint DEFAULT 0 NOT NULL,
  JSONDataStart nvarchar(max) NULL,
  JSONStartResp nvarchar(max) NULL,
  JSONDataKonec nvarchar(max) NULL,
  JSONKonecResp nvarchar(max) NULL,
  DatPorizeni datetime DEFAULT getdate() NOT NULL,
  JeCislo AS CONVERT([bit],case when isnumeric([CisloPalety])=(1) then (1) else (0) end),
  CONSTRAINT PK__TabVyroba_Palety PRIMARY KEY CLUSTERED (ID DESC) WITH (PAD_INDEX = OFF, IGNORE_DUP_KEY = OFF, STATISTICS_NORECOMPUTE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON)
 )




/* 25.11.2023 */
IF COL_LENGTH(N'dbo._TabVyroba_Palety', N'IDKmen') IS NULL ALTER TABLE dbo._TabVyroba_Palety ADD IDKmen INT NULL
IF COL_LENGTH(N'dbo._TabVyroba_Palety', N'IDVyrCisPrikaz') IS NULL ALTER TABLE dbo._TabVyroba_Palety ADD IDVyrCisPrikaz INT NULL
IF COL_LENGTH(N'dbo._TabVyroba_Palety', N'KusuVKA') IS NULL ALTER TABLE dbo._TabVyroba_Palety ADD KusuVKA SMALLINT DEFAULT 0 NOT NULL
IF COL_LENGTH(N'dbo._TabVyroba_Palety', N'DatExpirace') IS NULL ALTER TABLE dbo._TabVyroba_Palety ADD DatExpirace DATETIME NULL


/* 29.10.2024 */
IF COL_LENGTH(N'dbo._TabVyroba_Palety', N'IDPlanRozpis') IS NULL ALTER TABLE dbo._TabVyroba_Palety ADD IDPlanRozpis INT NULL
IF COL_LENGTH(N'dbo._TabVyroba_Palety', N'DatPlan') IS NULL ALTER TABLE dbo._TabVyroba_Palety ADD DatPlan DATETIME NULL
IF COL_LENGTH(N'dbo._TabVyroba_Palety', N'HodinaPlan') IS NULL ALTER TABLE dbo._TabVyroba_Palety ADD HodinaPlan TINYINT NULL

/* 7.12.2024 */
IF COL_LENGTH(N'dbo._TabVyroba_Palety', N'JSONDataStart') IS NULL ALTER TABLE dbo._TabVyroba_Palety ADD JSONDataStart NVARCHAR(max) NULL
IF COL_LENGTH(N'dbo._TabVyroba_Palety', N'JSONDataKonec') IS NULL ALTER TABLE dbo._TabVyroba_Palety ADD JSONDataKonec NVARCHAR(max) NULL

IF COL_LENGTH(N'dbo._TabVyroba_Palety', N'JSONStartResp') IS NULL ALTER TABLE dbo._TabVyroba_Palety ADD JSONStartResp NVARCHAR(max) NULL
IF COL_LENGTH(N'dbo._TabVyroba_Palety', N'JSONKonecResp') IS NULL ALTER TABLE dbo._TabVyroba_Palety ADD JSONKonecResp NVARCHAR(max) NULL

IF EXISTS (SELECT 1 FROM sys.extended_properties WHERE [name]='MS_Description' AND major_id=OBJECT_ID(N'dbo._TabVyroba_Palety', N'U'))
 EXEC sp_dropextendedproperty @name='MS_Description', @level0type='schema', @level0name='dbo', @level1type='table', @level1name='_TabVyroba_Palety', @level2type='column', @level2name='Typ'
EXEC sp_addextendedproperty @name='MS_Description', @value=N'0-nedefinovano
1-vyrobek pekarna (vlastni)
2-vyrobek pekarna (externi)
3-material
4-zbozi
5-nestandard', @level0type='schema', @level0name='dbo', @level1type='table', @level1name='_TabVyroba_Palety', @level2type='column', @level2name='Typ'



DROP INDEX IF EXISTS EI__TabVyroba_Palety_Typ ON dbo._TabVyroba_Palety
 CREATE NONCLUSTERED INDEX EI__TabVyroba_Palety_Typ ON dbo._TabVyroba_Palety (Typ)
  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_Palety_IdPrikaz ON dbo._TabVyroba_Palety
 CREATE NONCLUSTERED INDEX EI__TabVyroba_Palety_IdPrikaz ON dbo._TabVyroba_Palety (IDPrikaz)
  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_Palety_IdStroj ON dbo._TabVyroba_Palety
 CREATE NONCLUSTERED INDEX EI__TabVyroba_Palety_IdStroj ON dbo._TabVyroba_Palety (IDStroj)
  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_Palety_CisloOrg ON dbo._TabVyroba_Palety
 CREATE NONCLUSTERED INDEX EI__TabVyroba_Palety_CisloOrg ON dbo._TabVyroba_Palety (CisloOrg)
  WITH ( PAD_INDEX = OFF, DROP_EXISTING = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON)

