CREATE DATABASE [kufrik]
 CONTAINMENT = NONE
 ON  PRIMARY 
( NAME = N'kufrik', FILENAME = N'/var/opt/mssql/data/kufrik.mdf' , SIZE = 8192KB , FILEGROWTH = 65536KB )
 LOG ON 
( NAME = N'kufrik_log', FILENAME = N'/var/opt/mssql/data/kufrik_log.ldf' , SIZE = 8192KB , FILEGROWTH = 65536KB )
GO
ALTER DATABASE [kufrik] SET COMPATIBILITY_LEVEL = 150
GO

--user:
USE [master]
GO
CREATE LOGIN [kufrik] WITH PASSWORD=N'giteaKufrik_2024', DEFAULT_DATABASE=[master], CHECK_EXPIRATION=OFF, CHECK_POLICY=OFF
GO
use [master];
GO
USE [kufrik]
GO
CREATE USER [kufrik] FOR LOGIN [kufrik]
GO
USE [kufrik]
GO
ALTER USER [kufrik] WITH DEFAULT_SCHEMA=[dbo]
GO
USE [kufrik]
GO
ALTER ROLE [db_owner] ADD MEMBER [kufrik]
GO

USE [kufrik]
GO
/****** Object:  Table [dbo].[FAKTURA]    Script Date: 31.07.2026 9:05:46 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[FAKTURA](
	[ID] [int] IDENTITY(15,1) NOT NULL,
	[DATUM_VYSTAVENI] [datetime] NOT NULL,
	[DATUM_SPLATNOSTI] [datetime] NOT NULL,
	[ZAKAZNIK] [int] NOT NULL,
	[CISLO] [nvarchar](20) NOT NULL,
	[D_PRAJM] [nvarchar](511) NULL,
	[D_ULICE] [nvarchar](50) NULL,
	[D_MESTO] [nvarchar](50) NULL,
	[D_PSC] [nvarchar](50) NULL,
	[D_IC] [nvarchar](8) NULL,
	[D_DIC] [nvarchar](10) NULL,
	[D_BANKA] [nvarchar](100) NULL,
	[D_TELEFON] [nvarchar](15) NULL,
	[D_EMAIL] [nvarchar](100) NULL,
	[D_WEB] [nvarchar](100) NULL,
	[O_PRAJM] [nvarchar](511) NULL,
	[O_ULICE] [nvarchar](50) NULL,
	[O_MESTO] [nvarchar](50) NULL,
	[O_PSC] [nvarchar](5) NULL,
	[O_IC] [nvarchar](8) NULL,
	[O_DIC] [nvarchar](10) NULL,
	[FORMA_UHRADY] [tinyint] NOT NULL,
	[CISLO_ABS] [int] NOT NULL,
	[CINNOSTI] [ntext] NULL,
 CONSTRAINT [PK_FAKTURA] PRIMARY KEY CLUSTERED 
(
	[ID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, OPTIMIZE_FOR_SEQUENTIAL_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
GO
/****** Object:  Table [dbo].[KONFIGURACE]    Script Date: 31.07.2026 9:05:46 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[KONFIGURACE](
	[ID] [int] IDENTITY(2,1) NOT NULL,
	[DATA] [ntext] NULL,
 CONSTRAINT [PK_KONFIGURACE] PRIMARY KEY CLUSTERED 
(
	[ID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, OPTIMIZE_FOR_SEQUENTIAL_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
GO
/****** Object:  Table [dbo].[PLATBA]    Script Date: 31.07.2026 9:05:46 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[PLATBA](
	[ID] [int] IDENTITY(11,1) NOT NULL,
	[FAKTURA] [int] NOT NULL,
	[CASTKA] [money] NOT NULL,
	[DATUM] [datetime] NOT NULL,
	[POZNAMKA] [ntext] NULL,
 CONSTRAINT [PK_PLATBA] PRIMARY KEY CLUSTERED 
(
	[ID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, OPTIMIZE_FOR_SEQUENTIAL_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
GO
/****** Object:  Table [dbo].[POLOZKA]    Script Date: 31.07.2026 9:05:46 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[POLOZKA](
	[ID] [int] IDENTITY(24,1) NOT NULL,
	[FAKTURA] [int] NOT NULL,
	[NAZEV] [nvarchar](255) NOT NULL,
	[POCET] [float] NOT NULL,
	[CENA_JEDNOTKA] [money] NOT NULL,
	[SLEVA] [real] NULL,
	[CENA] [money] NOT NULL,
	[JEDNOTKA] [nvarchar](5) NULL,
 CONSTRAINT [PK_POLOZKA] PRIMARY KEY CLUSTERED 
(
	[ID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, OPTIMIZE_FOR_SEQUENTIAL_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[UZIVATEL]    Script Date: 31.07.2026 9:05:46 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[UZIVATEL](
	[ID] [int] IDENTITY(2,1) NOT NULL,
	[JMENO] [nvarchar](255) NULL,
	[PRIJMENI] [nvarchar](255) NOT NULL,
	[ULICE] [nvarchar](50) NULL,
	[MESTO] [nvarchar](50) NULL,
	[PSC] [nvarchar](5) NULL,
	[IC] [nvarchar](8) NULL,
	[DIC] [nvarchar](10) NULL,
	[TELEFON] [nvarchar](15) NULL,
	[EMAIL] [nvarchar](100) NULL,
	[BANKA] [nvarchar](100) NULL,
	[WEB] [nvarchar](100) NULL,
 CONSTRAINT [PK_UZIVATEL] PRIMARY KEY CLUSTERED 
(
	[ID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, OPTIMIZE_FOR_SEQUENTIAL_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[VERZE]    Script Date: 31.07.2026 9:05:46 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[VERZE](
	[ID] [int] IDENTITY(15,1) NOT NULL,
	[VERZE] [smallint] NOT NULL,
	[DATUM] [datetime] NOT NULL,
 CONSTRAINT [PK_VERZE] PRIMARY KEY CLUSTERED 
(
	[ID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, OPTIMIZE_FOR_SEQUENTIAL_KEY = OFF) ON [PRIMARY],
 CONSTRAINT [UQ__VERZE__ID] UNIQUE NONCLUSTERED 
(
	[ID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, OPTIMIZE_FOR_SEQUENTIAL_KEY = OFF) ON [PRIMARY],
 CONSTRAINT [UQ__VERZE__VERZE] UNIQUE NONCLUSTERED 
(
	[VERZE] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, OPTIMIZE_FOR_SEQUENTIAL_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[ZAKAZNIK]    Script Date: 31.07.2026 9:05:46 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[ZAKAZNIK](
	[ID] [int] IDENTITY(2,1) NOT NULL,
	[JMENO] [nvarchar](255) NULL,
	[PRIJMENI] [nvarchar](255) NOT NULL,
	[ULICE] [nvarchar](50) NULL,
	[MESTO] [nvarchar](50) NULL,
	[PSC] [nvarchar](5) NULL,
	[IC] [nvarchar](8) NULL,
	[DIC] [nvarchar](10) NULL,
	[TELEFON] [nvarchar](15) NULL,
	[EMAIL] [nvarchar](100) NULL,
 CONSTRAINT [PK_ZAKAZNIK] PRIMARY KEY CLUSTERED 
(
	[ID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, OPTIMIZE_FOR_SEQUENTIAL_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
GO
ALTER TABLE [dbo].[FAKTURA] ADD  DEFAULT ((1)) FOR [FORMA_UHRADY]
GO
ALTER TABLE [dbo].[FAKTURA]  WITH CHECK ADD  CONSTRAINT [FK_ZAKAZNIK] FOREIGN KEY([ZAKAZNIK])
REFERENCES [dbo].[ZAKAZNIK] ([ID])
GO
ALTER TABLE [dbo].[FAKTURA] CHECK CONSTRAINT [FK_ZAKAZNIK]
GO
ALTER TABLE [dbo].[PLATBA]  WITH CHECK ADD  CONSTRAINT [FK_PLATBA_FAKTURA] FOREIGN KEY([FAKTURA])
REFERENCES [dbo].[FAKTURA] ([ID])
GO
ALTER TABLE [dbo].[PLATBA] CHECK CONSTRAINT [FK_PLATBA_FAKTURA]
GO
ALTER TABLE [dbo].[POLOZKA]  WITH CHECK ADD  CONSTRAINT [FK_PLOZKA_FAKTURA] FOREIGN KEY([FAKTURA])
REFERENCES [dbo].[FAKTURA] ([ID])
GO
ALTER TABLE [dbo].[POLOZKA] CHECK CONSTRAINT [FK_PLOZKA_FAKTURA]
GO

