USE [callmaster] IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[ticket]') AND type in (N'U')) DROP TABLE [dbo].[ticket] IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[tag]') AND type in (N'U')) DROP TABLE [dbo].[tag] IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[schedule]') AND type in (N'U')) DROP TABLE [dbo].[schedule] IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[report]') AND type in (N'U')) DROP TABLE [dbo].[report] IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[web_user]') AND type in (N'U')) DROP TABLE [dbo].[web_user] IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[query_field]') AND type in (N'U')) DROP TABLE [dbo].[query_field] IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[profile]') AND type in (N'U')) DROP TABLE [dbo].[profile] IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[pinsetup]') AND type in (N'U')) DROP TABLE [dbo].[pinsetup] IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[phoneuserpbx]') AND type in (N'U')) DROP TABLE [dbo].[phoneuserpbx] IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[phone_number]') AND type in (N'U')) DROP TABLE [dbo].[phone_number] IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[ldap_log]') AND type in (N'U')) DROP TABLE [dbo].[ldap_log] IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[ldapconfig]') AND type in (N'U')) DROP TABLE [dbo].[ldapconfig] IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[holiday]') AND type in (N'U')) DROP TABLE [dbo].[holiday] IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[hlr]') AND type in (N'U')) DROP TABLE [dbo].[hlr] IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[cpx_authorization]') AND type in (N'U')) DROP TABLE [dbo].[cpx_authorization] IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[counter]') AND type in (N'U')) DROP TABLE [dbo].[counter] IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[client]') AND type in (N'U')) DROP TABLE [dbo].[client] IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[cdrmodifier]') AND type in (N'U')) DROP TABLE [dbo].[cdrmodifier] IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[calltransaction]') AND type in (N'U')) DROP TABLE [dbo].[calltransaction] IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[budget]') AND type in (N'U')) DROP TABLE [dbo].[budget] IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[authorization_consent]') AND type in (N'U')) DROP TABLE [dbo].[authorization_consent] IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[additional_cost]') AND type in (N'U')) DROP TABLE [dbo].[additional_cost] IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[account]') AND type in (N'U')) DROP TABLE [dbo].[account] IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[phone_user]') AND type in (N'U')) DROP TABLE [dbo].[phone_user] IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[trunk]') AND type in (N'U')) DROP TABLE [dbo].[trunk] IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[rate]') AND type in (N'U')) DROP TABLE [dbo].[rate] IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[zone]') AND type in (N'U')) DROP TABLE [dbo].[zone] IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[rate_page]') AND type in (N'U')) DROP TABLE [dbo].[rate_page] IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[pbx]') AND type in (N'U')) DROP TABLE [dbo].[pbx] IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[provider]') AND type in (N'U')) DROP TABLE [dbo].[provider] IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[organization]') AND type in (N'U')) DROP TABLE [dbo].[organization] IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[destination_group]') AND type in (N'U')) DROP TABLE [dbo].[destination_group] IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[cost_center]') AND type in (N'U')) DROP TABLE [dbo].[cost_center] IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[corcos]') AND type in (N'U')) DROP TABLE [dbo].[corcos] IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[area]') AND type in (N'U')) DROP TABLE [dbo].[area] IF NOT EXISTS( SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[account]') AND type IN (N'U')) BEGIN CREATE TABLE [dbo].[account] ( [id] [bigint] IDENTITY(1, 1) NOT NULL ,[uid] [varchar](255) NOT NULL ,[applied_date] [datetime2](6) NULL ,[expired_date] [datetime2](6) NULL ,[last_edit_by] [varchar](255) NULL ,[last_edit_time] [datetime2](6) NULL ,[code] [varchar](12) NOT NULL ,[description] [varchar](255) NULL ,[name] [varchar](100) NOT NULL ,[number] [varchar](4000) NOT NULL ,[counter_cost] [float] NULL ,[counter_duration] [int] NULL ,[counter_freq] [int] NULL ,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] ,CONSTRAINT [UKg0r31xiwjpn6bes07nsurpgh9] UNIQUE NONCLUSTERED ([uid] ASC) WITH ( PAD_INDEX = OFF ,STATISTICS_NORECOMPUTE = OFF ,IGNORE_DUP_KEY = OFF ,ALLOW_ROW_LOCKS = ON ,ALLOW_PAGE_LOCKS = ON ) ON [PRIMARY] ,CONSTRAINT [UKns3goek4kokjp7d9yl68uobml] UNIQUE NONCLUSTERED ([uid] ASC) WITH ( PAD_INDEX = OFF ,STATISTICS_NORECOMPUTE = OFF ,IGNORE_DUP_KEY = OFF ,ALLOW_ROW_LOCKS = ON ,ALLOW_PAGE_LOCKS = ON ) ON [PRIMARY] ) ON [PRIMARY] END IF NOT EXISTS( SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[additional_cost]') AND type IN (N'U')) BEGIN CREATE TABLE [dbo].[additional_cost] ( [id] [bigint] IDENTITY(1, 1) NOT NULL ,[uid] [varchar](255) NOT NULL ,[last_edit_by] [varchar](255) NULL ,[last_edit_time] [datetime2](6) NULL ,[continued] [int] NULL ,[cr_applied_date] [datetime2](6) NULL ,[cr_direction] [varchar](50) NULL ,[cr_expired_date] [datetime2](6) NULL ,[description] [varchar](255) NULL ,[percentage] [float] NOT NULL ,[percentage_baseon] [varchar](255) NULL ,[sequence] [varchar](255) NULL ,[target] [char](1) NULL ,[value] [float] NOT NULL ,[cr_account_uid] [varchar](255) NULL ,[cr_cost_center_uid] [varchar](255) NULL ,[cr_organization_uid] [varchar](255) NULL ,[cr_phone_user_uid] [varchar](255) NULL ,[cr_rate_page_uid] [varchar](255) NULL ,[cr_trunk_uid] [varchar](255) NULL ,[cr_zone_uid] [varchar](255) NULL ,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] ,CONSTRAINT [UKda1te60ega2mx55dcaqf2floe] UNIQUE NONCLUSTERED ([uid] ASC) WITH ( PAD_INDEX = OFF ,STATISTICS_NORECOMPUTE = OFF ,IGNORE_DUP_KEY = OFF ,ALLOW_ROW_LOCKS = ON ,ALLOW_PAGE_LOCKS = ON ) ON [PRIMARY] ,CONSTRAINT [UKrrqriq0740hbquewaq32l0d7o] UNIQUE NONCLUSTERED ([uid] ASC) WITH ( PAD_INDEX = OFF ,STATISTICS_NORECOMPUTE = OFF ,IGNORE_DUP_KEY = OFF ,ALLOW_ROW_LOCKS = ON ,ALLOW_PAGE_LOCKS = ON ) ON [PRIMARY] ) ON [PRIMARY] END IF NOT EXISTS( SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[area]') AND type IN (N'U')) BEGIN CREATE TABLE [dbo].[area] ( [id] [bigint] IDENTITY(1, 1) NOT NULL ,[uid] [varchar](255) NOT NULL ,[last_edit_by] [varchar](255) NULL ,[last_edit_time] [datetime2](6) NULL ,[code] [varchar](12) NOT NULL ,[latitude] [float] NULL ,[longitude] [float] NULL ,[name] [varchar](100) NOT NULL ,[provinsi] [varchar](255) NULL ,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] ,CONSTRAINT [UCAreaCode] UNIQUE NONCLUSTERED ([code] ASC) WITH ( PAD_INDEX = OFF ,STATISTICS_NORECOMPUTE = OFF ,IGNORE_DUP_KEY = OFF ,ALLOW_ROW_LOCKS = ON ,ALLOW_PAGE_LOCKS = ON ) ON [PRIMARY] ,CONSTRAINT [UKefagkhb6w9a5vmwxm8kjnp8ey] UNIQUE NONCLUSTERED ([uid] ASC) WITH ( PAD_INDEX = OFF ,STATISTICS_NORECOMPUTE = OFF ,IGNORE_DUP_KEY = OFF ,ALLOW_ROW_LOCKS = ON ,ALLOW_PAGE_LOCKS = ON ) ON [PRIMARY] ,CONSTRAINT [UKfhtwmbks1uty2y9fvejl1parb] UNIQUE NONCLUSTERED ([uid] ASC) WITH ( PAD_INDEX = OFF ,STATISTICS_NORECOMPUTE = OFF ,IGNORE_DUP_KEY = OFF ,ALLOW_ROW_LOCKS = ON ,ALLOW_PAGE_LOCKS = ON ) ON [PRIMARY] ) ON [PRIMARY] END IF NOT EXISTS( SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[authorization_consent]') AND type IN (N'U')) BEGIN CREATE TABLE [dbo].[authorization_consent] ( [principal_name] [varchar](255) NOT NULL ,[registered_client_id] [varchar](255) NOT NULL ,[authorities] [varchar](max) NULL ,PRIMARY KEY CLUSTERED ( [principal_name] ASC ,[registered_client_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] END IF NOT EXISTS( SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[budget]') AND type IN (N'U')) BEGIN CREATE TABLE [dbo].[budget] ( [id] [bigint] IDENTITY(1, 1) NOT NULL ,[accumulate] [bit] NULL ,[annual_cost] [int] NULL ,[max_auto_calculate] [varchar](255) NULL ,[max_cost] [varchar](255) NULL ,[max_dur] [varchar](255) NULL ,[max_freq] [varchar](255) NULL ,[temp_cost] [varchar](255) NULL ,[type] [char](1) NULL ,[user_type] [char](1) NULL ,[user_uid] [varchar](50) NULL ,[warn_cost_percentage] [varchar](255) NULL ,[warn_dur] [varchar](255) NULL ,[warn_freq] [varchar](255) NULL ,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] END IF NOT EXISTS( SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[calltransaction]') AND type IN (N'U')) BEGIN CREATE TABLE [dbo].[calltransaction] ( [id] [bigint] IDENTITY(1, 1) NOT NULL ,[cost] [float] NOT NULL ,[currency] [varchar](6) NULL ,[direction] [char](3) NULL ,[discount] [float] NOT NULL ,[duration] [int] NOT NULL ,[extension] [varchar](50) NULL ,[number] [varchar](50) NULL ,[phone_type] [char](1) NULL ,[pin] [varchar](100) NULL ,[raw_data] [varchar](8000) NULL ,[service] [float] NOT NULL ,[start_of_call] [datetime2](6) NULL ,[tag] [varchar](4000) NULL ,[tax] [float] NOT NULL ,[account_uid] [varchar](255) NULL ,[area_uid] [varchar](255) NULL ,[cost_center_uid] [varchar](255) NULL ,[destination_group_uid] [varchar](255) NULL ,[organization_uid] [varchar](255) NULL ,[phone_user_uid] [varchar](255) NULL ,[zone_uid] [varchar](255) NULL ,[rate_id] [bigint] NULL ,[trunk_uid] [varchar](255) NULL ,[pbx_uid] [varchar](255) NULL ,[caller_number] [varchar](50) NULL ,[end_of_call] [datetime2](6) NULL ,[ext_transfer_from] [varchar](50) NULL ,[ext_transfer_to] [varchar](50) NULL ,[owner_pin] [varchar](50) NULL ,[pulse] [varchar](50) NULL ,[start_of_answer] [datetime2](6) NULL ,[communication_type] [char](1) NULL ,[conference_type] [char](1) NULL ,[transfer_type] [char](1) NULL ,[access_number] [varchar](12) NULL ,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] END IF NOT EXISTS( SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[cdrmodifier]') AND type IN (N'U')) BEGIN CREATE TABLE [dbo].[cdrmodifier] ( [id] [bigint] IDENTITY(1, 1) NOT NULL ,[last_edit_by] [varchar](255) NULL ,[last_edit_time] [datetime2](6) NULL ,[action] [varchar](8000) NULL ,[continued] [bit] NOT NULL ,[criteria] [varchar](8000) NULL ,[description] [varchar](255) NOT NULL ,[match] [char](1) NULL ,[order_number] [varchar](255) NULL ,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] END IF NOT EXISTS( SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[client]') AND type IN (N'U')) BEGIN CREATE TABLE [dbo].[client] ( [id] [varchar](255) NOT NULL ,[authorization_grant_types] [varchar](max) NULL ,[client_authentication_methods] [varchar](max) NULL ,[client_id] [varchar](255) NULL ,[client_id_issued_at] [datetimeoffset](6) NULL ,[client_name] [varchar](255) NULL ,[client_secret] [varchar](255) NULL ,[client_secret_expires_at] [datetimeoffset](6) NULL ,[client_settings] [varchar](max) NULL ,[post_logout_redirect_uris] [varchar](max) NULL ,[redirect_uris] [varchar](max) NULL ,[scopes] [varchar](max) NULL ,[token_settings] [varchar](max) NULL ,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] TEXTIMAGE_ON [PRIMARY] END IF NOT EXISTS( SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[corcos]') AND type IN (N'U')) BEGIN CREATE TABLE [dbo].[corcos] ( [id] [bigint] IDENTITY(1, 1) NOT NULL ,[uid] [varchar](255) NOT NULL ,[command] [varchar](12) NOT NULL ,[description] [varchar](255) NULL ,[name] [varchar](100) NOT NULL ,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] ,CONSTRAINT [UK95r2819upm5y65lh6ulpngwv1] UNIQUE NONCLUSTERED ([uid] ASC) WITH ( PAD_INDEX = OFF ,STATISTICS_NORECOMPUTE = OFF ,IGNORE_DUP_KEY = OFF ,ALLOW_ROW_LOCKS = ON ,ALLOW_PAGE_LOCKS = ON ) ON [PRIMARY] ,CONSTRAINT [UKcwf2lhfa03ovdy8pcko9dwfkp] UNIQUE NONCLUSTERED ([uid] ASC) WITH ( PAD_INDEX = OFF ,STATISTICS_NORECOMPUTE = OFF ,IGNORE_DUP_KEY = OFF ,ALLOW_ROW_LOCKS = ON ,ALLOW_PAGE_LOCKS = ON ) ON [PRIMARY] ) ON [PRIMARY] END IF NOT EXISTS( SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[cost_center]') AND type IN (N'U')) BEGIN CREATE TABLE [dbo].[cost_center] ( [id] [bigint] IDENTITY(1, 1) NOT NULL ,[uid] [varchar](255) NOT NULL ,[applied_date] [datetime2](6) NULL ,[expired_date] [datetime2](6) NULL ,[last_edit_by] [varchar](255) NULL ,[last_edit_time] [datetime2](6) NULL ,[code] [varchar](12) NOT NULL ,[description] [varchar](255) NULL ,[email] [varchar](255) NULL ,[email_on_over_budget] [bit] NULL ,[name] [varchar](100) NOT NULL ,[structure] [varchar](255) NULL ,[parent_uid] [varchar](255) NULL ,[counter_cost] [float] NULL ,[counter_duration] [int] NULL ,[counter_freq] [int] NULL ,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] ,CONSTRAINT [UK90f9ok3nekbikmy8s0wajs234] UNIQUE NONCLUSTERED ([uid] ASC) WITH ( PAD_INDEX = OFF ,STATISTICS_NORECOMPUTE = OFF ,IGNORE_DUP_KEY = OFF ,ALLOW_ROW_LOCKS = ON ,ALLOW_PAGE_LOCKS = ON ) ON [PRIMARY] ,CONSTRAINT [UKg5ij4nw8lpl4sdhg0aoqtbrqt] UNIQUE NONCLUSTERED ([uid] ASC) WITH ( PAD_INDEX = OFF ,STATISTICS_NORECOMPUTE = OFF ,IGNORE_DUP_KEY = OFF ,ALLOW_ROW_LOCKS = ON ,ALLOW_PAGE_LOCKS = ON ) ON [PRIMARY] ) ON [PRIMARY] END IF NOT EXISTS( SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[counter]') AND type IN (N'U')) BEGIN CREATE TABLE [dbo].[counter] ( [id] [bigint] IDENTITY(1, 1) NOT NULL ,[account] [int] NULL ,[cost_center] [int] NULL ,[destination_group] [int] NULL ,[organization] [int] NULL ,[phone_user] [int] NULL ,[reset_direction] [char](1) NULL ,[reset_exec_date] [int] NULL ,[reset_exec_time] [datetime2](6) NULL ,[reset_period] [char](1) NULL ,[reset_target] [char](1) NULL ,[trunk] [int] NULL ,[reset_rate_page_uid] [varchar](255) NULL ,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] END IF NOT EXISTS( SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[cpx_authorization]') AND type IN (N'U')) BEGIN CREATE TABLE [dbo].[cpx_authorization] ( [id] [varchar](255) NOT NULL ,[access_token_expires_at] [datetimeoffset](6) NULL ,[access_token_issued_at] [datetimeoffset](6) NULL ,[access_token_metadata] [varchar](max) NULL ,[access_token_scopes] [varchar](max) NULL ,[access_token_type] [varchar](255) NULL ,[access_token_value] [varchar](max) NULL ,[attributes] [varchar](max) NULL ,[authorization_code_expires_at] [datetimeoffset](6) NULL ,[authorization_code_issued_at] [datetimeoffset](6) NULL ,[authorization_code_metadata] [varchar](255) NULL ,[authorization_code_value] [varchar](max) NULL ,[authorization_grant_type] [varchar](255) NULL ,[authorized_scopes] [varchar](1000) NULL ,[device_code_expires_at] [datetimeoffset](6) NULL ,[device_code_issued_at] [datetimeoffset](6) NULL ,[device_code_metadata] [varchar](max) NULL ,[device_code_value] [varchar](max) NULL ,[oidc_id_token_claims] [varchar](max) NULL ,[oidc_id_token_expires_at] [datetimeoffset](6) NULL ,[oidc_id_token_issued_at] [datetimeoffset](6) NULL ,[oidc_id_token_metadata] [varchar](max) NULL ,[oidc_id_token_value] [varchar](max) NULL ,[principal_name] [varchar](255) NULL ,[refresh_token_expires_at] [datetimeoffset](6) NULL ,[refresh_token_issued_at] [datetimeoffset](6) NULL ,[refresh_token_metadata] [varchar](max) NULL ,[refresh_token_value] [varchar](max) NULL ,[registered_client_id] [varchar](255) NULL ,[state] [varchar](500) NULL ,[user_code_expires_at] [datetimeoffset](6) NULL ,[user_code_issued_at] [datetimeoffset](6) NULL ,[user_code_metadata] [varchar](max) NULL ,[user_code_value] [varchar](max) NULL ,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] TEXTIMAGE_ON [PRIMARY] END IF NOT EXISTS( SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[destination_group]') AND type IN (N'U')) BEGIN CREATE TABLE [dbo].[destination_group] ( [id] [bigint] IDENTITY(1, 1) NOT NULL ,[uid] [varchar](255) NOT NULL ,[applied_date] [datetime2](6) NULL ,[expired_date] [datetime2](6) NULL ,[last_edit_by] [varchar](255) NULL ,[last_edit_time] [datetime2](6) NULL ,[code] [varchar](12) NOT NULL ,[description] [varchar](255) NULL ,[name] [varchar](100) NOT NULL ,[number] [varchar](4000) NOT NULL ,[type] [char](1) NULL ,[counter_cost] [float] NULL ,[counter_duration] [int] NULL ,[counter_freq] [int] NULL ,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] ,CONSTRAINT [UKqw7y6gcbp5nluu5vrtgxlgnln] UNIQUE NONCLUSTERED ([uid] ASC) WITH ( PAD_INDEX = OFF ,STATISTICS_NORECOMPUTE = OFF ,IGNORE_DUP_KEY = OFF ,ALLOW_ROW_LOCKS = ON ,ALLOW_PAGE_LOCKS = ON ) ON [PRIMARY] ,CONSTRAINT [UKsgrorq9e0fxpl3eod6gm761og] UNIQUE NONCLUSTERED ([uid] ASC) WITH ( PAD_INDEX = OFF ,STATISTICS_NORECOMPUTE = OFF ,IGNORE_DUP_KEY = OFF ,ALLOW_ROW_LOCKS = ON ,ALLOW_PAGE_LOCKS = ON ) ON [PRIMARY] ) ON [PRIMARY] END IF NOT EXISTS( SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[hlr]') AND type IN (N'U')) BEGIN CREATE TABLE [dbo].[hlr] ( [id] [bigint] IDENTITY(1, 1) NOT NULL ,[uid] [varchar](255) NOT NULL ,[applied_date] [datetime2](6) NULL ,[expired_date] [datetime2](6) NULL ,[last_edit_by] [varchar](255) NULL ,[last_edit_time] [datetime2](6) NULL ,[area] [varchar](50) NOT NULL ,[city_name] [varchar](100) NOT NULL ,[domain] [varchar](6) NOT NULL ,[holiday] [int] NULL ,[phone_type] [char](1) NULL ,[prefix] [varchar](12) NOT NULL ,[sub_domain] [varchar](6) NULL ,[provider_uid] [varchar](255) NULL ,[zone_uid] [varchar](255) NULL ,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] ,CONSTRAINT [UKe89x0s7xmqjdn22ip2s4f1sxw] UNIQUE NONCLUSTERED ([uid] ASC) WITH ( PAD_INDEX = OFF ,STATISTICS_NORECOMPUTE = OFF ,IGNORE_DUP_KEY = OFF ,ALLOW_ROW_LOCKS = ON ,ALLOW_PAGE_LOCKS = ON ) ON [PRIMARY] ,CONSTRAINT [UKocgju2or3vy6hnv283rp5eatp] UNIQUE NONCLUSTERED ([uid] ASC) WITH ( PAD_INDEX = OFF ,STATISTICS_NORECOMPUTE = OFF ,IGNORE_DUP_KEY = OFF ,ALLOW_ROW_LOCKS = ON ,ALLOW_PAGE_LOCKS = ON ) ON [PRIMARY] ) ON [PRIMARY] END IF NOT EXISTS( SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[holiday]') AND type IN (N'U')) BEGIN CREATE TABLE [dbo].[holiday] ( [id] [bigint] IDENTITY(1, 1) NOT NULL ,[last_edit_by] [varchar](255) NULL ,[last_edit_time] [datetime2](6) NULL ,[annual] [bit] NULL ,[description] [varchar](255) NOT NULL ,[holiday] [datetime2](6) NULL ,[page] [int] NULL ,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] END IF NOT EXISTS( SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[ldap_log]') AND type IN (N'U')) BEGIN CREATE TABLE [dbo].[ldap_log] ( [id] [bigint] IDENTITY(1, 1) NOT NULL ,[detail] [varchar](255) NULL ,[ldap_uid] [varchar](255) NULL ,[import_time] [datetime2](6) NULL ,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] END IF NOT EXISTS( SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[ldapconfig]') AND type IN (N'U')) BEGIN CREATE TABLE [dbo].[ldapconfig] ( [id] [bigint] IDENTITY(1, 1) NOT NULL ,[uid] [varchar](255) NOT NULL ,[attr_code] [varchar](100) NULL ,[attr_email] [varchar](100) NULL ,[attr_ext] [varchar](100) NULL ,[attr_name] [varchar](100) NULL ,[attr_org_code] [varchar](100) NULL ,[attr_org_name] [varchar](100) NULL ,[attr_pin] [varchar](100) NULL ,[auth_type] [char](1) NULL ,[basedn] [varchar](255) NOT NULL ,[conn_type] [char](1) NULL ,[filter_attr] [varchar](255) NULL ,[host] [varchar](100) NOT NULL ,[login_attr] [varchar](100) NULL ,[name] [varchar](100) NOT NULL ,[password] [varchar](255) NOT NULL ,[period] [char](1) NULL ,[period_time] [time](7) NULL ,[port] [varchar](3) NOT NULL ,[username] [varchar](255) NOT NULL ,[version] [varchar](1) NOT NULL ,[date_schedule] [int] NULL ,[datetime_start] [datetime2](6) NULL ,[day_schedule] [char](1) NULL ,[hour_schedule] [varchar](255) NULL ,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] ,CONSTRAINT [UK9br9e6d42cwsn4u08mpiij2e3] UNIQUE NONCLUSTERED ([uid] ASC) WITH ( PAD_INDEX = OFF ,STATISTICS_NORECOMPUTE = OFF ,IGNORE_DUP_KEY = OFF ,ALLOW_ROW_LOCKS = ON ,ALLOW_PAGE_LOCKS = ON ) ON [PRIMARY] ,CONSTRAINT [UKiu377pir58unid8w4g8nc0q1w] UNIQUE NONCLUSTERED ([uid] ASC) WITH ( PAD_INDEX = OFF ,STATISTICS_NORECOMPUTE = OFF ,IGNORE_DUP_KEY = OFF ,ALLOW_ROW_LOCKS = ON ,ALLOW_PAGE_LOCKS = ON ) ON [PRIMARY] ) ON [PRIMARY] END IF NOT EXISTS( SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[organization]') AND type IN(N'U')) BEGIN CREATE TABLE [dbo].[organization] ( [id] [bigint] IDENTITY(1, 1) NOT NULL ,[uid] [varchar](255) NOT NULL ,[applied_date] [datetime2](6) NULL ,[expired_date] [datetime2](6) NULL ,[last_edit_by] [varchar](255) NULL ,[last_edit_time] [datetime2](6) NULL ,[code] [varchar](12) NOT NULL ,[description] [varchar](255) NULL ,[email] [varchar](255) NULL ,[email_on_over_budget] [bit] NULL ,[name] [varchar](100) NOT NULL ,[structure] [varchar](255) NULL ,[parent_uid] [varchar](255) NULL ,[counter_cost] [float] NULL ,[counter_duration] [int] NULL ,[counter_freq] [int] NULL ,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] ,CONSTRAINT [UKgan7juxxybpr7dnc6rq9rgf1b] UNIQUE NONCLUSTERED ([uid] ASC) WITH ( PAD_INDEX = OFF ,STATISTICS_NORECOMPUTE = OFF ,IGNORE_DUP_KEY = OFF ,ALLOW_ROW_LOCKS = ON ,ALLOW_PAGE_LOCKS = ON ) ON [PRIMARY] ,CONSTRAINT [UKo582oodbehae8ilakotnoqyfa] UNIQUE NONCLUSTERED ([uid] ASC) WITH ( PAD_INDEX = OFF ,STATISTICS_NORECOMPUTE = OFF ,IGNORE_DUP_KEY = OFF ,ALLOW_ROW_LOCKS = ON ,ALLOW_PAGE_LOCKS = ON ) ON [PRIMARY] ) ON [PRIMARY] END IF NOT EXISTS( SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[pbx]') AND type IN (N'U')) BEGIN CREATE TABLE [dbo].[pbx] ( [id] [bigint] IDENTITY(1, 1) NOT NULL ,[uid] [varchar](255) NOT NULL ,[applied_date] [datetime2](6) NULL ,[expired_date] [datetime2](6) NULL ,[last_edit_by] [varchar](255) NULL ,[last_edit_time] [datetime2](6) NULL ,[code] [varchar](12) NOT NULL ,[location] [varchar](100) NULL ,[name] [varchar](50) NOT NULL ,[pbx_supporter] [int] NULL ,[area_uid] [varchar](255) NULL ,[provider_uid] [varchar](255) NULL ,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] ,CONSTRAINT [UK6v26ap07yhri3gjhrqms41ccc] UNIQUE NONCLUSTERED ([uid] ASC) WITH ( PAD_INDEX = OFF ,STATISTICS_NORECOMPUTE = OFF ,IGNORE_DUP_KEY = OFF ,ALLOW_ROW_LOCKS = ON ,ALLOW_PAGE_LOCKS = ON ) ON [PRIMARY] ,CONSTRAINT [UKbo6ykneanq0s86b9mrmi4ln32] UNIQUE NONCLUSTERED ([uid] ASC) WITH ( PAD_INDEX = OFF ,STATISTICS_NORECOMPUTE = OFF ,IGNORE_DUP_KEY = OFF ,ALLOW_ROW_LOCKS = ON ,ALLOW_PAGE_LOCKS = ON ) ON [PRIMARY] ) ON [PRIMARY] END IF NOT EXISTS( SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[phone_number]') AND type IN (N'U')) BEGIN CREATE TABLE [dbo].[phone_number] ( [id] [bigint] IDENTITY(1, 1) NOT NULL ,[uid] [varchar](255) NOT NULL ,[applied_date] [datetime2](6) NULL ,[expired_date] [datetime2](6) NULL ,[last_edit_by] [varchar](255) NULL ,[last_edit_time] [datetime2](6) NULL ,[code] [varchar](12) NOT NULL ,[description] [varchar](255) NULL ,[name] [varchar](100) NOT NULL ,[number] [varchar](50) NULL ,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] ,CONSTRAINT [UKo4xmgnniquxt3xxf0e8fwiwpa] UNIQUE NONCLUSTERED ([uid] ASC) WITH ( PAD_INDEX = OFF ,STATISTICS_NORECOMPUTE = OFF ,IGNORE_DUP_KEY = OFF ,ALLOW_ROW_LOCKS = ON ,ALLOW_PAGE_LOCKS = ON ) ON [PRIMARY] ,CONSTRAINT [UKoxj2wfoq9h0dqehod6myjwsmo] UNIQUE NONCLUSTERED ([uid] ASC) WITH ( PAD_INDEX = OFF ,STATISTICS_NORECOMPUTE = OFF ,IGNORE_DUP_KEY = OFF ,ALLOW_ROW_LOCKS = ON ,ALLOW_PAGE_LOCKS = ON ) ON [PRIMARY] ) ON [PRIMARY] END IF NOT EXISTS( SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[phone_user]') AND type IN (N'U')) BEGIN CREATE TABLE [dbo].[phone_user] ( [id] [bigint] IDENTITY(1, 1) NOT NULL ,[uid] [varchar](255) NOT NULL ,[applied_date] [datetime2](6) NULL ,[expired_date] [datetime2](6) NULL ,[last_edit_by] [varchar](255) NULL ,[last_edit_time] [datetime2](6) NULL ,[category] [varchar](50) NULL ,[code] [varchar](12) NOT NULL ,[counter_cost] [float] NULL ,[counter_duration] [int] NULL ,[counter_freq] [int] NULL ,[email] [varchar](255) NULL ,[name] [varchar](50) NOT NULL ,[phone_book_rights] [varchar](255) NULL ,[position] [varchar](50) NULL ,[report_order] [varchar](255) NULL ,[tags] [varchar](4000) NULL ,[whatsapp] [varchar](50) NULL ,[corcos_block_uid] [varchar](255) NULL ,[corcos_normal_uid] [varchar](255) NULL ,[corcos_reducing_uid] [varchar](255) NULL ,[cost_center_uid] [varchar](255) NULL ,[destination_group_uid] [varchar](255) NULL ,[organization_uid] [varchar](255) NULL ,[rate_page_uid] [varchar](255) NULL ,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] ,CONSTRAINT [UK2lwj0henswh1er2pgr99w45d0] UNIQUE NONCLUSTERED ([uid] ASC) WITH ( PAD_INDEX = OFF ,STATISTICS_NORECOMPUTE = OFF ,IGNORE_DUP_KEY = OFF ,ALLOW_ROW_LOCKS = ON ,ALLOW_PAGE_LOCKS = ON ) ON [PRIMARY] ,CONSTRAINT [UKedhq4soinr7r0kmj54a6495f8] UNIQUE NONCLUSTERED ([uid] ASC) WITH ( PAD_INDEX = OFF ,STATISTICS_NORECOMPUTE = OFF ,IGNORE_DUP_KEY = OFF ,ALLOW_ROW_LOCKS = ON ,ALLOW_PAGE_LOCKS = ON ) ON [PRIMARY] ) ON [PRIMARY] END IF NOT EXISTS( SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[phoneuserpbx]') AND type IN (N'U')) BEGIN CREATE TABLE [dbo].[phoneuserpbx] ( [id] [bigint] IDENTITY(1, 1) NOT NULL ,[uid] [varchar](255) NOT NULL ,[extension] [varchar](4000) NULL ,[pin] [varchar](100) NULL ,[pbx_uid] [varchar](255) NULL ,[phone_user_uid] [varchar](255) NULL ,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] ,CONSTRAINT [UK8e06t1jj2hlha6ro7qwnc8il5] UNIQUE NONCLUSTERED ([uid] ASC) WITH ( PAD_INDEX = OFF ,STATISTICS_NORECOMPUTE = OFF ,IGNORE_DUP_KEY = OFF ,ALLOW_ROW_LOCKS = ON ,ALLOW_PAGE_LOCKS = ON ) ON [PRIMARY] ,CONSTRAINT [UKj1chy8r2ksbqg4anj2prpwddm] UNIQUE NONCLUSTERED ([uid] ASC) WITH ( PAD_INDEX = OFF ,STATISTICS_NORECOMPUTE = OFF ,IGNORE_DUP_KEY = OFF ,ALLOW_ROW_LOCKS = ON ,ALLOW_PAGE_LOCKS = ON ) ON [PRIMARY] ) ON [PRIMARY] END IF NOT EXISTS( SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[pinsetup]') AND type IN (N'U')) BEGIN CREATE TABLE [dbo].[pinsetup] ( [id] [bigint] IDENTITY(1, 1) NOT NULL ,[exec_date] [int] NULL ,[exec_time] [time](7) NULL ,[flag] [char](1) NULL ,[period] [char](1) NULL ,[start_date] [datetime2](6) NULL ,[target] [char](1) NULL ,[user_target] [varchar](255) NULL ,[pbx_uid] [varchar](255) NULL ,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] END IF NOT EXISTS( SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[profile]') AND type IN (N'U')) BEGIN CREATE TABLE [dbo].[profile] ( [id] [bigint] IDENTITY(1, 1) NOT NULL ,[uid] [varchar](255) NOT NULL ,[name] [varchar](100) NOT NULL ,[rights] [varchar](100) NOT NULL ,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] ,CONSTRAINT [UCProfileName] UNIQUE NONCLUSTERED ([name] ASC) WITH ( PAD_INDEX = OFF ,STATISTICS_NORECOMPUTE = OFF ,IGNORE_DUP_KEY = OFF ,ALLOW_ROW_LOCKS = ON ,ALLOW_PAGE_LOCKS = ON ) ON [PRIMARY] ,CONSTRAINT [UK72ubcp4jyvymgs58u2qebwtl2] UNIQUE NONCLUSTERED ([uid] ASC) WITH ( PAD_INDEX = OFF ,STATISTICS_NORECOMPUTE = OFF ,IGNORE_DUP_KEY = OFF ,ALLOW_ROW_LOCKS = ON ,ALLOW_PAGE_LOCKS = ON ) ON [PRIMARY] ,CONSTRAINT [UKt3dqc5xqio84wwjq350e8cr6w] UNIQUE NONCLUSTERED ([uid] ASC) WITH ( PAD_INDEX = OFF ,STATISTICS_NORECOMPUTE = OFF ,IGNORE_DUP_KEY = OFF ,ALLOW_ROW_LOCKS = ON ,ALLOW_PAGE_LOCKS = ON ) ON [PRIMARY] ) ON [PRIMARY] END IF NOT EXISTS( SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[provider]') AND type IN (N'U')) BEGIN CREATE TABLE [dbo].[provider] ( [id] [bigint] IDENTITY(1, 1) NOT NULL ,[uid] [varchar](255) NOT NULL ,[last_edit_by] [varchar](255) NULL ,[last_edit_time] [datetime2](6) NULL ,[code] [varchar](12) NOT NULL ,[description] [varchar](255) NULL ,[name] [varchar](50) NOT NULL ,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] ,CONSTRAINT [UCProviderCode] UNIQUE NONCLUSTERED ([code] ASC) WITH ( PAD_INDEX = OFF ,STATISTICS_NORECOMPUTE = OFF ,IGNORE_DUP_KEY = OFF ,ALLOW_ROW_LOCKS = ON ,ALLOW_PAGE_LOCKS = ON ) ON [PRIMARY] ,CONSTRAINT [UKep9duujaqlym9k5xl93p0u8dw] UNIQUE NONCLUSTERED ([uid] ASC) WITH ( PAD_INDEX = OFF ,STATISTICS_NORECOMPUTE = OFF ,IGNORE_DUP_KEY = OFF ,ALLOW_ROW_LOCKS = ON ,ALLOW_PAGE_LOCKS = ON ) ON [PRIMARY] ,CONSTRAINT [UKml34l3gm0pj4oges8rovutexg] UNIQUE NONCLUSTERED ([uid] ASC) WITH ( PAD_INDEX = OFF ,STATISTICS_NORECOMPUTE = OFF ,IGNORE_DUP_KEY = OFF ,ALLOW_ROW_LOCKS = ON ,ALLOW_PAGE_LOCKS = ON ) ON [PRIMARY] ) ON [PRIMARY] END IF NOT EXISTS( SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[query_field]') AND type IN (N'U')) BEGIN CREATE TABLE [dbo].[query_field] ( [id] [bigint] IDENTITY(1, 1) NOT NULL ,[column_name] [varchar](50) NOT NULL ,[data_type] [varchar](50) NOT NULL ,[description] [varchar](255) NULL ,[join_table] [varchar](50) NULL ,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] END IF NOT EXISTS( SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[rate]') AND type IN (N'U')) BEGIN CREATE TABLE [dbo].[rate] ( [id] [bigint] IDENTITY(1, 1) NOT NULL ,[uid] [varchar](255) NOT NULL ,[applied_date] [datetime2](6) NULL ,[expired_date] [datetime2](6) NULL ,[last_edit_by] [varchar](255) NULL ,[last_edit_time] [datetime2](6) NULL ,[day_code] [varchar](8) NULL ,[tarif] [varchar](8000) NULL ,[provider_from_uid] [varchar](255) NOT NULL ,[provider_to_uid] [varchar](255) NULL ,[rate_page_uid] [varchar](255) NULL ,[zone_uid] [varchar](255) NOT NULL ,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] END IF NOT EXISTS( SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[rate_page]') AND type IN (N'U')) BEGIN CREATE TABLE [dbo].[rate_page] ( [id] [bigint] IDENTITY(1, 1) NOT NULL ,[uid] [varchar](255) NOT NULL ,[name] [varchar](100) NOT NULL ,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] ,CONSTRAINT [UCRatePageName] UNIQUE NONCLUSTERED ([name] ASC) WITH ( PAD_INDEX = OFF ,STATISTICS_NORECOMPUTE = OFF ,IGNORE_DUP_KEY = OFF ,ALLOW_ROW_LOCKS = ON ,ALLOW_PAGE_LOCKS = ON ) ON [PRIMARY] ,CONSTRAINT [UK2j1gxqkqosdp8u6w6yf8uvbdv] UNIQUE NONCLUSTERED ([uid] ASC) WITH ( PAD_INDEX = OFF ,STATISTICS_NORECOMPUTE = OFF ,IGNORE_DUP_KEY = OFF ,ALLOW_ROW_LOCKS = ON ,ALLOW_PAGE_LOCKS = ON ) ON [PRIMARY] ,CONSTRAINT [UKqtm1hasulqwx0nkrak8sdqqo0] UNIQUE NONCLUSTERED ([uid] ASC) WITH ( PAD_INDEX = OFF ,STATISTICS_NORECOMPUTE = OFF ,IGNORE_DUP_KEY = OFF ,ALLOW_ROW_LOCKS = ON ,ALLOW_PAGE_LOCKS = ON ) ON [PRIMARY] ) ON [PRIMARY] END IF NOT EXISTS( SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[report]') AND type IN (N'U')) BEGIN CREATE TABLE [dbo].[report] ( [id] [bigint] IDENTITY(1, 1) NOT NULL ,[uid] [varchar](255) NOT NULL ,[description] [varchar](255) NOT NULL ,[display_column] [varchar](255) NULL ,[filter_list] [varchar](255) NULL ,[lang] [char](1) NULL ,[sort_list] [varchar](255) NULL ,[template_name] [varchar](50) NOT NULL ,[title] [varchar](100) NOT NULL ,[rights] [varchar](255) NULL ,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] ,CONSTRAINT [UK1ie06vhy3begtwuuvrv0f71se] UNIQUE NONCLUSTERED ([uid] ASC) WITH ( PAD_INDEX = OFF ,STATISTICS_NORECOMPUTE = OFF ,IGNORE_DUP_KEY = OFF ,ALLOW_ROW_LOCKS = ON ,ALLOW_PAGE_LOCKS = ON ) ON [PRIMARY] ,CONSTRAINT [UKjctupmv448qg1txp89cn2tvnn] UNIQUE NONCLUSTERED ([uid] ASC) WITH ( PAD_INDEX = OFF ,STATISTICS_NORECOMPUTE = OFF ,IGNORE_DUP_KEY = OFF ,ALLOW_ROW_LOCKS = ON ,ALLOW_PAGE_LOCKS = ON ) ON [PRIMARY] ) ON [PRIMARY] END IF NOT EXISTS( SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[schedule]') AND type IN (N'U')) BEGIN CREATE TABLE [dbo].[schedule] ( [id] [bigint] IDENTITY(1, 1) NOT NULL ,[last_edit_by] [varchar](255) NULL ,[last_edit_time] [datetime2](6) NULL ,[date_schedule] [int] NULL ,[datetime_exec] [datetime2](6) NULL ,[datetime_start] [datetime2](6) NULL ,[day_schedule] [char](1) NULL ,[display_column] [varchar](255) NULL ,[email] [varchar](255) NOT NULL ,[file_format] [char](1) NULL ,[filter_label] [varchar](255) NULL ,[hour_schedule] [varchar](255) NULL ,[iterance] [char](1) NULL ,[report_filter] [varchar](255) NULL ,[sort_label] [varchar](255) NULL ,[title] [varchar](255) NULL ,[unit] [char](1) NULL ,[unit_count] [int] NULL ,[report_uid] [varchar](255) NULL ,[report_sort] [varchar](255) NULL ,[unit_flag] [bit] NULL ,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] END IF NOT EXISTS( SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[tag]') AND type IN (N'U')) BEGIN CREATE TABLE [dbo].[tag] ( [id] [bigint] IDENTITY(1, 1) NOT NULL ,[uid] [varchar](255) NOT NULL ,[applied_date] [datetime2](6) NULL ,[expired_date] [datetime2](6) NULL ,[description] [varchar](255) NULL ,[flag] [bit] NULL ,[name] [varchar](100) NOT NULL ,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] ,CONSTRAINT [UKeelbh6x3t14h473mxxnwugclj] UNIQUE NONCLUSTERED ([uid] ASC) WITH ( PAD_INDEX = OFF ,STATISTICS_NORECOMPUTE = OFF ,IGNORE_DUP_KEY = OFF ,ALLOW_ROW_LOCKS = ON ,ALLOW_PAGE_LOCKS = ON ) ON [PRIMARY] ,CONSTRAINT [UKjhsskogott48402sr2wjiudr] UNIQUE NONCLUSTERED ([uid] ASC) WITH ( PAD_INDEX = OFF ,STATISTICS_NORECOMPUTE = OFF ,IGNORE_DUP_KEY = OFF ,ALLOW_ROW_LOCKS = ON ,ALLOW_PAGE_LOCKS = ON ) ON [PRIMARY] ) ON [PRIMARY] END IF NOT EXISTS( SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[ticket]') AND type IN (N'U')) BEGIN CREATE TABLE [dbo].[ticket] ( [id] [bigint] IDENTITY(1, 1) NOT NULL ,[request_date] [datetime2](6) NULL ,[request_group] [varchar](4000) NULL ,[request_note] [varchar](255) NULL ,[request_type] [char](1) NULL ,[request_value] [float] NULL ,[result] [char](1) NULL ,[result_date] [datetime2](6) NULL ,[result_group] [varchar](4000) NULL ,[result_note] [varchar](255) NULL ,[result_value] [float] NULL ,[ticket] [varchar](255) NULL ,[type] [char](1) NULL ,[request_corcos_uid] [varchar](255) NULL ,[request_pbx_uid] [varchar](255) NULL ,[requester_uid] [varchar](255) NULL ,[result_by_uid] [varchar](255) NULL ,[tag_uid] [varchar](255) NULL ,[target_corcos_uid] [varchar](255) NULL ,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] END IF NOT EXISTS( SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[trunk]') AND type IN (N'U')) BEGIN CREATE TABLE [dbo].[trunk] ( [id] [bigint] IDENTITY(1, 1) NOT NULL ,[uid] [varchar](255) NOT NULL ,[applied_date] [datetime2](6) NULL ,[expired_date] [datetime2](6) NULL ,[last_edit_by] [varchar](255) NULL ,[last_edit_time] [datetime2](6) NULL ,[abonemen] [float] NULL ,[code] [varchar](12) NOT NULL ,[direction] [varchar](50) NULL ,[name] [varchar](100) NOT NULL ,[subscribed_no] [varchar](50) NULL ,[area_uid] [varchar](255) NULL ,[pbx_uid] [varchar](255) NOT NULL ,[provider_uid] [varchar](255) NULL ,[counter_cost] [float] NULL ,[counter_duration] [int] NULL ,[counter_freq] [int] NULL ,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] ,CONSTRAINT [UKkng4lg3dsslt3h4w701cli9m] UNIQUE NONCLUSTERED ([uid] ASC) WITH ( PAD_INDEX = OFF ,STATISTICS_NORECOMPUTE = OFF ,IGNORE_DUP_KEY = OFF ,ALLOW_ROW_LOCKS = ON ,ALLOW_PAGE_LOCKS = ON ) ON [PRIMARY] ,CONSTRAINT [UKrdxxkyi2hij8j1jgq43wcol2o] UNIQUE NONCLUSTERED ([uid] ASC) WITH ( PAD_INDEX = OFF ,STATISTICS_NORECOMPUTE = OFF ,IGNORE_DUP_KEY = OFF ,ALLOW_ROW_LOCKS = ON ,ALLOW_PAGE_LOCKS = ON ) ON [PRIMARY] ) ON [PRIMARY] END IF NOT EXISTS( SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[web_user]') AND type IN (N'U')) BEGIN CREATE TABLE [dbo].[web_user] ( [id] [bigint] IDENTITY(1, 1) NOT NULL ,[uid] [varchar](255) NOT NULL ,[last_edit_by] [varchar](255) NULL ,[last_edit_time] [datetime2](6) NULL ,[cost_center] [varchar](4000) NULL ,[destination_group] [varchar](4000) NULL ,[lang] [char](1) NULL ,[last_login] [datetime2](6) NULL ,[name] [varchar](255) NOT NULL ,[organization] [varchar](4000) NULL ,[password] [varchar](255) NOT NULL ,[phone_user_tag] [varchar](4000) NULL ,[rights] [varchar](255) NULL ,[rights_budget_pin] [varchar](4000) NULL ,[rights_group] [varchar](4000) NULL ,[username] [varchar](100) NOT NULL ,[ldap_uid] [varchar](255) NULL ,[phone_user_uid] [varchar](255) NULL ,[pinext_uid] [varchar](255) NULL ,[profile_uid] [varchar](255) NULL ,[last_active_datetime] [datetime2](6) NULL ,[rights_approval] [char](1) NULL ,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] ,CONSTRAINT [UCWebUserUsername] UNIQUE NONCLUSTERED ([username] ASC) WITH ( PAD_INDEX = OFF ,STATISTICS_NORECOMPUTE = OFF ,IGNORE_DUP_KEY = OFF ,ALLOW_ROW_LOCKS = ON ,ALLOW_PAGE_LOCKS = ON ) ON [PRIMARY] ,CONSTRAINT [UK3583rwkvhq1st255fk01dqidp] UNIQUE NONCLUSTERED ([uid] ASC) WITH ( PAD_INDEX = OFF ,STATISTICS_NORECOMPUTE = OFF ,IGNORE_DUP_KEY = OFF ,ALLOW_ROW_LOCKS = ON ,ALLOW_PAGE_LOCKS = ON ) ON [PRIMARY] ,CONSTRAINT [UKgqp8bs2nvynsedxok0pq7n24q] UNIQUE NONCLUSTERED ([uid] ASC) WITH ( PAD_INDEX = OFF ,STATISTICS_NORECOMPUTE = OFF ,IGNORE_DUP_KEY = OFF ,ALLOW_ROW_LOCKS = ON ,ALLOW_PAGE_LOCKS = ON ) ON [PRIMARY] ) ON [PRIMARY] END IF NOT EXISTS( SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[zone]') AND type IN (N'U')) BEGIN CREATE TABLE [dbo].[zone] ( [id] [bigint] IDENTITY(1, 1) NOT NULL ,[uid] [varchar](255) NOT NULL ,[code] [varchar](12) NOT NULL ,[description] [varchar](255) NULL ,[name] [varchar](100) NOT NULL ,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] ,CONSTRAINT [UCZoneCode] UNIQUE NONCLUSTERED ([code] ASC) WITH ( PAD_INDEX = OFF ,STATISTICS_NORECOMPUTE = OFF ,IGNORE_DUP_KEY = OFF ,ALLOW_ROW_LOCKS = ON ,ALLOW_PAGE_LOCKS = ON ) ON [PRIMARY] ,CONSTRAINT [UK7ma27s0bh5jx5y32dth08yvqg] UNIQUE NONCLUSTERED ([uid] ASC) WITH ( PAD_INDEX = OFF ,STATISTICS_NORECOMPUTE = OFF ,IGNORE_DUP_KEY = OFF ,ALLOW_ROW_LOCKS = ON ,ALLOW_PAGE_LOCKS = ON ) ON [PRIMARY] ,CONSTRAINT [UKotmclh5xwnrkho38m52d4eehx] UNIQUE NONCLUSTERED ([uid] ASC) WITH ( PAD_INDEX = OFF ,STATISTICS_NORECOMPUTE = OFF ,IGNORE_DUP_KEY = OFF ,ALLOW_ROW_LOCKS = ON ,ALLOW_PAGE_LOCKS = ON ) ON [PRIMARY] ) ON [PRIMARY] END IF EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[quartal4]')) DROP VIEW [dbo].[quartal4] IF EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[quartal3]')) DROP VIEW [dbo].[quartal3] IF EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[quartal2]')) DROP VIEW [dbo].[quartal2] IF EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[quartal1]')) DROP VIEW [dbo].[quartal1] IF NOT EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[quartal1]')) EXEC dbo.sp_executesql @statement = N' CREATE VIEW [dbo].[quartal1] AS SELECT TOP 100 PERCENT o.name ,(b.annual_cost / 12) * 3 AS budget_1 ,CASE WHEN month(getdate()) BETWEEN 1 AND 3 THEN( SELECT isnull(sum(cost), 0) FROM calltransaction WHERE start_of_call BETWEEN DATEADD(yy, DATEDIFF(yy, 0, GETDATE()), 0) AND dateadd(mm, - 9, DATEADD(yy, DATEDIFF(yy, 0, GETDATE()) + 1, - 1)) AND organization_uid = o.uid) ELSE 0 END AS actual_1 ,(b.annual_cost / 12) * 3 - CASE WHEN month(getdate()) BETWEEN 1 AND 3 THEN ( SELECT isnull(sum(cost), 0) FROM calltransaction WHERE start_of_call BETWEEN DATEADD(yy, DATEDIFF(yy, 0, GETDATE()), 0) AND dateadd(mm, - 9, DATEADD(yy, DATEDIFF(yy, 0, GETDATE()) + 1, - 1)) AND organization_uid = o.uid ) ELSE 0 END AS variance_1 FROM budget b LEFT JOIN organization o ON o.uid = b.user_uid LEFT JOIN calltransaction c ON o.uid = c.organization_uid WHERE b.user_type = 1 AND o.counter_cost > 0 AND c.start_of_call BETWEEN DATEADD(yy, DATEDIFF(yy, 0, GETDATE()), 0) AND dateadd(mm, - 9, DATEADD(yy, DATEDIFF(yy, 0, GETDATE()) + 1, - 1)) GROUP BY o.name ,o.counter_cost ,b.annual_cost ,o.uid ORDER BY b.annual_cost DESC ' IF NOT EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[quartal2]')) EXEC dbo.sp_executesql @statement = N' CREATE VIEW [dbo].[quartal2] AS SELECT TOP 100 PERCENT o.name ,(b.annual_cost / 12) * 3 AS budget_1 ,CASE WHEN month(getdate()) BETWEEN 4 AND 6 THEN( SELECT isnull(sum(cost), 0) FROM calltransaction WHERE start_of_call BETWEEN dateadd(mm, 3, DATEADD(yy, DATEDIFF(yy, 0, GETDATE()), 0)) AND dateadd(mm, - 6, DATEADD(yy, DATEDIFF(yy, 0, GETDATE()) + 1, - 1)) AND organization_uid = o.uid) ELSE 0 END AS actual_1 ,(b.annual_cost / 12) * 3 - CASE WHEN month(getdate()) BETWEEN 4 AND 6 THEN ( SELECT isnull(sum(cost), 0) FROM calltransaction WHERE start_of_call BETWEEN dateadd(mm, 3, DATEADD(yy, DATEDIFF(yy, 0, GETDATE()), 0)) AND dateadd(mm, - 6, DATEADD(yy, DATEDIFF(yy, 0, GETDATE()) + 1, - 1)) AND organization_uid = o.uid ) ELSE 0 END AS variance_1 FROM budget b LEFT JOIN organization o ON o.uid = b.user_uid LEFT JOIN calltransaction c ON o.uid = c.organization_uid WHERE b.user_type = 1 AND o.counter_cost > 0 AND c.start_of_call BETWEEN dateadd(mm, 3, DATEADD(yy, DATEDIFF(yy, 0, GETDATE()), 0)) AND dateadd(mm, - 6, DATEADD(yy, DATEDIFF(yy, 0, GETDATE()) + 1, - 1)) GROUP BY o.name ,o.counter_cost ,b.annual_cost ,o.uid ORDER BY b.annual_cost DESC ' IF NOT EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[quartal3]')) EXEC dbo.sp_executesql @statement = N' CREATE VIEW [dbo].[quartal3] AS SELECT TOP 100 PERCENT o.name ,(b.annual_cost / 12) * 3 AS budget_1 ,CASE WHEN month(getdate()) BETWEEN 7 AND 9 THEN( SELECT isnull(sum(cost), 0) FROM calltransaction WHERE start_of_call BETWEEN dateadd(mm, 6, DATEADD(yy, DATEDIFF(yy, 0, GETDATE()), 0)) AND dateadd(mm, - 3, DATEADD(yy, DATEDIFF(yy, 0, GETDATE()) + 1, - 1)) AND organization_uid = o.uid) ELSE 0 END AS actual_1 ,(b.annual_cost / 12) * 3 - CASE WHEN month(getdate()) BETWEEN 7 AND 9 THEN ( SELECT isnull(sum(cost), 0) FROM calltransaction WHERE start_of_call BETWEEN dateadd(mm, 6, DATEADD(yy, DATEDIFF(yy, 0, GETDATE()), 0)) AND dateadd(mm, - 3, DATEADD(yy, DATEDIFF(yy, 0, GETDATE()) + 1, - 1)) AND organization_uid = o.uid ) ELSE 0 END AS variance_1 FROM budget b LEFT JOIN organization o ON o.uid = b.user_uid LEFT JOIN calltransaction c ON o.uid = c.organization_uid WHERE b.user_type = 1 AND o.counter_cost > 0 AND c.start_of_call BETWEEN dateadd(mm, 6, DATEADD(yy, DATEDIFF(yy, 0, GETDATE()), 0)) AND dateadd(mm, - 3, DATEADD(yy, DATEDIFF(yy, 0, GETDATE()) + 1, - 1)) GROUP BY o.name ,o.counter_cost ,b.annual_cost ,o.uid ORDER BY b.annual_cost DESC ' IF NOT EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[quartal4]')) EXEC dbo.sp_executesql @statement = N' CREATE VIEW [dbo].[quartal4] AS SELECT TOP 100 PERCENT o.name ,(b.annual_cost / 12) * 3 AS budget_1 ,CASE WHEN month(getdate()) BETWEEN 10 AND 12 THEN( SELECT isnull(sum(cost), 0) FROM calltransaction WHERE start_of_call BETWEEN dateadd(mm, 9, DATEADD(yy, DATEDIFF(yy, 0, GETDATE()), 0)) AND DATEADD(yy, DATEDIFF(yy, 0, GETDATE()) + 1, - 1) AND organization_uid = o.uid) ELSE 0 END AS actual_1 ,(b.annual_cost / 12) * 3 - CASE WHEN month(getdate()) BETWEEN 10 AND 12 THEN ( SELECT isnull(sum(cost), 0) FROM calltransaction WHERE start_of_call BETWEEN dateadd(mm, 9, DATEADD(yy, DATEDIFF(yy, 0, GETDATE()), 0)) AND DATEADD(yy, DATEDIFF(yy, 0, GETDATE()) + 1, - 1) AND organization_uid = o.uid ) ELSE 0 END AS variance_1 FROM budget b LEFT JOIN organization o ON o.uid = b.user_uid LEFT JOIN calltransaction c ON o.uid = c.organization_uid WHERE b.user_type = 1 AND o.counter_cost > 0 AND c.start_of_call BETWEEN dateadd(mm, 9, DATEADD(yy, DATEDIFF(yy, 0, GETDATE()), 0)) AND DATEADD(yy, DATEDIFF(yy, 0, GETDATE()) + 1, - 1) GROUP BY o.name ,o.counter_cost ,b.annual_cost ,o.uid ORDER BY b.annual_cost DESC ' IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[reset_counter]') AND type in (N'P', N'PC')) DROP PROCEDURE [dbo].[reset_counter] IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[reset_counter]') AND type in (N'FN', N'IF', N'TF', N'FS', N'FT')) BEGIN EXECUTE dbo.sp_executesql @statement = N' CREATE PROCEDURE [dbo].[reset_counter] AS BEGIN BEGIN UPDATE phone_user SET counter_cost = 0; UPDATE organization SET counter_cost = 0; UPDATE cost_center SET counter_cost = 0; UPDATE budget SET temp_cost = ''0;0;0;0;0;0;0;0;0;0;0;0'' END; END; ' END CREATE UNIQUE NONCLUSTERED INDEX [UCHolidayDate] ON [dbo].[holiday]( [holiday] ASC) WHERE ([holiday] IS NOT NULL) WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, IGNORE_DUP_KEY = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY] CREATE UNIQUE NONCLUSTERED INDEX [UCHolidayDatePage] ON [dbo].[holiday]( [holiday] ASC, [page] ASC) WHERE ([holiday] IS NOT NULL AND [page] IS NOT NULL) WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, IGNORE_DUP_KEY = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY] CREATE UNIQUE NONCLUSTERED INDEX [UCTicketNumber] ON [dbo].[ticket]( [ticket] ASC) WHERE ([ticket] IS NOT NULL) WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, IGNORE_DUP_KEY = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY] ALTER TABLE [dbo].[additional_cost] WITH CHECK ADD CONSTRAINT [FKAdditionalAccount] FOREIGN KEY([cr_account_uid]) REFERENCES [dbo].[account] ([uid]) ALTER TABLE [dbo].[additional_cost] CHECK CONSTRAINT [FKAdditionalAccount] ALTER TABLE [dbo].[additional_cost] WITH CHECK ADD CONSTRAINT [FKAdditionalCostCenter] FOREIGN KEY([cr_cost_center_uid]) REFERENCES [dbo].[cost_center] ([uid]) ALTER TABLE [dbo].[additional_cost] CHECK CONSTRAINT [FKAdditionalCostCenter] ALTER TABLE [dbo].[additional_cost] WITH CHECK ADD CONSTRAINT [FKAdditionalCostRatePage] FOREIGN KEY([cr_rate_page_uid]) REFERENCES [dbo].[rate_page] ([uid]) ALTER TABLE [dbo].[additional_cost] CHECK CONSTRAINT [FKAdditionalCostRatePage] ALTER TABLE [dbo].[additional_cost] WITH CHECK ADD CONSTRAINT [FKAdditionalCostZone] FOREIGN KEY([cr_zone_uid]) REFERENCES [dbo].[zone] ([uid]) ALTER TABLE [dbo].[additional_cost] CHECK CONSTRAINT [FKAdditionalCostZone] ALTER TABLE [dbo].[additional_cost] WITH CHECK ADD CONSTRAINT [FKAdditionalOrganization] FOREIGN KEY([cr_organization_uid]) REFERENCES [dbo].[organization] ([uid]) ALTER TABLE [dbo].[additional_cost] CHECK CONSTRAINT [FKAdditionalOrganization] ALTER TABLE [dbo].[additional_cost] WITH CHECK ADD CONSTRAINT [FKAdditionalPhoneUser] FOREIGN KEY([cr_phone_user_uid]) REFERENCES [dbo].[phone_user] ([uid]) ALTER TABLE [dbo].[additional_cost] CHECK CONSTRAINT [FKAdditionalPhoneUser] ALTER TABLE [dbo].[additional_cost] WITH CHECK ADD CONSTRAINT [FKAdditionalTrunk] FOREIGN KEY([cr_trunk_uid]) REFERENCES [dbo].[trunk] ([uid]) ALTER TABLE [dbo].[additional_cost] CHECK CONSTRAINT [FKAdditionalTrunk] ALTER TABLE [dbo].[calltransaction] WITH CHECK ADD CONSTRAINT [FKTransactionAccount] FOREIGN KEY([account_uid]) REFERENCES [dbo].[account] ([uid]) ALTER TABLE [dbo].[calltransaction] CHECK CONSTRAINT [FKTransactionAccount] ALTER TABLE [dbo].[calltransaction] WITH CHECK ADD CONSTRAINT [FKTransactionArea] FOREIGN KEY([area_uid]) REFERENCES [dbo].[area] ([uid]) ALTER TABLE [dbo].[calltransaction] CHECK CONSTRAINT [FKTransactionArea] ALTER TABLE [dbo].[calltransaction] WITH CHECK ADD CONSTRAINT [FKTransactionCostCenter] FOREIGN KEY([cost_center_uid]) REFERENCES [dbo].[cost_center] ([uid]) ALTER TABLE [dbo].[calltransaction] CHECK CONSTRAINT [FKTransactionCostCenter] ALTER TABLE [dbo].[calltransaction] WITH CHECK ADD CONSTRAINT [FKTransactionDestinationGroup] FOREIGN KEY([destination_group_uid]) REFERENCES [dbo].[destination_group] ([uid]) ALTER TABLE [dbo].[calltransaction] CHECK CONSTRAINT [FKTransactionDestinationGroup] ALTER TABLE [dbo].[calltransaction] WITH CHECK ADD CONSTRAINT [FKTransactionOrganization] FOREIGN KEY([organization_uid]) REFERENCES [dbo].[organization] ([uid]) ALTER TABLE [dbo].[calltransaction] CHECK CONSTRAINT [FKTransactionOrganization] ALTER TABLE [dbo].[calltransaction] WITH CHECK ADD CONSTRAINT [FKTransactionPbx] FOREIGN KEY([pbx_uid]) REFERENCES [dbo].[pbx] ([uid]) ALTER TABLE [dbo].[calltransaction] CHECK CONSTRAINT [FKTransactionPbx] ALTER TABLE [dbo].[calltransaction] WITH CHECK ADD CONSTRAINT [FKTransactionPhoneUser] FOREIGN KEY([phone_user_uid]) REFERENCES [dbo].[phone_user] ([uid]) ALTER TABLE [dbo].[calltransaction] CHECK CONSTRAINT [FKTransactionPhoneUser] ALTER TABLE [dbo].[calltransaction] WITH CHECK ADD CONSTRAINT [FKTransactionRate] FOREIGN KEY([rate_id]) REFERENCES [dbo].[rate] ([id]) ALTER TABLE [dbo].[calltransaction] CHECK CONSTRAINT [FKTransactionRate] ALTER TABLE [dbo].[calltransaction] WITH CHECK ADD CONSTRAINT [FKTransactionTrunk] FOREIGN KEY([trunk_uid]) REFERENCES [dbo].[trunk] ([uid]) ALTER TABLE [dbo].[calltransaction] CHECK CONSTRAINT [FKTransactionTrunk] ALTER TABLE [dbo].[calltransaction] WITH CHECK ADD CONSTRAINT [FKTransactionZone] FOREIGN KEY([zone_uid]) REFERENCES [dbo].[zone] ([uid]) ALTER TABLE [dbo].[calltransaction] CHECK CONSTRAINT [FKTransactionZone] ALTER TABLE [dbo].[cost_center] WITH CHECK ADD CONSTRAINT [FKCostCenterParent] FOREIGN KEY([parent_uid]) REFERENCES [dbo].[cost_center] ([uid]) ALTER TABLE [dbo].[cost_center] CHECK CONSTRAINT [FKCostCenterParent] ALTER TABLE [dbo].[counter] WITH CHECK ADD CONSTRAINT [FKCounterRatePage] FOREIGN KEY([reset_rate_page_uid]) REFERENCES [dbo].[rate_page] ([uid]) ALTER TABLE [dbo].[counter] CHECK CONSTRAINT [FKCounterRatePage] ALTER TABLE [dbo].[hlr] WITH CHECK ADD CONSTRAINT [FKHlrProvider] FOREIGN KEY([provider_uid]) REFERENCES [dbo].[provider] ([uid]) ALTER TABLE [dbo].[hlr] CHECK CONSTRAINT [FKHlrProvider] ALTER TABLE [dbo].[hlr] WITH CHECK ADD CONSTRAINT [FKHlrZone] FOREIGN KEY([zone_uid]) REFERENCES [dbo].[zone] ([uid]) ALTER TABLE [dbo].[hlr] CHECK CONSTRAINT [FKHlrZone] ALTER TABLE [dbo].[ldap_log] WITH CHECK ADD CONSTRAINT [FKLapConfigLdapLog] FOREIGN KEY([ldap_uid]) REFERENCES [dbo].[ldapconfig] ([uid]) ALTER TABLE [dbo].[ldap_log] CHECK CONSTRAINT [FKLapConfigLdapLog] ALTER TABLE [dbo].[organization] WITH CHECK ADD CONSTRAINT [FKOrganizationParent] FOREIGN KEY([parent_uid]) REFERENCES [dbo].[organization] ([uid]) ALTER TABLE [dbo].[organization] CHECK CONSTRAINT [FKOrganizationParent] ALTER TABLE [dbo].[pbx] WITH CHECK ADD CONSTRAINT [FKPbxArea] FOREIGN KEY([area_uid]) REFERENCES [dbo].[area] ([uid]) ALTER TABLE [dbo].[pbx] CHECK CONSTRAINT [FKPbxArea] ALTER TABLE [dbo].[pbx] WITH CHECK ADD CONSTRAINT [FKPbxProvider] FOREIGN KEY([provider_uid]) REFERENCES [dbo].[provider] ([uid]) ALTER TABLE [dbo].[pbx] CHECK CONSTRAINT [FKPbxProvider] ALTER TABLE [dbo].[phone_user] WITH CHECK ADD CONSTRAINT [FKPhoneUserCorcosBlock] FOREIGN KEY([corcos_block_uid]) REFERENCES [dbo].[corcos] ([uid]) ALTER TABLE [dbo].[phone_user] CHECK CONSTRAINT [FKPhoneUserCorcosBlock] ALTER TABLE [dbo].[phone_user] WITH CHECK ADD CONSTRAINT [FKPhoneUserCorcosNormal] FOREIGN KEY([corcos_normal_uid]) REFERENCES [dbo].[corcos] ([uid]) ALTER TABLE [dbo].[phone_user] CHECK CONSTRAINT [FKPhoneUserCorcosNormal] ALTER TABLE [dbo].[phone_user] WITH CHECK ADD CONSTRAINT [FKPhoneUserCorcosReducing] FOREIGN KEY([corcos_reducing_uid]) REFERENCES [dbo].[corcos] ([uid]) ALTER TABLE [dbo].[phone_user] CHECK CONSTRAINT [FKPhoneUserCorcosReducing] ALTER TABLE [dbo].[phone_user] WITH CHECK ADD CONSTRAINT [FKPhoneUserCostCenter] FOREIGN KEY([cost_center_uid]) REFERENCES [dbo].[cost_center] ([uid]) ALTER TABLE [dbo].[phone_user] CHECK CONSTRAINT [FKPhoneUserCostCenter] ALTER TABLE [dbo].[phone_user] WITH CHECK ADD CONSTRAINT [FKPhoneUserDestinationGroup] FOREIGN KEY([destination_group_uid]) REFERENCES [dbo].[destination_group] ([uid]) ALTER TABLE [dbo].[phone_user] CHECK CONSTRAINT [FKPhoneUserDestinationGroup] ALTER TABLE [dbo].[phone_user] WITH CHECK ADD CONSTRAINT [FKPhoneUserOrganization] FOREIGN KEY([organization_uid]) REFERENCES [dbo].[organization] ([uid]) ALTER TABLE [dbo].[phone_user] CHECK CONSTRAINT [FKPhoneUserOrganization] ALTER TABLE [dbo].[phone_user] WITH CHECK ADD CONSTRAINT [FKPhoneUserRatePage] FOREIGN KEY([rate_page_uid]) REFERENCES [dbo].[rate_page] ([uid]) ALTER TABLE [dbo].[phone_user] CHECK CONSTRAINT [FKPhoneUserRatePage] ALTER TABLE [dbo].[phoneuserpbx] WITH CHECK ADD CONSTRAINT [FKPhoneUserPbxPbx] FOREIGN KEY([pbx_uid]) REFERENCES [dbo].[pbx] ([uid]) ALTER TABLE [dbo].[phoneuserpbx] CHECK CONSTRAINT [FKPhoneUserPbxPbx] ALTER TABLE [dbo].[phoneuserpbx] WITH CHECK ADD CONSTRAINT [FKPhoneUserPbxPhoneUser] FOREIGN KEY([phone_user_uid]) REFERENCES [dbo].[phone_user] ([uid]) ALTER TABLE [dbo].[phoneuserpbx] CHECK CONSTRAINT [FKPhoneUserPbxPhoneUser] ALTER TABLE [dbo].[pinsetup] WITH CHECK ADD CONSTRAINT [FKPinSetupPbx] FOREIGN KEY([pbx_uid]) REFERENCES [dbo].[pbx] ([uid]) ALTER TABLE [dbo].[pinsetup] CHECK CONSTRAINT [FKPinSetupPbx] ALTER TABLE [dbo].[rate] WITH CHECK ADD CONSTRAINT [FKRateProviderFrom] FOREIGN KEY([provider_from_uid]) REFERENCES [dbo].[provider] ([uid]) ALTER TABLE [dbo].[rate] CHECK CONSTRAINT [FKRateProviderFrom] ALTER TABLE [dbo].[rate] WITH CHECK ADD CONSTRAINT [FKRateProviderTo] FOREIGN KEY([provider_to_uid]) REFERENCES [dbo].[provider] ([uid]) ALTER TABLE [dbo].[rate] CHECK CONSTRAINT [FKRateProviderTo] ALTER TABLE [dbo].[rate] WITH CHECK ADD CONSTRAINT [FKRateRatePage] FOREIGN KEY([rate_page_uid]) REFERENCES [dbo].[rate_page] ([uid]) ALTER TABLE [dbo].[rate] CHECK CONSTRAINT [FKRateRatePage] ALTER TABLE [dbo].[rate] WITH CHECK ADD CONSTRAINT [FKRateZone] FOREIGN KEY([zone_uid]) REFERENCES [dbo].[zone] ([uid]) ALTER TABLE [dbo].[rate] CHECK CONSTRAINT [FKRateZone] ALTER TABLE [dbo].[schedule] WITH CHECK ADD CONSTRAINT [FKReportSchedule] FOREIGN KEY([report_uid]) REFERENCES [dbo].[report] ([uid]) ALTER TABLE [dbo].[schedule] CHECK CONSTRAINT [FKReportSchedule] ALTER TABLE [dbo].[ticket] WITH CHECK ADD CONSTRAINT [FKTicketCorcos] FOREIGN KEY([target_corcos_uid]) REFERENCES [dbo].[corcos] ([uid]) ALTER TABLE [dbo].[ticket] CHECK CONSTRAINT [FKTicketCorcos] ALTER TABLE [dbo].[ticket] WITH CHECK ADD CONSTRAINT [FKTicketRequestCorcos] FOREIGN KEY([request_corcos_uid]) REFERENCES [dbo].[corcos] ([uid]) ALTER TABLE [dbo].[ticket] CHECK CONSTRAINT [FKTicketRequestCorcos] ALTER TABLE [dbo].[ticket] WITH CHECK ADD CONSTRAINT [FKTicketRequestPbx] FOREIGN KEY([request_pbx_uid]) REFERENCES [dbo].[pbx] ([uid]) ALTER TABLE [dbo].[ticket] CHECK CONSTRAINT [FKTicketRequestPbx] ALTER TABLE [dbo].[ticket] WITH CHECK ADD CONSTRAINT [FKTicketTag] FOREIGN KEY([tag_uid]) REFERENCES [dbo].[tag] ([uid]) ALTER TABLE [dbo].[ticket] CHECK CONSTRAINT [FKTicketTag] ALTER TABLE [dbo].[ticket] WITH CHECK ADD CONSTRAINT [FKTicketWebUserRequester] FOREIGN KEY([requester_uid]) REFERENCES [dbo].[web_user] ([uid]) ALTER TABLE [dbo].[ticket] CHECK CONSTRAINT [FKTicketWebUserRequester] ALTER TABLE [dbo].[ticket] WITH CHECK ADD CONSTRAINT [FKTicketWebUserResultBy] FOREIGN KEY([result_by_uid]) REFERENCES [dbo].[web_user] ([uid]) ALTER TABLE [dbo].[ticket] CHECK CONSTRAINT [FKTicketWebUserResultBy] ALTER TABLE [dbo].[trunk] WITH CHECK ADD CONSTRAINT [FKTrunkArea] FOREIGN KEY([area_uid]) REFERENCES [dbo].[area] ([uid]) ALTER TABLE [dbo].[trunk] CHECK CONSTRAINT [FKTrunkArea] ALTER TABLE [dbo].[trunk] WITH CHECK ADD CONSTRAINT [FKTrunkPbx] FOREIGN KEY([pbx_uid]) REFERENCES [dbo].[pbx] ([uid]) ALTER TABLE [dbo].[trunk] CHECK CONSTRAINT [FKTrunkPbx] ALTER TABLE [dbo].[trunk] WITH CHECK ADD CONSTRAINT [FKTrunkProvider] FOREIGN KEY([provider_uid]) REFERENCES [dbo].[provider] ([uid]) ALTER TABLE [dbo].[trunk] CHECK CONSTRAINT [FKTrunkProvider] ALTER TABLE [dbo].[web_user] WITH CHECK ADD CONSTRAINT [FKWebUserLdapConfig] FOREIGN KEY([ldap_uid]) REFERENCES [dbo].[ldapconfig] ([uid]) ALTER TABLE [dbo].[web_user] CHECK CONSTRAINT [FKWebUserLdapConfig] ALTER TABLE [dbo].[web_user] WITH CHECK ADD CONSTRAINT [FKWebUserPBX] FOREIGN KEY([pinext_uid]) REFERENCES [dbo].[pbx] ([uid]) ALTER TABLE [dbo].[web_user] CHECK CONSTRAINT [FKWebUserPBX] ALTER TABLE [dbo].[web_user] WITH CHECK ADD CONSTRAINT [FKWebUserPhoneUser] FOREIGN KEY([phone_user_uid]) REFERENCES [dbo].[phone_user] ([uid]) ALTER TABLE [dbo].[web_user] CHECK CONSTRAINT [FKWebUserPhoneUser] ALTER TABLE [dbo].[web_user] WITH CHECK ADD CONSTRAINT [FKWebUserProfile] FOREIGN KEY([profile_uid]) REFERENCES [dbo].[profile] ([uid]) ALTER TABLE [dbo].[web_user] CHECK CONSTRAINT [FKWebUserProfile] ALTER TABLE [dbo].[additional_cost] WITH CHECK ADD CHECK (([target]>=(0) AND [target]<=(4))) ALTER TABLE [dbo].[budget] WITH CHECK ADD CHECK (([type]>=(0) AND [type]<=(2))) ALTER TABLE [dbo].[budget] WITH CHECK ADD CHECK (([user_type]>=(0) AND [user_type]<=(6))) ALTER TABLE [dbo].[calltransaction] WITH CHECK ADD CHECK (([communication_type]>=(0) AND [communication_type]<=(2))) ALTER TABLE [dbo].[calltransaction] WITH CHECK ADD CHECK (([conference_type]>=(0) AND [conference_type]<=(1))) ALTER TABLE [dbo].[calltransaction] WITH CHECK ADD CHECK (([direction]>=(0) AND [direction]<=(3))) ALTER TABLE [dbo].[calltransaction] WITH CHECK ADD CHECK (([phone_type]>=(0) AND [phone_type]<=(2))) ALTER TABLE [dbo].[calltransaction] WITH CHECK ADD CHECK (([transfer_type]>=(0) AND [transfer_type]<=(3))) ALTER TABLE [dbo].[cdrmodifier] WITH CHECK ADD CHECK (([match]>=(0) AND [match]<=(2))) ALTER TABLE [dbo].[counter] WITH CHECK ADD CHECK (([reset_direction]>=(0) AND [reset_direction]<=(3))) ALTER TABLE [dbo].[counter] WITH CHECK ADD CHECK (([reset_period]>=(0) AND [reset_period]<=(4))) ALTER TABLE [dbo].[counter] WITH CHECK ADD CHECK (([reset_target]>=(0) AND [reset_target]<=(3))) ALTER TABLE [dbo].[destination_group] WITH CHECK ADD CHECK (([type]>=(0) AND [type]<=(2))) ALTER TABLE [dbo].[hlr] WITH CHECK ADD CHECK (([phone_type]>=(0) AND [phone_type]<=(2))) ALTER TABLE [dbo].[ldapconfig] WITH CHECK ADD CHECK (([auth_type]>=(0) AND [auth_type]<=(2))) ALTER TABLE [dbo].[ldapconfig] WITH CHECK ADD CHECK (([conn_type]>=(0) AND [conn_type]<=(4))) ALTER TABLE [dbo].[ldapconfig] WITH CHECK ADD CHECK (([day_schedule]>=(0) AND [day_schedule]<=(8))) ALTER TABLE [dbo].[ldapconfig] WITH CHECK ADD CHECK (([period]>=(0) AND [period]<=(6))) ALTER TABLE [dbo].[pinsetup] WITH CHECK ADD CHECK (([flag]>=(0) AND [flag]<=(2))) ALTER TABLE [dbo].[pinsetup] WITH CHECK ADD CHECK (([period]>=(0) AND [period]<=(4))) ALTER TABLE [dbo].[pinsetup] WITH CHECK ADD CHECK (([target]>=(0) AND [target]<=(2))) ALTER TABLE [dbo].[report] WITH CHECK ADD CHECK (([lang]>=(0) AND [lang]<=(2))) ALTER TABLE [dbo].[schedule] WITH CHECK ADD CHECK (([day_schedule]>=(0) AND [day_schedule]<=(3))) ALTER TABLE [dbo].[schedule] WITH CHECK ADD CHECK (([file_format]>=(0) AND [file_format]<=(4))) ALTER TABLE [dbo].[schedule] WITH CHECK ADD CHECK (([iterance]>=(0) AND [iterance]<=(6))) ALTER TABLE [dbo].[schedule] WITH CHECK ADD CHECK (([unit]>=(0) AND [unit]<=(3))) ALTER TABLE [dbo].[ticket] WITH CHECK ADD CHECK (([request_type]>=(0) AND [request_type]<=(2))) ALTER TABLE [dbo].[ticket] WITH CHECK ADD CHECK (([result]>=(0) AND [result]<=(3))) ALTER TABLE [dbo].[ticket] WITH CHECK ADD CHECK (([type]>=(0) AND [type]<=(4))) ALTER TABLE [dbo].[web_user] WITH CHECK ADD CHECK (([lang]>=(0) AND [lang]<=(2))) ALTER TABLE [dbo].[web_user] WITH CHECK ADD CHECK (([rights_approval]>=(0) AND [rights_approval]<=(3))) ALTER DATABASE [callmaster] SET READ_WRITE