IF OBJECT_ID(N'dbo._TabVyroba_PlanRozpad', N'U') IS NULL
 CREATE TABLE dbo._TabVyroba_PlanRozpad (
  ID int IDENTITY(1, 1) NOT NULL,
  Datum DATETIME NOT NULL,
  CasOd AS DATEPART(hour, Datum),
  Datum_D AS DATEPART(day, Datum),
  Datum_M AS DATEPART(month ,Datum),
  Datum_Y AS DATEPART(year, Datum),
  Datum_W AS DATEPART(week, Datum),
  Datum_V AS DATEPART(iso_week, Datum),
  Datum_Y_ISO AS DATEPART(year, DATEADD(day, 26-DATEPART(iso_week, Datum), Datum)),
  IDAdvKPDavka int NULL,
  IDPrikaz int NULL,
  DatPorizeni DATETIME NOT NULL DEFAULT GETDATE(),
  Autor NVARCHAR(80) NOT NULL DEFAULT SUSER_SNAME(),
  CONSTRAINT PK__TabVyroba_PlanRozpad PRIMARY KEY CLUSTERED (ID DESC) WITH (PAD_INDEX = OFF, IGNORE_DUP_KEY = OFF, STATISTICS_NORECOMPUTE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON)
 )

DROP INDEX IF EXISTS EI__TabVyroba_PlanRozpad_Datum ON dbo._TabVyroba_PlanRozpad
 CREATE NONCLUSTERED INDEX EI__TabVyroba_PlanRozpad_Datum ON dbo._TabVyroba_PlanRozpad (Datum)
  WITH ( PAD_INDEX = OFF, DROP_EXISTING = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON)
