USE [VIGIL-Analytics]
GO


-- DROP TABLES

IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[vpos_exceptionrecipient]') AND type in (N'U'))
DROP TABLE [dbo].[vpos_exceptionrecipient]
GO

IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[vpos_exception]') AND type in (N'U'))
DROP TABLE [dbo].[vpos_exception]
GO

IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[vpos_alarm]') AND type in (N'U'))
DROP TABLE [dbo].[vpos_alarm]
GO

IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[vacounter]') AND type in (N'U'))
DROP TABLE [dbo].[vacounter]
GO

IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[va_pos]') AND type in (N'U'))
DROP TABLE [dbo].[va_pos]
GO

IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[va_faces]') AND type in (N'U'))
DROP TABLE [dbo].[va_faces]
GO

IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[va_alarms]') AND type in (N'U'))
DROP TABLE [dbo].[va_alarms]
GO

IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[users]') AND type in (N'U'))
DROP TABLE [dbo].[users]
GO

IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[usergroup]') AND type in (N'U'))
DROP TABLE [dbo].[usergroup]
GO

IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[table_version]') AND type in (N'U'))
DROP TABLE [dbo].[table_version]
GO

IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[posdata]') AND type in (N'U'))
DROP TABLE [dbo].[posdata]
GO

IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[pos_camera_mapping]') AND type in (N'U'))
DROP TABLE [dbo].[pos_camera_mapping]
GO

IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[perms]') AND type in (N'U'))
DROP TABLE [dbo].[perms]
GO

IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[groups]') AND type in (N'U'))
DROP TABLE [dbo].[groups]
GO

IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[grouppermission]') AND type in (N'U'))
DROP TABLE [dbo].[grouppermission]
GO

IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[DVR]') AND type in (N'U'))
DROP TABLE [dbo].[DVR]
GO

IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[audit_users]') AND type in (N'U'))
DROP TABLE [dbo].[audit_users]
GO

IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[audit_reports]') AND type in (N'U'))
DROP TABLE [dbo].[audit_reports]
GO

IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[audit_report_criterias]') AND type in (N'U'))
DROP TABLE [dbo].[audit_report_criterias]
GO

IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[audit_report_criteria_types]') AND type in (N'U'))
DROP TABLE [dbo].[audit_report_criteria_types]
GO

IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[audit_events]') AND type in (N'U'))
DROP TABLE [dbo].[audit_events]
GO

IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[audit_event_types]') AND type in (N'U'))
DROP TABLE [dbo].[audit_event_types]
GO

IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[audit_details_info_types]') AND type in (N'U'))
DROP TABLE [dbo].[audit_details_info_types]
GO

IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[audit_details_info]') AND type in (N'U'))
DROP TABLE [dbo].[audit_details_info]
GO

IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[audit_details]') AND type in (N'U'))
DROP TABLE [dbo].[audit_details]
GO

IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[audit_daily_user_summary]') AND type in (N'U'))
DROP TABLE [dbo].[audit_daily_user_summary]
GO

IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[alarmevents]') AND type in (N'U'))
DROP TABLE [dbo].[alarmevents]
GO


-- CREATE TABLES

SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[alarmevents](
	[idx] [bigint] IDENTITY(1,1) NOT NULL,
	[vcm_dvr_id] [int] NOT NULL,
	[pc_idx] [bigint] NOT NULL,
	[alarm_type] [int] NOT NULL,
	[alarm_guid] [nvarchar](40) NOT NULL,
	[alarm_input] [int] NOT NULL,
	[alarm_name] [nvarchar](50) NULL,
	[camera_numbers] [nvarchar](640) NULL,
	[start_time] [datetime] NOT NULL,
	[end_time] [datetime] NULL,
	[acknowledged] [bit] NOT NULL CONSTRAINT [DF_alarmevents_acknowledged]  DEFAULT ((0)),
	[custom_text] [text] NULL,
	[server_local_alarm] [bit] NOT NULL CONSTRAINT [DF_alarmevents_server_local_alarm]  DEFAULT ((0)),
	[vcm_insert_time] [datetime] NOT NULL DEFAULT GETDATE(),
 CONSTRAINT [PK_alarmevents] PRIMARY KEY CLUSTERED 
(
	[idx] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY],
 CONSTRAINT [uc_alarmevents_pc_idx_vcm_dvr_id] UNIQUE NONCLUSTERED 
(
	[pc_idx] ASC,
	[vcm_dvr_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] TEXTIMAGE_ON [PRIMARY]
GO

SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[audit_daily_user_summary](
	[idx] [bigint] IDENTITY(1,1) NOT NULL,
	[vcm_dvr_id] [int] NOT NULL,
	[pc_idx] [bigint] NOT NULL,
	[date] [datetime] NOT NULL,
	[user] [nvarchar](50) NOT NULL,
	[item] [nvarchar](30) NOT NULL,
	[value] [float] NOT NULL,
	[vcm_insert_time] [datetime] NOT NULL DEFAULT GETDATE(),
 CONSTRAINT [PK_audit_daily_user_summary] PRIMARY KEY CLUSTERED 
(
	[idx] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY],
 CONSTRAINT [uc_audit_daily_user_summary_pc_idx_vcm_dvr_id] UNIQUE NONCLUSTERED 
(
	[pc_idx] ASC,
	[vcm_dvr_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 ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[audit_details](
	[idx] [bigint] IDENTITY(1,1) NOT NULL,
	[vcm_dvr_id] [int] NOT NULL,
	[pc_idx] [int] NOT NULL,
	[event_id] [smallint] NOT NULL,
	[user_id] [smallint] NOT NULL,
	[event_time] [datetime] NOT NULL,
	[guid] [uniqueidentifier] NOT NULL,
	[vcm_insert_time] [datetime] NOT NULL DEFAULT GETDATE(),
 CONSTRAINT [PK_audit_details] PRIMARY KEY CLUSTERED 
(
	[idx] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY],
 CONSTRAINT [uc_audit_details_pc_idx_vcm_dvr_id] UNIQUE NONCLUSTERED 
(
	[pc_idx] ASC,
	[vcm_dvr_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 ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[audit_details_info](
	[idx] [bigint] IDENTITY(1,1) NOT NULL,
	[vcm_dvr_id] [int] NOT NULL,
	[pc_idx] [int] NOT NULL,
	[audit_details_id] [int] NOT NULL,
	[data] [nvarchar](64) NOT NULL,
	[data_type_id] [int] NULL,
	[vcm_insert_time] [datetime] NOT NULL DEFAULT GETDATE(),
 CONSTRAINT [PK_audit_details_info] PRIMARY KEY CLUSTERED 
(
	[idx] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY],
 CONSTRAINT [uc_audit_details_info_pc_idx_vcm_dvr_id] UNIQUE NONCLUSTERED 
(
	[pc_idx] ASC,
	[vcm_dvr_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 ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[audit_details_info_types](
	[idx] [bigint] IDENTITY(1,1) NOT NULL,
	[vcm_dvr_id] [int] NOT NULL,
	[pc_idx] [int] NOT NULL,
	[name] [nvarchar](30) NOT NULL,
	[vcm_insert_time] [datetime] NOT NULL DEFAULT GETDATE(),
 CONSTRAINT [PK_audit_details_info_types] PRIMARY KEY CLUSTERED 
(
	[idx] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY],
 CONSTRAINT [uc_audit_details_info_types_pc_idx_vcm_dvr_id] UNIQUE NONCLUSTERED 
(
	[pc_idx] ASC,
	[vcm_dvr_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 ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[audit_event_types](
	[idx] [bigint] IDENTITY(1,1) NOT NULL,
	[vcm_dvr_id] [int] NOT NULL,
	[pc_idx] [smallint] NOT NULL,
	[name] [nvarchar](30) NOT NULL,
	[active] [bit] NOT NULL,
	[vcm_insert_time] [datetime] NOT NULL DEFAULT GETDATE(),
 CONSTRAINT [PK_audit_event_types] PRIMARY KEY CLUSTERED 
(
	[idx] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY],
 CONSTRAINT [uc_audit_event_types_pc_idx_vcm_dvr_id] UNIQUE NONCLUSTERED 
(
	[pc_idx] ASC,
	[vcm_dvr_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 ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[audit_events](
	[idx] [bigint] IDENTITY(1,1) NOT NULL,
	[vcm_dvr_id] [int] NOT NULL,
	[pc_idx] [smallint] NOT NULL,
	[type_id] [smallint] NOT NULL,
	[name] [nvarchar](30) NOT NULL,
	[active] [bit] NOT NULL,
	[vcm_insert_time] [datetime] NOT NULL DEFAULT GETDATE(),
 CONSTRAINT [PK_audit_events] PRIMARY KEY CLUSTERED 
(
	[idx] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY],
 CONSTRAINT [uc_audit_events_pc_idx_vcm_dvr_id] UNIQUE NONCLUSTERED 
(
	[pc_idx] ASC,
	[vcm_dvr_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 ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[audit_report_criteria_types](
	[idx] [bigint] IDENTITY(1,1) NOT NULL,
	[vcm_dvr_id] [int] NOT NULL,
	[pc_idx] [tinyint] NOT NULL,
	[name] [nvarchar](30) NOT NULL,
	[tag] [nvarchar](64) NULL,
	[vcm_insert_time] [datetime] NOT NULL DEFAULT GETDATE(),
 CONSTRAINT [PK_audit_report_criteria_types] PRIMARY KEY CLUSTERED 
(
	[idx] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY],
 CONSTRAINT [uc_audit_report_criteria_types_pc_idx_vcm_dvr_id] UNIQUE NONCLUSTERED 
(
	[pc_idx] ASC,
	[vcm_dvr_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 ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[audit_report_criterias](
	[idx] [bigint] IDENTITY(1,1) NOT NULL,
	[vcm_dvr_id] [int] NOT NULL,
	[pc_idx] [smallint] NOT NULL,
	[report_id] [tinyint] NOT NULL,
	[user_id] [smallint] NULL,
	[group_name] [nvarchar](50) NULL,
	[type_id] [tinyint] NOT NULL,
	[val] [int] NOT NULL,
	[vcm_insert_time] [datetime] NOT NULL DEFAULT GETDATE(),
 CONSTRAINT [PK_audit_report_criterias] PRIMARY KEY CLUSTERED 
(
	[idx] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY],
 CONSTRAINT [uc_audit_report_criterias_pc_idx_vcm_dvr_id] UNIQUE NONCLUSTERED 
(
	[pc_idx] ASC,
	[vcm_dvr_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 ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[audit_reports](
	[idx] [bigint] IDENTITY(1,1) NOT NULL,
	[vcm_dvr_id] [int] NOT NULL,
	[pc_idx] [tinyint] NOT NULL,
	[name] [nvarchar](50) NOT NULL,
	[keyword] [nvarchar](30) NOT NULL,
	[summary] [bit] NOT NULL,
	[units] [nvarchar](10) NULL,
	[vcm_insert_time] [datetime] NOT NULL DEFAULT GETDATE(),
 CONSTRAINT [PK_audit_reports] PRIMARY KEY CLUSTERED 
(
	[idx] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY],
 CONSTRAINT [uc_audit_reports_pc_idx_vcm_dvr_id] UNIQUE NONCLUSTERED 
(
	[pc_idx] ASC,
	[vcm_dvr_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 ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[audit_users](
	[idx] [bigint] IDENTITY(1,1) NOT NULL,
	[vcm_dvr_id] [int] NOT NULL,
	[pc_idx] [smallint] NOT NULL,
	[name] [nvarchar](50) NOT NULL,
	[active] [bit] NOT NULL,
	[vcm_insert_time] [datetime] NOT NULL DEFAULT GETDATE(),
 CONSTRAINT [PK_audit_users] PRIMARY KEY CLUSTERED 
(
	[idx] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY],
 CONSTRAINT [uc_audit_users_pc_idx_vcm_dvr_id] UNIQUE NONCLUSTERED 
(
	[pc_idx] ASC,
	[vcm_dvr_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 ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[DVR](
	[idx] [int] NOT NULL,
	[fleet_name] [nvarchar](250) NOT NULL,
	[dvr_name] [nvarchar](250) NOT NULL,
	[ip_address] [nvarchar](250) NOT NULL,
	[port] [int] NOT NULL CONSTRAINT [DF_DVR_port]  DEFAULT ((22801)),
	[timezone_offset] [float] NOT NULL CONSTRAINT [DF_DVR_timezone_offset]  DEFAULT ((0)),
	[vigil_connect_alias] [nvarchar](30) NULL,
	[group_path] [nvarchar](512) NULL,
 CONSTRAINT [PK_DVR] PRIMARY KEY CLUSTERED 
(
	[idx] 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 ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[grouppermission](
	[vcm_dvr_id] [int] NOT NULL,
	[permission_id] [int] NOT NULL,
	[groupname] [nvarchar](50) NOT NULL,
	[vcm_insert_time] [datetime] NOT NULL DEFAULT GETDATE(),
 CONSTRAINT [uc_permission_id_groupname_vcm_dvr_id] UNIQUE NONCLUSTERED 
(
	[permission_id] ASC,
	[groupname] ASC,
	[vcm_dvr_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 ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[groups](
	[vcm_dvr_id] [int] NOT NULL,
	[groupname] [nvarchar](50) NOT NULL,
	[vcm_insert_time] [datetime] NOT NULL DEFAULT GETDATE(),
 CONSTRAINT [uc_groupname_vcm_dvr_id] UNIQUE NONCLUSTERED 
(
	[groupname] ASC,
	[vcm_dvr_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 ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[perms](
	[vcm_dvr_id] [int] NOT NULL,
	[permission_id] [int] NOT NULL,
	[permission_desc_id] [int] NOT NULL,
	[permission_sort_order] [int] NOT NULL,
	[vcm_insert_time] [datetime] NOT NULL DEFAULT GETDATE(),
 CONSTRAINT [uc_permission_id_vcm_dvr_id] UNIQUE NONCLUSTERED 
(
	[permission_id] ASC,
	[vcm_dvr_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 ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[pos_camera_mapping](
	[vcm_dvr_id] [int] NOT NULL,
	[terminal] [int] NOT NULL,
	[register] [int] NOT NULL,
	[camera] [int] NOT NULL,
	[vcm_insert_time] [datetime] NOT NULL DEFAULT GETDATE(),
	[preset] [int] NOT NULL DEFAULT (-1),
 CONSTRAINT [uc_pos_camera_mapping] UNIQUE NONCLUSTERED 
(
	[vcm_dvr_id] ASC,
	[terminal] ASC,
	[register] ASC,
	[camera] ASC,
	[preset] 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 ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[posdata](
	[idx] [bigint] IDENTITY(1,1) NOT NULL,
	[vcm_dvr_id] [int] NOT NULL,
	[pc_idx] [bigint] NOT NULL,
	[receipt_no] [nvarchar](20) NULL,
	[register_time] [datetime] NOT NULL,
	[server_time] [datetime] NOT NULL,
	[item] [nvarchar](50) NULL,
	[value_char] [nvarchar](20) NULL,
	[value_num] [money] NULL,
	[sequence_num] [int] NULL,
	[register_num] [int] NULL,
	[terminal_num] [int] NOT NULL,
	[void] [bit] NOT NULL,
	[nosale] [bit] NOT NULL,
	[quantity] [smallmoney] NULL,
	[cashier] [nvarchar](50) NULL,
	[action_code_num] [smallint] NULL,
	[parser_type] [smallint] NULL,
	[is_standardized] [bit] NULL CONSTRAINT [DF_posdata_is_standardized]  DEFAULT ((0)),
	[vcm_insert_time] [datetime] NOT NULL DEFAULT GETDATE(),
 CONSTRAINT [PK_posdata] PRIMARY KEY CLUSTERED 
(
	[idx] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY],
 CONSTRAINT [uc_posdata_pc_idx_vcm_dvr_id] UNIQUE NONCLUSTERED 
(
	[pc_idx] ASC,
	[vcm_dvr_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 ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[table_version](
	[entity] [nvarchar](50) NOT NULL,
	[version] [int] NOT NULL,
 CONSTRAINT [PK_table_version] PRIMARY KEY CLUSTERED 
(
	[entity] 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 ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[usergroup](
	[vcm_dvr_id] [int] NOT NULL,
	[username] [nvarchar](50) NULL,
	[groupname] [nvarchar](50) NULL,
	[vcm_insert_time] [datetime] NOT NULL DEFAULT GETDATE(),
 CONSTRAINT [uc_vcm_dvr_id_username_groupname] UNIQUE NONCLUSTERED 
(
	[vcm_dvr_id] ASC,
	[username] ASC,
	[groupname] 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 ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[users](
	[vcm_dvr_id] [int] NOT NULL,
	[account_username] [nvarchar](50) NOT NULL,
	[vcm_insert_time] [datetime] NOT NULL DEFAULT GETDATE(),
 CONSTRAINT [uc_account_username_vcm_dvr_id] UNIQUE NONCLUSTERED 
(
	[account_username] ASC,
	[vcm_dvr_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 ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[va_alarms](
	[idx] [bigint] IDENTITY(1,1) NOT NULL,
	[vcm_dvr_id] [int] NOT NULL,
	[pc_idx] [bigint] NOT NULL,
	[camera_number] [int] NOT NULL,
	[rule_id] [int] NOT NULL,
	[rule_type] [nvarchar](30) NOT NULL,
	[start_time] [datetime] NOT NULL,
	[end_time] [datetime] NOT NULL,
	[counter] [int] NOT NULL,
	[period] [int] NULL,
	[rule_name] [nvarchar](100) NULL,
	[description] [nvarchar](256) NULL,
	[vcm_insert_time] [datetime] NOT NULL DEFAULT GETDATE(),
	[details] [nvarchar](2000) NULL,
 CONSTRAINT [PK_va_alarms] PRIMARY KEY CLUSTERED 
(
	[idx] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY],
 CONSTRAINT [uc_va_alarms_pc_idx_vcm_dvr_id] UNIQUE NONCLUSTERED 
(
	[pc_idx] ASC,
	[vcm_dvr_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 ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[va_faces](
	[idx] [bigint] IDENTITY(1,1) NOT NULL,
	[vcm_dvr_id] [int] NOT NULL,
	[pc_idx] [bigint] NOT NULL,
	[camera_number] [int] NOT NULL,
	[rule_id] [int] NOT NULL,
	[rule_type] [int] NOT NULL,
	[start_time] [datetime] NOT NULL,
	[end_time] [datetime] NOT NULL,
	[gender] [int] NOT NULL,
	[age] [int] NOT NULL,
	[age_deviation] [int] NOT NULL,
	[happy] [int] NOT NULL,
	[sad] [int] NOT NULL,
	[surprised] [int] NOT NULL,
	[angry] [int] NOT NULL,
	[rule_name] [nvarchar](100) NULL,
	[vcm_insert_time] [datetime] NOT NULL DEFAULT GETDATE(),
 CONSTRAINT [PK_va_faces] PRIMARY KEY CLUSTERED 
(
	[idx] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY],
 CONSTRAINT [uc_va_faces_pc_idx_vcm_dvr_id] UNIQUE NONCLUSTERED 
(
	[pc_idx] ASC,
	[vcm_dvr_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 ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[va_pos](
	[idx] [bigint] IDENTITY(1,1) NOT NULL,
	[vcm_dvr_id] [int] NOT NULL,
	[pc_idx] [bigint] NOT NULL,
	[camera_number] [int] NOT NULL,
	[start_time] [datetime] NOT NULL,
	[end_time] [datetime] NOT NULL,
	[register_num] [int] NOT NULL,
	[rule_name] [nvarchar](100) NULL,
	[dwell] [int] NOT NULL CONSTRAINT [DF_va_pos_dwell]  DEFAULT ((0)),
	[vcm_insert_time] [datetime] NOT NULL DEFAULT GETDATE(),
 CONSTRAINT [PK_va_pos] PRIMARY KEY CLUSTERED 
(
	[idx] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY],
 CONSTRAINT [uc_va_pos_pc_idx_vcm_dvr_id] UNIQUE NONCLUSTERED 
(
	[pc_idx] ASC,
	[vcm_dvr_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 ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[vacounter](
	[idx] [bigint] IDENTITY(1,1) NOT NULL,
	[vcm_dvr_id] [int] NOT NULL,
	[pc_idx] [bigint] NOT NULL,
	[camera_number] [int] NULL,
	[rule_id] [int] NOT NULL,
	[rule_type] [nvarchar](30) NOT NULL,
	[start_time] [datetime] NOT NULL,
	[insert_time] [datetime] NOT NULL,
	[counter] [int] NULL,
	[rule_name] [nvarchar](100) NULL,
	[vcm_insert_time] [datetime] NOT NULL DEFAULT GETDATE(),
	[details] [nvarchar](2000) NULL,
 CONSTRAINT [PK_vacounter] PRIMARY KEY CLUSTERED 
(
	[idx] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY],
 CONSTRAINT [uc_vacounter_pc_idx_vcm_dvr_id] UNIQUE NONCLUSTERED 
(
	[pc_idx] ASC,
	[vcm_dvr_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 ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[vpos_alarm](
	[idx] [bigint] IDENTITY(1,1) NOT NULL,
	[vcm_dvr_id] [int] NOT NULL,
	[alarm_idx] [bigint] NOT NULL,
	[exception_idx] [int] NOT NULL,
	[acknowledged] [bit] NOT NULL,
	[pos_idx] [bigint] NOT NULL,
	[va_checked] [bit] NOT NULL,
	[alarm_flag_idx] [int] NOT NULL,
	[notes] [nvarchar](256) NOT NULL,
	[visible] [bit] NOT NULL,
	[vcm_insert_time] [datetime] NOT NULL DEFAULT GETDATE(),
 CONSTRAINT [PK_vpos_alarm] PRIMARY KEY CLUSTERED 
(
	[idx] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY],
 CONSTRAINT [uc_vpos_alarm_idx_vcm_dvr_id] UNIQUE NONCLUSTERED 
(
	[alarm_idx] ASC,
	[vcm_dvr_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 ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[vpos_exception](
	[idx] [bigint] IDENTITY(1,1) NOT NULL,
	[vcm_dvr_id] [int] NOT NULL,
	[exception_idx] [int] NOT NULL,
	[exception_guid] [nvarchar](50) NOT NULL,
	[exception_description] [nvarchar](50) NULL,
	[item] [nvarchar](50) NULL,
	[value_num] [money] NULL,
	[value_num_max] [money] NULL,
	[compare_type] [int] NULL,
	[quantity] [int] NULL,
	[quantity_compare_type] [int] NULL,
	[register_num] [int] NULL,
	[cashier] [nvarchar](50) NULL,
	[value_char] [nvarchar](20) NULL,
	[whole_dollar_amounts] [bit] NULL,
	[void_nosale_transactions] [bit] NULL,
	[start_hour] [int] NULL,
	[end_hour] [int] NULL,
	[alert_enabled] [bit] NOT NULL,
	[email_enabled] [bit] NOT NULL,
	[email_is_html] [bit] NOT NULL,
	[email_period] [int] NOT NULL,
	[email_period_type] [int] NOT NULL,
	[email_specific_day_enabled] [bit] NOT NULL,
	[email_specific_day] [int] NOT NULL,
	[email_specific_hour_enabled] [bit] NOT NULL,
	[email_specific_hour] [int] NOT NULL,
	[email_exception_threshold] [int] NOT NULL,
	[where_clause] [nvarchar](1000) NULL,
	[filter_conjunction_AND] [bit] NOT NULL,
	[show_exception_in_list] [bit] NULL,
	[va_enabled] [bit] NOT NULL,
	[va_camera] [int] NOT NULL,
	[va_rulename] [nvarchar](30) NOT NULL,
	[va_compare] [int] NOT NULL,
	[va_value] [int] NOT NULL,
	[item_case_sensitive] [bit] NOT NULL,
	[terminal_num] [int] NULL,
	[vcm_insert_time] [datetime] NOT NULL DEFAULT GETDATE(),
 CONSTRAINT [PK_vpos_exception] PRIMARY KEY CLUSTERED 
(
	[idx] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY],
 CONSTRAINT [uc_vpos_exception_idx_vcm_dvr_id] UNIQUE NONCLUSTERED 
(
	[exception_idx] ASC,
	[vcm_dvr_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 ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[vpos_exceptionrecipient](
	[vcm_dvr_id] [int] NOT NULL,
	[exception_idx] [int] NOT NULL,
	[email_address] [nvarchar](50) NOT NULL,
	[email_name] [nvarchar](50) NULL,
	[vcm_insert_time] [datetime] NOT NULL DEFAULT GETDATE(),
 CONSTRAINT [uc_vpos_exceptionrecipient_idx_email_address_vcm_dvr_id] UNIQUE NONCLUSTERED 
(
	[exception_idx] ASC,
	[email_address] ASC,
	[vcm_dvr_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


-- CREATE INDEXES

CREATE NONCLUSTERED INDEX [ix_alarmevents_pc_idx] ON [dbo].[alarmevents]
(
	[pc_idx] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
GO

CREATE NONCLUSTERED INDEX [ix_alarmevents_vcm_dvr_id] ON [dbo].[alarmevents]
(
	[vcm_dvr_id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
GO

CREATE NONCLUSTERED INDEX [ix_audit_daily_user_summary_pc_idx] ON [dbo].[audit_daily_user_summary]
(
	[pc_idx] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
GO

CREATE NONCLUSTERED INDEX [ix_audit_daily_user_summary_vcm_dvr_id] ON [dbo].[audit_daily_user_summary]
(
	[vcm_dvr_id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
GO

CREATE NONCLUSTERED INDEX [ix_audit_details_event_time] ON [dbo].[audit_details]
(
	[event_time] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
GO

CREATE NONCLUSTERED INDEX [ix_audit_details_pc_idx] ON [dbo].[audit_details]
(
	[pc_idx] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
GO

CREATE NONCLUSTERED INDEX [ix_audit_details_vcm_dvr_id] ON [dbo].[audit_details]
(
	[vcm_dvr_id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
GO

CREATE NONCLUSTERED INDEX [ix_audit_details_info_pc_idx] ON [dbo].[audit_details_info]
(
	[pc_idx] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
GO

CREATE NONCLUSTERED INDEX [ix_audit_details_info_vcm_dvr_id] ON [dbo].[audit_details_info]
(
	[vcm_dvr_id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
GO

CREATE NONCLUSTERED INDEX [ix_audit_details_info_types_vcm_dvr_id] ON [dbo].[audit_details_info_types]
(
	[vcm_dvr_id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
GO

CREATE NONCLUSTERED INDEX [ix_audit_event_types_vcm_dvr_id] ON [dbo].[audit_event_types]
(
	[vcm_dvr_id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
GO

CREATE NONCLUSTERED INDEX [ix_audit_events_vcm_dvr_id] ON [dbo].[audit_events]
(
	[vcm_dvr_id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
GO

CREATE NONCLUSTERED INDEX [ix_audit_report_criteria_types_vcm_dvr_id] ON [dbo].[audit_report_criteria_types]
(
	[vcm_dvr_id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
GO

CREATE NONCLUSTERED INDEX [ix_audit_report_criterias_vcm_dvr_id] ON [dbo].[audit_report_criterias]
(
	[vcm_dvr_id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
GO

CREATE NONCLUSTERED INDEX [ix_audit_reports_vcm_dvr_id] ON [dbo].[audit_reports]
(
	[vcm_dvr_id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
GO

CREATE NONCLUSTERED INDEX [ix_audit_users_vcm_dvr_id] ON [dbo].[audit_users]
(
	[vcm_dvr_id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
GO

CREATE NONCLUSTERED INDEX [ix_DVR_idx] ON [dbo].[DVR]
(
	[idx] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
GO

CREATE NONCLUSTERED INDEX [ix_grouppermission_vcm_dvr_id] ON [dbo].[grouppermission]
(
	[vcm_dvr_id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
GO

CREATE NONCLUSTERED INDEX [ix_groups_vcm_dvr_id] ON [dbo].[groups]
(
	[vcm_dvr_id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
GO

CREATE NONCLUSTERED INDEX [ix_perms_vcm_dvr_id] ON [dbo].[perms]
(
	[vcm_dvr_id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
GO

CREATE NONCLUSTERED INDEX [ix_pos_camera_mapping_vcm_dvr_id] ON [dbo].[pos_camera_mapping]
(
	[vcm_dvr_id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
GO

CREATE NONCLUSTERED INDEX [ix_posdata_pc_idx] ON [dbo].[posdata]
(
	[pc_idx] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
GO

CREATE NONCLUSTERED INDEX [ix_posdata_vcm_dvr_id] ON [dbo].[posdata]
(
	[vcm_dvr_id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
GO

CREATE NONCLUSTERED INDEX [ix_users_vcm_dvr_id] ON [dbo].[users]
(
	[vcm_dvr_id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
GO

CREATE NONCLUSTERED INDEX [ix_va_alarms_vcm_pc_idx] ON [dbo].[va_alarms]
(
	[pc_idx] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
GO

CREATE NONCLUSTERED INDEX [ix_va_alarms_vcm_start_time] ON [dbo].[va_alarms]
(
	[start_time] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
GO

CREATE NONCLUSTERED INDEX [ix_va_alarms_vcm_vcm_dvr_id] ON [dbo].[va_alarms]
(
	[vcm_dvr_id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
GO

CREATE NONCLUSTERED INDEX [ix_va_faces_vcm_pc_idx] ON [dbo].[va_faces]
(
	[pc_idx] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
GO

CREATE NONCLUSTERED INDEX [ix_va_faces_vcm_start_time] ON [dbo].[va_faces]
(
	[start_time] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
GO

CREATE NONCLUSTERED INDEX [ix_va_faces_vcm_vcm_dvr_id] ON [dbo].[va_faces]
(
	[vcm_dvr_id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
GO

CREATE NONCLUSTERED INDEX [idx_va_pos_start_time] ON [dbo].[va_pos]
(
	[start_time] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
GO

CREATE NONCLUSTERED INDEX [ix_va_pos_vcm_pc_idx] ON [dbo].[va_pos]
(
	[pc_idx] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
GO

CREATE NONCLUSTERED INDEX [ix_va_pos_vcm_vcm_dvr_id] ON [dbo].[va_pos]
(
	[vcm_dvr_id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
GO

CREATE NONCLUSTERED INDEX [ix_va_counter_vcm_pc_idx] ON [dbo].[vacounter]
(
	[pc_idx] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
GO

CREATE NONCLUSTERED INDEX [ix_va_counter_vcm_start_time] ON [dbo].[vacounter]
(
	[start_time] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
GO

CREATE NONCLUSTERED INDEX [ix_va_counter_vcm_vcm_dvr_id] ON [dbo].[vacounter]
(
	[vcm_dvr_id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
GO

CREATE NONCLUSTERED INDEX [ix_vpos_alarm_alarm_idx] ON [dbo].[vpos_alarm]
(
	[alarm_idx] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
GO

CREATE NONCLUSTERED INDEX [ix_vpos_alarm_vcm_dvr_id] ON [dbo].[vpos_alarm]
(
	[vcm_dvr_id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
GO

CREATE NONCLUSTERED INDEX [ix_vpos_exception_exception_idx] ON [dbo].[vpos_exception]
(
	[exception_idx] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
GO

CREATE NONCLUSTERED INDEX [ix_vpos_exception_vcm_dvr_id] ON [dbo].[vpos_exception]
(
	[vcm_dvr_id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
GO

CREATE NONCLUSTERED INDEX [ix_vpos_exceptionrecipient_vcm_dvr_id] ON [dbo].[vpos_exceptionrecipient]
(
	[vcm_dvr_id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
GO
