
SET LANGUAGE russian
SET IMPLICIT_TRANSACTIONS OFF
SET ANSI_NULLS ON
SET ANSI_PADDING ON
SET ANSI_WARNINGS ON
SET CONCAT_NULL_YIELDS_NULL ON
SET NUMERIC_ROUNDABORT OFF
SET NOCOUNT OFF
SET LOCK_TIMEOUT -1
SET XACT_ABORT ON
SET ARITHABORT ON
SET CURSOR_CLOSE_ON_COMMIT OFF
SET DATEFIRST 1
SET DATEFORMAT DMY
SET QUOTED_IDENTIFIER ON
GO
 
IF not exists(select * from sysobjects where id = object_id('[dbo].[S_OBJECTS_U]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
CREATE TABLE [S_OBJECTS_U] (
	[LINK] [int] IDENTITY (1, 1) NOT NULL ,
	[CODE] [char] (30)  NOT NULL ,
	[NAME] [varchar] (254)  NOT NULL ,
	[ORDERS] [smallint] NOT NULL ,
	[LINK_SELF] [int] NULL ,
	[LINK_CLASS] [int] NULL ,
	[Managed] [bit] NOT NULL ,
	[Inherited] [bit] NOT NULL 
) ON [PRIMARY]
GO


IF not exists(select * from sysobjects where id = object_id('[dbo].[S_DBObjects_U]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
CREATE TABLE [S_DBObjects_U] (
	[LINK] [int] IDENTITY (1, 1) NOT NULL ,
	[Object] [int] NOT NULL ,
	[DBObject] [varchar] (128)  NOT NULL ,
	[Rights] [tinyint] NOT NULL 
) ON [PRIMARY]
GO


IF not exists(select * from sysobjects where id = object_id('[dbo].[OBJECT_VAR_U]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
CREATE TABLE [OBJECT_VAR_U] (
	[LINK] [int] IDENTITY (1, 1) NOT NULL ,
	[OBJECT] [int] NOT NULL ,
	[NAME] [varchar] (254)  NULL ,
	[ORDERS] [smallint] NULL ,
	[LINK_SELF] [int] NULL ,
	[CODE] [varchar] (60)  NULL ,
	[LINK_STATE] [int] NULL ,
	[USERS] [varbinary] (85) NULL ,
	[SYS] [bit] NOT NULL 
) ON [PRIMARY]
GO


IF not exists(select * from sysobjects where id = object_id('[dbo].[S_NAVIGATOR_U]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
CREATE TABLE [S_NAVIGATOR_U] (
	[LINK] [int] IDENTITY (1, 1) NOT NULL ,
	[CODE] [char] (50)  NOT NULL ,
	[NAME] [char] (250)  NOT NULL ,
	[ORDERS] [smallint] NOT NULL ,
	[SYS] [bit] NOT NULL ,
	[LINK_SELF] [int] NULL ,
	[OBJECT] [int] NULL ,
	[LINK_VAR] [int] NULL ,
	[IMAGE_KEY] [char] (30)  NOT NULL ,
	[USERS] [varbinary] (85) NULL ,
	[VISIBLE] [tinyint] NOT NULL 
) ON [PRIMARY]
GO


IF not exists(select * from sysobjects where id = object_id('[dbo].[DICTION_U]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
CREATE TABLE [DICTION_U] (
	[LINK] [int] IDENTITY (1, 1) NOT NULL ,
	[NAME] [varchar] (254)  NULL ,
	[OBJECT] [int] NOT NULL ,
	[CODE] [varchar] (20)  NULL ,
	[BEGINDATE] [datetime] NOT NULL ,
	[ENDDATE] [datetime] NOT NULL 
) ON [PRIMARY]
GO


IF not exists(select * from sysobjects where id = object_id('[dbo].[S_PERMISSIONS_U]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
CREATE TABLE [S_PERMISSIONS_U] (
	[LINK] [int] IDENTITY (1, 1) NOT NULL ,
	[OBJECT] [int] NOT NULL ,
	[Permitted] [tinyint] NOT NULL ,
	[Restricted] [tinyint] NOT NULL ,
	[SID] [varbinary] (85) NOT NULL 
) ON [PRIMARY]
GO


IF not exists(select * from sysobjects where id = object_id('[dbo].[S_PROPERTY_U]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
CREATE TABLE [S_PROPERTY_U] (
	[LINK] [int] IDENTITY (1, 1) NOT NULL ,
	[NAME] [varchar] (254)  NOT NULL ,
	[DATA_TYPE] [varchar] (20)  NULL ,
	[DATA_LEN] [smallint] NULL ,
	[DATA_PREC] [smallint] NULL ,
	[CODE] [varchar] (30)  NOT NULL 
) ON [PRIMARY]
GO


IF not exists(select * from sysobjects where id = object_id('[dbo].[OBJECT_VAR_VALUES_U]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
CREATE TABLE [OBJECT_VAR_VALUES_U] (
	[LINK_UP] [int] NOT NULL ,
	[PROPERTY] [int] NOT NULL ,
	[VALUE] [varchar] (7900)  NULL ,
	[ORDERS] [int] NULL ,
	[USERS] [varbinary] (85) NULL 
) ON [PRIMARY]
GO


IF not exists(select * from sysobjects where id = object_id('[dbo].[OBJECT_VALUES_U]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
CREATE TABLE [OBJECT_VALUES_U] (
	[OBJECT] [int] NOT NULL ,
	[PROPERTY] [int] NOT NULL ,
	[VALUE] [varchar] (8000)  NULL ,
	[INHERITED] [bit] NOT NULL 
) ON [PRIMARY]
GO


--Таблица REPORT_FORMS
IF not exists(select * from sysobjects where id = object_id('[dbo].[REPORT_FORMS_U]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
CREATE TABLE [dbo].[REPORT_FORMS_U] (
	[Link_Form] int NOT NULL IDENTITY(1,1) ,
	[Name] varchar(200) NULL ,
	[Code] varchar(20) NULL ,
	[Start_Date] datetime NOT NULL ,
	[Periodic] tinyint NOT NULL ,
	[IsSvod] tinyint NOT NULL ,
	[IsExported] tinyint NOT NULL ,
	[IsUserForm] tinyint NOT NULL ,
	[IsUsedRazdel] tinyint NOT NULL ,
	[IsUsedCelSt] tinyint NOT NULL ,
	[IsUsedRashod] tinyint NOT NULL ,
	[LinkRazdel] int NULL ,
	[LinkCelSt] int NULL ,
	[LinkRashod] int NULL ,
	[Print_Object_Method] varchar(200) NULL ,
	[Query_Add_Module] varchar(200) NULL ,
	[Query_Before] varchar(200) NULL ,
	[Query_RepMaker] varchar(200) NULL ,
	[Query_Report] varchar(200) NULL ,
	[Query_Report_Path] varchar(200) NULL ,
	[Form_Type] int NOT NULL ,
	[Export_Proc] varchar(100) NULL ,
	[Decript_Proc] varchar(30) NULL ,
	[IsRemoteAccess] tinyint NOT NULL ,
	[IsKonsolid] tinyint NOT NULL ,
	[Param_Export] varchar(8000) NULL ,
	[Param_Import] varchar(8000) NULL ,
	[Object] varchar(254) NULL ,
	[ExportCode] char(10) NOT NULL ,
	[IS_AUTOFILL] tinyint NOT NULL ,
	[atributs] varchar(1000) NULL ,
	[UPDATE_DATE] datetime NOT NULL ,
	[SvodProc] varchar(254) NULL ,
	[End_Date] datetime NULL ,
	[COMMENT] varchar(200) NULL ,
	[Print_Object_Method_New] varchar(200) NULL ,
	[Query_Before_Print_New] varchar(200) NULL ,
	[Query_Report_New] varchar(200) NULL ,
	[IS_CALC] int NOT NULL ,
	[Hint_File_Id] int NULL ,
	[GUID] varchar(100) NOT NULL )
GO


--Таблица REPORT_TABLES
IF not exists(select * from sysobjects where id = object_id('[dbo].[REPORT_TABLES_U]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
CREATE TABLE [dbo].[REPORT_TABLES_U] (
	[Link_Table] int NULL,
	[Name] varchar(50) NULL ,
	[Link_Form] int NULL ,
	[Orders] tinyint NULL ,
	[Link_Code_Col] int NULL ,
	[Val_Type] tinyint NULL ,
	[Script_Str] varchar(7000) NULL ,
	[order_rule] varchar(4000) NULL ,
	[IS_DINAMIC] int NULL ,
	[GUID] varchar(100) NULL ,
	[Doschet_Tree] tinyint NULL )
GO

--Таблица REPORT_ROWS
IF not exists(select * from sysobjects where id = object_id('[dbo].[REPORT_ROWS_U]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
CREATE TABLE [dbo].[REPORT_ROWS_U] (
	[Link_Row] int NOT NULL IDENTITY(1,1) ,
	[Orders] smallint NOT NULL ,
	[Link_Table] int NOT NULL ,
	[Calc_Orders] smallint NOT NULL ,
	[Print_Null] tinyint NOT NULL ,
	[GUID] varchar(100) NOT NULL )
GO


--Таблица REPORT_COLOUMNS
IF not exists(select * from sysobjects where id = object_id('[dbo].[REPORT_COLOUMNS_U]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
CREATE TABLE [dbo].[REPORT_COLOUMNS_U] (
	[Link_Col] int NOT NULL IDENTITY(1,1) ,
	[Orders] tinyint NOT NULL ,
	[Name] varchar(70) NULL ,
	[Link_Table] int NOT NULL ,
	[IsExported] tinyint NOT NULL ,
	[Col_Type] tinyint NOT NULL ,
	[Export_Order] tinyint NULL ,
	[Calc_Orders] tinyint NOT NULL ,
	[IsEdited] tinyint NOT NULL ,
	[Val_Len] int NULL ,
	[Dictionary] varchar(100) NULL ,
	[Dictionary_Columns_List] varchar(250) NULL ,
	[Dictionary_Fields_List] varchar(250) NULL ,
	[input_mask] varchar(200) NULL ,
	[property] int NULL ,
	[STR_PROPERTY] varchar(200) NULL ,
	[GUID] varchar(100) NOT NULL )
GO


--Таблица REPORT_FORMULA
IF not exists(select * from sysobjects where id = object_id('[dbo].[REPORT_FORMULA_U]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
CREATE TABLE [dbo].[REPORT_FORMULA_U] (
	[Link_Row] int NOT NULL ,
	[Link_Col] int NOT NULL ,
	[Formula] varchar(8000) NULL )
GO



--IF not exists(select * from sysobjects where id = object_id('[dbo].[REPORT_CONTROL_PARITIES_U]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
--CREATE TABLE [REPORT_CONTROL_PARITIES_U] (
--	[Link_Form] [int] NOT NULL ,
--	[OrderRule] [int] NOT NULL ,
--	[OrderRow] [smallint] NOT NULL ,
--	[IsOutsideParity] [tinyint] NOT NULL ,
--	[Period] [smallint] NOT NULL ,
--	[Val_Type] [tinyint] NOT NULL ,
--	[Link_Table] [int] NULL ,
--	[Link_Col] [int] NULL ,
--	[Link_Row] [int] NULL ,
--	[Period_Form] [smallint] NOT NULL ,
--	[Factor] [float] NULL ,
--	[Exec_Proc] [varchar] (250)  NULL ,
--	[Exec_Proc_Desc] [varchar] (250)  NULL ,
--	[Sign] [char] (2)  NOT NULL 
--) ON [PRIMARY]
--GO


IF not exists(select * from sysobjects where id = object_id('[dbo].[S_RELEASE_U]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
CREATE TABLE [S_RELEASE_U] (
	[ID] [int] IDENTITY (1, 1) NOT NULL ,
	[Project] [int] NOT NULL ,
	[Release] [int] NOT NULL ,
	[Fix] [int] NOT NULL 
) ON [PRIMARY]
GO


IF not exists(select * from sysobjects where id = object_id('[dbo].[S_FILES_U]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
CREATE TABLE [S_FILES_U] (
	[ID] [int] IDENTITY (1, 1) NOT NULL ,
	[Name] [varchar] (254)  NOT NULL ,
	[Release] [int] NOT NULL ,
	[Path] [varchar] (254)  NOT NULL ,
	[CreateDate] [datetime] NOT NULL ,
	[FileSize] [int] NOT NULL 
) ON [PRIMARY]
GO


--Таблица EXPORT_BLOCKS
IF not exists(select * from sysobjects where id = object_id('[dbo].[EXPORT_BLOCKS_U]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
CREATE TABLE [dbo].[EXPORT_BLOCKS_U] (
	[Link_Block] int NOT NULL IDENTITY(1,1) ,
	[Link_Model] int NOT NULL ,
	[Code] char(10) NOT NULL ,
	[Orders] smallint NOT NULL ,
	[IsOnce] tinyint NOT NULL ,
	[Name] varchar(200) NOT NULL ,
	[Obligatory] tinyint NOT NULL )
GO


--Таблица EXPORT_FIELDS
IF not exists(select * from sysobjects where id = object_id('[dbo].[EXPORT_FIELDS_U]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
CREATE TABLE [dbo].[EXPORT_FIELDS_U] (
	[Link_Field] int NOT NULL IDENTITY(1,1) ,
	[Link_Block] int NOT NULL ,
	[Orders] smallint NOT NULL ,
	[Code] char(15) NOT NULL ,
	[Name] char(250) NULL ,
	[Val_Type] char(7) NOT NULL ,
	[Val_Len] smallint NULL ,
	[Val_Len_Eq] tinyint NOT NULL ,
	[Need_Check] tinyint NOT NULL ,
	[Obligatory] tinyint NOT NULL ,
	[Alias_Code] varchar(25) NULL ,
	[Check_Proc] varchar(200) NOT NULL ,
	[Val_List] varchar(250) NOT NULL )
GO



--Таблица EXPORT_MODELS
IF not exists(select * from sysobjects where id = object_id('[dbo].[EXPORT_MODELS_U]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
CREATE TABLE [dbo].[EXPORT_MODELS_U] (
	[Link_Model] int NOT NULL IDENTITY(1,1) ,
	[Code] char(5) NOT NULL ,
	[Name] varchar(250) NULL ,
	[Model_Ver] char(10) NOT NULL ,
	[IsOnce] tinyint NOT NULL ,
	[NORM_DOC] varchar(250) NOT NULL ,
	[FILE_NAME_MASK] char(12) NOT NULL ,
	[FILE_NAME_PROC] char(50) NULL ,
	[PROC_EXP] char(50) NULL ,
	[PROC_DOP_PARAM] char(50) NOT NULL ,
	[DEP_NAME] char(20) NULL ,
	[PROG_SAVE] char(50) NULL )
GO



--Таблица REPORT_CONTROL_ROWS
IF not exists(select * from sysobjects where id = object_id('[dbo].[REPORT_CONTROL_ROWS_U]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
CREATE TABLE [dbo].[REPORT_CONTROL_ROWS_U] (
	[Link_Rule] int NOT NULL ,
	[OrderRow] int NOT NULL ,
	[Val_Type] tinyint NOT NULL ,
	[Sign] char(2) NOT NULL ,
	[Link_Form] int NULL ,
	[Link_Table] int NULL ,
	[Link_Col] int NULL ,
	[Link_Row] int NULL ,
	[PERIOD_FORM] smallint NULL ,
	[Factor] float NOT NULL ,
	[Exec_Proc] varchar(250) NULL ,
	[Exec_Proc_Desc] varchar(250) NULL ,
	[Code_Row] varchar(50) NULL ,
	[Filter] varchar(1000) NOT NULL ,
	[Filter_Desc] varchar(250) NOT NULL ,
	[Maska] varchar(250) NOT NULL ,
	[Maska_Desc] varchar(250) NOT NULL ,
	[PERIOD_TYPE] tinyint NOT NULL ,
	[BUDG_CODE] char(5) NOT NULL ,
	[PERIOD_YEAR] smallint NULL ,
	[atr_code] varchar(254) NOT NULL ,
	[part] tinyint NOT NULL ,
	[begin_date] datetime NULL ,
	[px] float NOT NULL ,
	[px_comment] varchar(254) NOT NULL )
GO



--Таблица REPORT_CONTROL_RULES
IF not exists(select * from sysobjects where id = object_id('[dbo].[REPORT_CONTROL_RULES_U]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
CREATE TABLE [dbo].[REPORT_CONTROL_RULES_U] (
	[Link_Rule] int NOT NULL IDENTITY(1,1) ,
	[Link_Task] int NOT NULL ,
	[IsOutside] tinyint NOT NULL ,
	[Link_Form] int NULL ,
	[OrderRule] int NOT NULL ,
	[Period] smallint NOT NULL ,
	[Period_nom] smallint NOT NULL ,
	[Org_Level] smallint NOT NULL ,
	[IsSvod] smallint NOT NULL ,
	[Str_Rule] varchar(5800) NOT NULL ,
	[IsDoschet] tinyint NOT NULL ,
	[CALC_ORDERS] int NOT NULL ,
	[IsSystemsRule] tinyint NOT NULL ,
	[Modify_Date] datetime NOT NULL ,
	[Rows] varchar(1000) NOT NULL ,
	[Cols] varchar(250) NOT NULL ,
	[Rows_desc] varchar(250) NOT NULL ,
	[REGION] varchar(100) NULL ,
	[COMMENT] varchar(2000) NULL ,
	[sign_sr] char(2) NOT NULL ,
	[algorithm] tinyint NOT NULL ,
	[atr_code_sr] varchar(254) NOT NULL )
GO


----Таблица REPORT_OPTIONS
--IF not exists(select * from sysobjects where id = object_id('[dbo].[REPORT_OPTIONS_U]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
--CREATE TABLE [dbo].[REPORT_OPTIONS_U] (
--	[Razdel] varchar(30) NOT NULL ,
--	[Code] varchar(20) NOT NULL ,
--	[Orders] int NOT NULL ,
--	[Name] varchar(200) NULL ,
--	[Val_Type] smallint NOT NULL ,
--	[Val_Int] int NULL ,
--	[Val_Float] float NULL ,
--	[Val_Str] varchar(250) NULL ,
--	[Val_Date] datetime NULL ,
--	[Link_KAU] int NULL ,
--	[SID] varbinary(85) NOT NULL )
--GO



--Таблица S_BANK_FORMAT_BASE
IF not exists(select * from sysobjects where id = object_id('[dbo].[S_BANK_FORMAT_BASE_U]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
CREATE TABLE [dbo].[S_BANK_FORMAT_BASE_U] (
	[link] int NOT NULL IDENTITY(1,1) ,
	[CODE] varchar(20) NOT NULL ,
	[NAME] varchar(254) NOT NULL ,
	[FTYPE] tinyint NOT NULL ,
	[FVALUE] varchar(254) NOT NULL ,
	[DATATYPE] char(1) NOT NULL )
GO


IF not exists(select * from sysobjects where id = object_id('[dbo].[S_GROUP_SID_U]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
CREATE TABLE [S_GROUP_SID_U] (
	[UID] [smallint] NOT NULL ,
	[SID] [varbinary] (85) NOT NULL ,
	[Name] [varchar] (128)  NOT NULL ,
	[CreateDate] [datetime] NOT NULL 
) ON [PRIMARY]
GO

IF not exists(select * from sysobjects where id = object_id('[dbo].[s_fileparts_U]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
CREATE TABLE [s_fileparts_U] (
	[file_id] [int] NOT NULL ,
	[orders] [int] NOT NULL ,
	[body] [varbinary] (8000) NULL 
) ON [PRIMARY]
GO

IF not exists(select * from sysobjects where id = object_id('[dbo].[S_TABLES_U]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
CREATE TABLE [dbo].[S_TABLES_U] (
	[NAME] [varchar] (128) NOT NULL ,
	[QUERY_ADD] [varchar] (8000) NOT NULL,
	[FROM_ADD] [varchar] (8000) NOT NULL,
	[WHERE_ADD] [varchar] (8000) NOT NULL)
GO

IF not exists(select * from sysobjects where id = object_id('[dbo].[DICTION_APP_U]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
CREATE TABLE [dbo].[DICTION_APP_U] (
	[LINK_UP] [int] NOT NULL ,
	[OBJECT] [int] NOT NULL ,
	[VALUE] [varchar] (8000)
)
GO



----Таблица ECONOMY_OPER
--IF not exists(select * from sysobjects where id = object_id('[dbo].[ECONOMY_OPER]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
--CREATE TABLE [dbo].[ECONOMY_OPER] (
--	[LINK] int NOT NULL IDENTITY(1,1) ,
--	[CODE] varchar(20) NOT NULL ,
--	[NAME] varchar(254) NOT NULL ,
--	[SYSTEM] bit NOT NULL ,
--	[LINK_SELF] int NULL ,
--	[KASSA] tinyint NOT NULL ,
--	[LEDGER_JOURNAL] int NULL ,
--	[NO_JOUR] bit NOT NULL ,
--	[NO_GK] bit NOT NULL ,
--	[ZP] bit NOT NULL ,
--	[BO] bit NOT NULL )
--GO


----Таблица JOURNAL_OPERATION
--IF not exists(select * from sysobjects where id = object_id('[dbo].[JOURNAL_OPERATION]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
--CREATE TABLE [dbo].[JOURNAL_OPERATION] (
--	[LINK] int NOT NULL IDENTITY(1,1) ,
--	[CODE] char(10) NOT NULL ,
--	[NAME] varchar(254) NOT NULL ,
--	[ACTIVITIES] char(10) NULL ,
--	[DELIMITER] char(10) NULL ,
--	[FACT_TOTAL] bit NOT NULL ,
--	[ACCT_TOTAL] bit NOT NULL ,
--	[TOTAL_DATE] varchar(100) NOT NULL ,
--	[TOTAL_MODE] tinyint NOT NULL )
--GO



if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[HISTORY_U]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[HISTORY_U]
GO

CREATE TABLE [dbo].[HISTORY_U] (
	[LINK] [int] IDENTITY(1,1) NOT NULL ,
	[LINK_UP] [int] NOT NULL ,
	[TASK_CODE] [varchar] (10) NOT NULL ,
	[INFO] [varchar] (8000) NOT NULL 
) ON [PRIMARY]
GO

if not exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[FAQ_U]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
BEGIN
CREATE TABLE [FAQ_U] (
	[LINK] [int] IDENTITY (1, 1) NOT NULL ,
	[TASK] [varchar] (20)  NOT NULL ,
	[GRP] [varchar] (100)  NOT NULL ,
	[ORDERS] [int] NOT NULL ,
	[QUEST] [varchar] (250)  NOT NULL ,
	[ANSWER] [varchar] (7000)  NOT NULL
) ON [PRIMARY]
END

GO

----Таблица _DIVISION
--IF not exists(select * from sysobjects where id = object_id('[dbo].[_DIVISION]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
--CREATE TABLE [dbo].[_DIVISION] (
--	[CODE] varchar(4) NOT NULL ,
--	[NAME] varchar(1000) NOT NULL )
--GO



----Таблица _EXP
--IF not exists(select * from sysobjects where id = object_id('[dbo].[_EXP]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
--CREATE TABLE [dbo].[_EXP] (
--	[CODE] varchar(3) NOT NULL ,
--	[NAME] varchar(1000) NOT NULL )
--GO



----Таблица _IVF
--IF not exists(select * from sysobjects where id = object_id('[dbo].[_IVF]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
--CREATE TABLE [dbo].[_IVF] (
--	[CODE] varchar(14) NOT NULL ,
--	[NAME] varchar(1000) NOT NULL )
--GO


----Таблица _IVnF
--IF not exists(select * from sysobjects where id = object_id('[dbo].[_IVnF]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
--CREATE TABLE [dbo].[_IVnF] (
--	[CODE] varchar(14) NOT NULL ,
--	[NAME] varchar(1000) NOT NULL )
--GO


----Таблица _T_ITEM
--IF not exists(select * from sysobjects where id = object_id('[dbo].[_T_ITEM]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
--CREATE TABLE [dbo].[_T_ITEM] (
--	[CODE] varchar(7) NOT NULL ,
--	[NAME] varchar(1000) NOT NULL )
--GO


----Таблица _adm
--IF not exists(select * from sysobjects where id = object_id('[dbo].[_adm]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
--CREATE TABLE [dbo].[_adm] (
--	[CODE] varchar(3) NOT NULL ,
--	[NAME] varchar(1000) NOT NULL )
--GO

----Таблица _KD
--IF not exists(select * from sysobjects where id = object_id('[dbo].[_KD]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
--CREATE TABLE [dbo].[_KD] (
--	[CODE] varchar(14) NOT NULL ,
--	[NAME] varchar(1000) NOT NULL )
--GO

--Таблица REPORT_GROUP_KS
IF not exists(select * from sysobjects where id = object_id('[dbo].[REPORT_GROUP_KS_U]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
CREATE TABLE [dbo].[REPORT_GROUP_KS_U] (
	[LINK_GROUP_KS] int NOT NULL,
	[CODE] char(20) NOT NULL ,
	[NAME] varchar(254) NOT NULL ,
	[TYPE] tinyint NOT NULL ,
	[SYSTEM] bit NOT NULL ,
	[dt_begin] datetime NULL ,
	[dt_end] datetime NULL )
GO

IF not exists(select * from sysobjects where id = object_id('[dbo].[REPORT_CONTROL_GROUP_U]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
CREATE TABLE [dbo].[REPORT_CONTROL_GROUP_U] (
	[Link_Rule] int NULL ,
	[Link_Group_KS] int NULL )
GO

IF not exists(select * from sysobjects where id = object_id('[dbo].[REPORT_FORM_GROUPS_U]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
CREATE TABLE [dbo].[REPORT_FORM_GROUPS_U] (
	[LINK] int NOT NULL ,
	[CODE] char(10) NULL ,
	[NAME] varchar(50) NULL ,
	[SYSTEM] bit NOT NULL )
GO

IF not exists(select * from sysobjects where id = object_id('[dbo].[REPORT_FORM_GROUPS_REF_U]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
CREATE TABLE [dbo].[REPORT_FORM_GROUPS_REF_U] (
	[LINK_FORM] int NOT NULL ,
	[LINK_FORM_GROUPS] int NOT NULL )
GO

IF not exists(select * from sysobjects where id = object_id('[dbo].[R_FILES_U]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
CREATE TABLE [dbo].[R_FILES_U] (
	[ID] int NOT NULL IDENTITY(1,1) ,
	[Name] varchar(254) NOT NULL ,
	[Path] varchar(254) NOT NULL ,
	[CreateDate] datetime NOT NULL ,
	[FileSize] int NOT NULL )
GO

IF not exists(select * from sysobjects where id = object_id('[dbo].[R_FILEPARTS_U]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
CREATE TABLE [dbo].[R_FILEPARTS_U] (
	[File_ID] int NOT NULL ,
	[Orders] int NOT NULL ,
	[Body] varchar(8000) NOT NULL )
GO


IF not exists(select * from sysobjects where id = object_id('[dbo].[REMIND_QUERY_U]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
CREATE TABLE [dbo].[REMIND_QUERY_U] (
	[LINK] int NULL,
	[CODE] varchar(50) NULL ,
	[NAME] varchar(254) NULL ,
	[SQLSTR] varchar(4000) NULL ,
	[PREPARE] varchar(3000) NULL ,
	[TASK_ENABLE] tinyint NULL ,
	[S_OBJECTS_CODE] varchar(30) NULL )
GO
