USE [KinoPoisk]
GO
/****** Object:  Table [dbo].[Films]    Script Date: 02.10.2022 13:10:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[Films](
	[Id] [int] IDENTITY(1,1) NOT NULL,
	[NameFilm] [nvarchar](50) NOT NULL,
	[YearFilm] [date] NOT NULL,
	[GanreFilm] [nvarchar](200) NOT NULL,
	[Discript] [nvarchar](500) NULL,
	[DurationFilm] [varchar](10) NOT NULL,
 CONSTRAINT [PK_Films] PRIMARY KEY CLUSTERED 
(
	[Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[MovieSessions]    Script Date: 02.10.2022 13:10:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[MovieSessions](
	[Id] [int] IDENTITY(1,1) NOT NULL,
	[Id_Film] [int] NOT NULL,
	[Seats] [int] NOT NULL,
	[DatePremiers] [date] NOT NULL,
	[Price] [decimal](18, 2) NOT NULL,
 CONSTRAINT [PK_MovieSessions] PRIMARY KEY CLUSTERED 
(
	[Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[Statuses]    Script Date: 02.10.2022 13:10:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[Statuses](
	[Id] [int] IDENTITY(1,1) NOT NULL,
	[Name] [nvarchar](50) NOT NULL,
 CONSTRAINT [PK_Statuses] PRIMARY KEY CLUSTERED 
(
	[Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[Tickets]    Script Date: 02.10.2022 13:10:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[Tickets](
	[Id] [int] IDENTITY(1,1) NOT NULL,
	[Id_Film] [int] NOT NULL,
	[Id_Owner] [int] NOT NULL,
	[DatePurchase] [date] NOT NULL,
 CONSTRAINT [PK_Tickets] PRIMARY KEY CLUSTERED 
(
	[Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[Users]    Script Date: 02.10.2022 13:10:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[Users](
	[Id] [int] IDENTITY(1,1) NOT NULL,
	[FirstName] [nvarchar](100) NOT NULL,
	[LastName] [nvarchar](100) NOT NULL,
	[PhoneNumber] [varchar](15) NOT NULL,
	[UserPassword] [varchar](100) NOT NULL,
	[Status] [int] NULL,
 CONSTRAINT [PK_Users] PRIMARY KEY CLUSTERED 
(
	[Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
SET IDENTITY_INSERT [dbo].[Films] ON 

INSERT [dbo].[Films] ([Id], [NameFilm], [YearFilm], [GanreFilm], [Discript], [DurationFilm]) VALUES (2, N'Быстрее пули', CAST(N'2022-01-01' AS Date), N'Боевик', N'Наёмник под кодовым именем Божья Коровка отправляется на новую миссию: вместо заболевшего коллеги он должен сесть в скоростной поезд Токио — Киото, выкрасть чемоданчик и сойти на промежуточной станции. Но выполнение простого задания сильно осложняется, когда выясняется, что состав просто кишит всевозможными киллерами.', N'02:06')
INSERT [dbo].[Films] ([Id], [NameFilm], [YearFilm], [GanreFilm], [Discript], [DurationFilm]) VALUES (4, N'Тор', CAST(N'2011-01-01' AS Date), N'Фантастика', N'Эпическое приключение происходит как на нашей планете Земля, так и в королевстве богов Асгарде. В центре истории - Могучий Тор, сильный, но высокомерный воин, чьи безрассудные поступки возрождают древнюю войну в Асгарде. Тора отправляют в ссылку на Землю, лишают сил и заставляют жить среди обычных людей в качестве наказания...', N'01:50')
INSERT [dbo].[Films] ([Id], [NameFilm], [YearFilm], [GanreFilm], [Discript], [DurationFilm]) VALUES (8, N'Зеленая миля', CAST(N'1999-04-18' AS Date), N'Драма', N'Пол Эджкомб — начальник блока смертников в тюрьме «Холодная гора», каждый из узников которого однажды проходит «зеленую милю» по пути к месту казни. Пол повидал много заключённых и надзирателей за время работы. Однако гигант Джон Коффи, обвинённый в страшном преступлении, стал одним из самых необычных обитателей блока.', N'3:09')
SET IDENTITY_INSERT [dbo].[Films] OFF
GO
SET IDENTITY_INSERT [dbo].[MovieSessions] ON 

INSERT [dbo].[MovieSessions] ([Id], [Id_Film], [Seats], [DatePremiers], [Price]) VALUES (1, 4, 54, CAST(N'2022-10-15' AS Date), CAST(250.00 AS Decimal(18, 2)))
INSERT [dbo].[MovieSessions] ([Id], [Id_Film], [Seats], [DatePremiers], [Price]) VALUES (2, 2, 44, CAST(N'2022-10-14' AS Date), CAST(150.00 AS Decimal(18, 2)))
SET IDENTITY_INSERT [dbo].[MovieSessions] OFF
GO
SET IDENTITY_INSERT [dbo].[Statuses] ON 

INSERT [dbo].[Statuses] ([Id], [Name]) VALUES (1, N'Администратор')
INSERT [dbo].[Statuses] ([Id], [Name]) VALUES (2, N'Пользователь')
SET IDENTITY_INSERT [dbo].[Statuses] OFF
GO
SET IDENTITY_INSERT [dbo].[Tickets] ON 

INSERT [dbo].[Tickets] ([Id], [Id_Film], [Id_Owner], [DatePurchase]) VALUES (1, 2, 1, CAST(N'2022-10-02' AS Date))
INSERT [dbo].[Tickets] ([Id], [Id_Film], [Id_Owner], [DatePurchase]) VALUES (2, 4, 1, CAST(N'2022-10-02' AS Date))
SET IDENTITY_INSERT [dbo].[Tickets] OFF
GO
SET IDENTITY_INSERT [dbo].[Users] ON 

INSERT [dbo].[Users] ([Id], [FirstName], [LastName], [PhoneNumber], [UserPassword], [Status]) VALUES (1, N'Александр', N'Вальтер', N'88005553535', N'qwe123', 1)
INSERT [dbo].[Users] ([Id], [FirstName], [LastName], [PhoneNumber], [UserPassword], [Status]) VALUES (2, N'qwe', N'qwe', N'123123123', N'qwe', 2)
SET IDENTITY_INSERT [dbo].[Users] OFF
GO
ALTER TABLE [dbo].[MovieSessions]  WITH CHECK ADD  CONSTRAINT [FK_MovieSessions_Films] FOREIGN KEY([Id_Film])
REFERENCES [dbo].[Films] ([Id])
GO
ALTER TABLE [dbo].[MovieSessions] CHECK CONSTRAINT [FK_MovieSessions_Films]
GO
ALTER TABLE [dbo].[Tickets]  WITH CHECK ADD  CONSTRAINT [FK_Tickets_Films] FOREIGN KEY([Id_Film])
REFERENCES [dbo].[Films] ([Id])
GO
ALTER TABLE [dbo].[Tickets] CHECK CONSTRAINT [FK_Tickets_Films]
GO
ALTER TABLE [dbo].[Tickets]  WITH CHECK ADD  CONSTRAINT [FK_Tickets_Users] FOREIGN KEY([Id_Owner])
REFERENCES [dbo].[Users] ([Id])
GO
ALTER TABLE [dbo].[Tickets] CHECK CONSTRAINT [FK_Tickets_Users]
GO
ALTER TABLE [dbo].[Users]  WITH CHECK ADD  CONSTRAINT [FK_Users_Statuses] FOREIGN KEY([Status])
REFERENCES [dbo].[Statuses] ([Id])
GO
ALTER TABLE [dbo].[Users] CHECK CONSTRAINT [FK_Users_Statuses]
GO
