CREATE DATABASE TrustManager
 COLLATE Cyrillic_General_CI_AS
GO

USE TrustManager
GO

if not exists (select * from dbo.sysusers where name = N'tm_admin')
	EXEC dbo.sp_addrole @rolename = N'tm_admin', @ownername = N'dbo'
GO
if not exists (select * from dbo.sysusers where name = N'tm_user')
	EXEC dbo.sp_addrole @rolename = N'tm_user', @ownername = N'dbo'
GO

/* Различные типы данных  */


create default [DisabledNo] as 'n'
GO
create rule [BuySellRule] as (@buy='B') or (@buy='S') or (@buy='X')
GO
create rule [DisabledFlag] as (@flag='y') or (@flag='n')
GO

EXEC dbo.sp_addtype @typename=N'BuySell', @phystype='char(1)', @nulltype='NULL'
GO
EXEC dbo.sp_addtype @typename=N'DisabledFlag', @phystype='char(1)', @nulltype='NOT NULL'
GO

EXEC sp_bindefault N'[DisabledNo]', N'[DisabledFlag]'
GO
EXEC dbo.sp_bindrule N'[BuySellRule]', N'[BuySell]'
GO
EXEC dbo.sp_bindrule N'[DisabledFlag]', N'[DisabledFlag]'
GO

/* Таблицы */

SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [Clients](
	[ClientCode] [varchar](20) COLLATE Cyrillic_General_CS_AS NOT NULL,
	[GroupID] [int] NOT NULL,
	[Num] [int] NULL,
	[Weight] [float] NULL,
	[Comment] [varchar](50) COLLATE Cyrillic_General_CI_AS NULL
) ON [PRIMARY]
GO
SET ANSI_PADDING OFF
GO
CREATE UNIQUE NONCLUSTERED INDEX [ClientsFullIndex] ON [Clients] 
(
	[GroupID] ASC,
	[ClientCode] ASC
) ON [PRIMARY]
GO
CREATE NONCLUSTERED INDEX [GroupDescClients] ON [Clients] 
(
	[GroupID] ASC
) ON [PRIMARY]
GO

SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [ExportOrder](
	[ID] [int] NOT NULL,
	[OrderID] [int] NOT NULL,
	[GroupOrderID] [int] NOT NULL,
	[OrderType] [int] NOT NULL,
	[TradeDate] [int] NOT NULL,
	[SendDate] [int] NOT NULL,
	[SendTime] [int] NOT NULL,
	[OrderTime] [int] NULL,
	[Status] [int] NULL,
	[UserGroupID] [int] NULL,
	[UserGroupCode] [varchar](64) COLLATE Cyrillic_General_CI_AS NULL,
	[PoolID] [int] NULL,
	[BrokerPoolID] [varchar](32) COLLATE Cyrillic_General_CI_AS NULL,
	[ClientCode] [varchar](12) COLLATE Cyrillic_General_CI_AS NULL,
	[TrdAcc] [varchar](12) COLLATE Cyrillic_General_CI_AS NULL,
	[Price] [float] NULL,
	[Qty] [float] NULL,
	[Balance] [float] NULL,
	[Buy] [BuySell] NULL,
	[ML] [char](1) COLLATE Cyrillic_General_CI_AS NULL,
	[ClassCode] [varchar](12) COLLATE Cyrillic_General_CI_AS NULL,
	[SecCode] [varchar](12) COLLATE Cyrillic_General_CI_AS NULL,
	[VisibleQty] [float] NULL,
	[RepoValue] [float] NULL,
	[Discount] [float] NULL,
	[DiscountUpper] [float] NULL,
	[DiscountLower] [float] NULL,
	[RepoRate] [float] NULL,
	[RepoTerm] [int] NULL,
 CONSTRAINT [PK_ExportOrder] PRIMARY KEY CLUSTERED 
(
	[ID] ASC
)WITH FILLFACTOR = 90 ON [PRIMARY]
) ON [PRIMARY]
GO
SET ANSI_PADDING OFF
GO
CREATE NONCLUSTERED INDEX [IX_ExportOrder_Date] ON [ExportOrder] 
(
	[TradeDate] ASC
)WITH FILLFACTOR = 90 ON [PRIMARY]
GO
CREATE NONCLUSTERED INDEX [IX_ExportOrder_GrOrderID] ON [ExportOrder] 
(
	[GroupOrderID] ASC
)WITH FILLFACTOR = 90 ON [PRIMARY]
GO
CREATE NONCLUSTERED INDEX [IX_ExportOrder_OrderID] ON [ExportOrder] 
(
	[OrderID] ASC
)WITH FILLFACTOR = 90 ON [PRIMARY]
GO
CREATE NONCLUSTERED INDEX [IX_ExportOrder_Time] ON [ExportOrder] 
(
	[SendTime] ASC
)WITH FILLFACTOR = 90 ON [PRIMARY]
GO
CREATE NONCLUSTERED INDEX [IX_ExportOrder_UserGrID] ON [ExportOrder] 
(
	[UserGroupID] ASC
)WITH FILLFACTOR = 90 ON [PRIMARY]
GO

SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [GroupDesc](
	[GroupID] [int] IDENTITY(1,1) NOT NULL,
	[GroupCode] [varchar](64) COLLATE Cyrillic_General_CI_AS NOT NULL,
	[GroupName] [varchar](255) COLLATE Cyrillic_General_CI_AS NULL,
	[disabled] [DisabledFlag] NOT NULL,
	[Mode] [varchar](10) COLLATE Cyrillic_General_CS_AS NULL,
	[DefWeight] [float] NULL,
	[SplitOrders] [int] NULL,
 CONSTRAINT [GroupDesc_PK] PRIMARY KEY NONCLUSTERED 
(
	[GroupID] ASC
)WITH FILLFACTOR = 90 ON [PRIMARY]
) ON [PRIMARY]
GO
SET ANSI_PADDING OFF
GO
CREATE NONCLUSTERED INDEX [GroupCode] ON [GroupDesc] 
(
	[GroupCode] ASC
)WITH FILLFACTOR = 90 ON [PRIMARY]
GO

SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [GroupNegOrders](
	[ID] [int] NOT NULL,
	[GroupID] [int] NULL,
	[TradeDate] [int] NULL,
	[TradeTime] [int] NULL,
	[Buy] [BuySell] NULL,
	[SecCode] [varchar](12) COLLATE Cyrillic_General_CI_AS NULL,
	[ClassCode] [varchar](12) COLLATE Cyrillic_General_CI_AS NULL,
	[CPFirmID] [varchar](12) COLLATE Cyrillic_General_CI_AS NULL,
	[SettleCode] [varchar](12) COLLATE Cyrillic_General_CI_AS NULL,
	[MatchRef] [varchar](10) COLLATE Cyrillic_General_CI_AS NULL,
	[Price] [float] NULL,
	[Vozm] [float] NULL,
	[Qty] [float] NULL,
	[RealQty] [float] NULL,
	[KilledQty] [float] NULL,
	[Status] [char](1) COLLATE Cyrillic_General_CI_AS NULL,
	[Result] [char](1) COLLATE Cyrillic_General_CI_AS NULL,
	[OrdersCount] [int] NULL,
	[RepoValue] [float] NULL,
	[RealRepoValue] [float] NULL,
	[Discount] [float] NULL,
	[DiscountUpper] [float] NULL,
	[DiscountLower] [float] NULL,
	[RepoRate] [float] NULL,
	[RepoTerm] [int] NULL,
	[OrderType] [int] NULL,
	[Flags] [int] NULL,
	[TMUserID] [int] NULL,
	[TMSessionID] [varchar](40) COLLATE Cyrillic_General_CI_AS NULL,
	[TMCounter] [int] NULL,
 CONSTRAINT [GroupNegOrders_PK] PRIMARY KEY NONCLUSTERED 
(
	[ID] ASC
) ON [PRIMARY]
) ON [PRIMARY]
GO
SET ANSI_PADDING OFF
GO

SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [GroupOrders](
	[ID] [int] NOT NULL,
	[GroupID] [int] NOT NULL,
	[TradeDate] [int] NOT NULL,
	[TradeTime] [int] NOT NULL,
	[Buy] [BuySell] NOT NULL,
	[ML] [char](1) COLLATE Cyrillic_General_CI_AS NOT NULL,
	[SecCode] [varchar](12) COLLATE Cyrillic_General_CI_AS NOT NULL,
	[ClassCode] [varchar](12) COLLATE Cyrillic_General_CI_AS NOT NULL,
	[Price] [float] NOT NULL,
	[Qty] [float] NOT NULL,
	[RealQty] [float] NOT NULL,
	[BalanceQty] [float] NOT NULL,
	[KilledQty] [float] NOT NULL,
	[Status] [char](1) COLLATE Cyrillic_General_CI_AS NOT NULL,
	[Result] [char](1) COLLATE Cyrillic_General_CI_AS NOT NULL,
	[OrdersCount] [int] NOT NULL,
	[Flags] [char](10) COLLATE Cyrillic_General_CI_AS NULL,
	[PoolID] [int] NULL,
	[Value] [float] NULL,
	[TMUserID] [int] NULL,
	[TMSessionID] [varchar](40) COLLATE Cyrillic_General_CI_AS NULL,
	[TMCounter] [int] NULL,
	[VisibleQty] [float] NULL,
 CONSTRAINT [GroupOrders_PK] PRIMARY KEY NONCLUSTERED 
(
	[ID] ASC
) ON [PRIMARY]
) ON [PRIMARY]
GO
SET ANSI_PADDING OFF
GO
CREATE NONCLUSTERED INDEX [GroupDescGroupOrders] ON [GroupOrders] 
(
	[GroupID] ASC
) ON [PRIMARY]
GO

SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [GroupStopOrders](
	[ID] [int] NOT NULL,
	[GroupID] [int] NOT NULL,
	[StopStyle] [int] NULL,
	[TradeDate] [int] NOT NULL,
	[TradeTime] [int] NOT NULL,
	[Buy] [BuySell] NOT NULL,
	[ML] [char](1) COLLATE Cyrillic_General_CI_AS NOT NULL,
	[SecCode] [varchar](12) COLLATE Cyrillic_General_CI_AS NOT NULL,
	[ClassCode] [varchar](12) COLLATE Cyrillic_General_CI_AS NOT NULL,
	[ASecCode] [varchar](12) COLLATE Cyrillic_General_CI_AS NULL,
	[AClassCode] [varchar](12) COLLATE Cyrillic_General_CI_AS NULL,
	[StopCond] [int] NULL,
	[TransFlags] [int] NULL,
	[StopPrice] [float] NOT NULL,
	[Price] [float] NOT NULL,
	[LinkedPrice] [float] NULL,
	[Offset] [float] NULL,
	[Spread] [float] NULL,
	[Qty] [float] NOT NULL,
	[RealQty] [float] NOT NULL,
	[BalanceQty] [float] NOT NULL,
	[KilledQty] [float] NOT NULL,
	[BaseOrderNum] [float] NULL,
	[Status] [char](1) COLLATE Cyrillic_General_CI_AS NOT NULL,
	[Result] [char](1) COLLATE Cyrillic_General_CI_AS NOT NULL,
	[OrdersCount] [int] NOT NULL,
	[LinkedGrOrder] [int] NULL,
	[CoOrderNum] [float] NULL,
	[Expire] [int] NULL,
	[StopPrice2] [float] NULL,
	[ActiveFromTime] [int] NULL,
	[ActiveToTime] [int] NULL,
 CONSTRAINT [GroupStopOrders_PK] PRIMARY KEY NONCLUSTERED 
(
	[ID] ASC
) ON [PRIMARY]
) ON [PRIMARY]
GO

SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [ImportLog](
	[ID] [int] NOT NULL,
	[ImportType] [varchar](32) NULL,
	[TMUserID] [int] NULL,
	[TMSessionID] [varchar](40) NULL,
	[TMCounter] [int] NULL,
 CONSTRAINT [PK_ImportLog] PRIMARY KEY CLUSTERED 
(
	[ID] ASC
) ON [PRIMARY]
) ON [PRIMARY]
GO

SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [LoadedPositions](
	[PosID] [int] NOT NULL,
	[PosType] [int] NOT NULL,
	[FirmID] [varchar](12) NULL,
	[ActiveCode] [varchar](12) NULL,
	[ClientCode] [varchar](12) NULL,
	[LimitKind] [int] NULL,
	[OpenBalance] [decimal](19, 6) NULL,
 CONSTRAINT [PK_LoadedPositions] PRIMARY KEY CLUSTERED 
(
	[PosID] ASC
) ON [PRIMARY]
) ON [PRIMARY]
GO

SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [LoadedSecurities](
	[SecID] [int] NOT NULL,
	[SecCode] [varchar](12) NULL,
	[SecName] [varchar](16) NULL,
	[SecStyle] [varchar](16) NULL,
	[SecType] [varchar](32) NULL,
	[FaceValue] [decimal](19, 4) NULL,
	[AccInt] [decimal](19, 4) NULL,
	[Price] [decimal](19, 6) NULL,
 CONSTRAINT [PK_LoadedSecurities] PRIMARY KEY CLUSTERED 
(
	[SecID] ASC
) ON [PRIMARY]
) ON [PRIMARY]

SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [LoadedSecuritiesClientPrices](
	[ClientID] [int] NOT NULL,
	[SecID] [int] NOT NULL,
	[Code] [varchar](12) NULL,
	[CodeType] [int] NULL,
	[Price] [decimal](19, 6) NULL,
 CONSTRAINT [PK_LoadedSecuritiesClientPrices] PRIMARY KEY CLUSTERED 
(
	[ClientID] ASC
) ON [PRIMARY]
) ON [PRIMARY]
GO

SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [NegOrders](
	[OrderId] [int] NOT NULL,
	[GroupOrderID] [int] NULL,
	[TradeDate] [int] NULL,
	[TradeTime] [int] NULL,
	[Buy] [BuySell] NULL,
	[ClassCode] [varchar](12) COLLATE Cyrillic_General_CI_AS NULL,
	[SecCode] [varchar](12) COLLATE Cyrillic_General_CI_AS NULL,
	[ClientCode] [varchar](12) COLLATE Cyrillic_General_CI_AS NULL,
	[TrdAcc] [varchar](12) COLLATE Cyrillic_General_CI_AS NULL,
	[CPFirmId] [varchar](12) COLLATE Cyrillic_General_CI_AS NULL,
	[SettleCode] [varchar](12) COLLATE Cyrillic_General_CI_AS NULL,
	[MatchRef] [varchar](10) COLLATE Cyrillic_General_CI_AS NULL,
	[Price] [float] NULL,
	[Vozm] [float] NULL,
	[Qty] [float] NULL,
	[OrderNum] [float] NULL,
	[Status] [char](1) COLLATE Cyrillic_General_CI_AS NULL,
	[Result] [char](1) COLLATE Cyrillic_General_CI_AS NULL,
	[RepoValue] [float] NULL,
	[Discount] [float] NULL,
	[DiscountUpper] [float] NULL,
	[DiscountLower] [float] NULL,
	[RepoRate] [float] NULL,
	[RepoTerm] [int] NULL,
	[Flags] [int] NULL,
	[TMUserID] [int] NULL,
	[TMSessionID] [varchar](40) COLLATE Cyrillic_General_CI_AS NULL,
	[TMCounter] [int] NULL,
 CONSTRAINT [NegOrders_PK] PRIMARY KEY NONCLUSTERED 
(
	[OrderId] ASC
) ON [PRIMARY]
) ON [PRIMARY]
GO

SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [Orders](
	[OrderID] [int] NOT NULL,
	[GroupOrderID] [int] NOT NULL,
	[Buy] [BuySell] NOT NULL,
	[ML] [char](1) COLLATE Cyrillic_General_CI_AS NOT NULL,
	[TradeDate] [int] NOT NULL,
	[TradeTime] [int] NOT NULL,
	[SecCode] [varchar](12) COLLATE Cyrillic_General_CI_AS NOT NULL,
	[ClassCode] [varchar](12) COLLATE Cyrillic_General_CI_AS NOT NULL,
	[ClientCode] [varchar](12) COLLATE Cyrillic_General_CS_AS NOT NULL,
	[TrdAcc] [varchar](12) COLLATE Cyrillic_General_CI_AS NULL,
	[Price] [float] NOT NULL,
	[Qty] [float] NOT NULL,
	[BalanceQty] [float] NOT NULL,
	[OrderNum] [float] NOT NULL,
	[Status] [char](1) COLLATE Cyrillic_General_CI_AS NULL,
	[Result] [char](1) COLLATE Cyrillic_General_CI_AS NOT NULL,
	[OrderInPoolID] [int] NULL,
	[Value] [float] NULL,
	[VisibleQty] [float] NULL,
	[TMUserID] [int] NULL,
	[TMSessionID] [varchar](40) COLLATE Cyrillic_General_CI_AS NULL,
	[TMCounter] [int] NULL,
 CONSTRAINT [Orders_PK] PRIMARY KEY NONCLUSTERED 
(
	[OrderID] ASC
) ON [PRIMARY]
) ON [PRIMARY]
GO
SET ANSI_PADDING OFF
GO
CREATE NONCLUSTERED INDEX [GroupOrdersOrders] ON [Orders] 
(
	[GroupOrderID] ASC
) ON [PRIMARY]
GO

SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [OrdersInPool](
	[OrderID] [int] IDENTITY(1,1) NOT NULL,
	[PoolID] [int] NOT NULL,
	[OrderType] [char](1) COLLATE Cyrillic_General_CI_AS NOT NULL,
	[ClientCode] [varchar](12) COLLATE Cyrillic_General_CS_AS NOT NULL,
	[ClassCode] [varchar](12) COLLATE Cyrillic_General_CI_AS NOT NULL,
	[SecCode] [varchar](12) COLLATE Cyrillic_General_CI_AS NOT NULL,
	[Price] [float] NULL,
	[Qty] [float] NOT NULL,
	[Buy] [BuySell] NOT NULL,
	[ML] [char](1) COLLATE Cyrillic_General_CI_AS NOT NULL,
	[SendQty] [float] NOT NULL,
	[ExecQty] [float] NOT NULL,
	[RejectQty] [float] NOT NULL,
	[KillQty] [float] NOT NULL,
	[ActiveQty] [float] NULL,
	[Comment] [varchar](20) COLLATE Cyrillic_General_CI_AS NULL,
 CONSTRAINT [PK_OrdersInPool] PRIMARY KEY CLUSTERED 
(
	[OrderID] ASC
) ON [PRIMARY]
) ON [PRIMARY]
GO
SET ANSI_PADDING OFF
GO
CREATE NONCLUSTERED INDEX [IX_OrdersInPool_Clients] ON [OrdersInPool] 
(
	[ClientCode] ASC
) ON [PRIMARY]
GO
CREATE NONCLUSTERED INDEX [IX_OrdersInPool_PoolID] ON [OrdersInPool] 
(
	[PoolID] ASC
) ON [PRIMARY]
GO

SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [PoolOrders](
	[PoolID] [int] IDENTITY(1,1) NOT NULL,
	[BrokerPoolID] [varchar](32) COLLATE Cyrillic_General_CS_AS NOT NULL,
	[PoolName] [varchar](128) COLLATE Cyrillic_General_CI_AS NULL,
	[LoadDate] [int] NOT NULL,
	[LoadTime] [int] NOT NULL,
	[ExpireDate] [int] NOT NULL,
	[Source] [varchar](250) COLLATE Cyrillic_General_CI_AS NULL,
	[Status] [varchar](50) COLLATE Cyrillic_General_CI_AS NULL,
	[KillTime] [int] NULL,
	[TotalQty] [float] NULL,
	[SendQty] [float] NULL,
	[ExecQty] [float] NULL,
	[RejectQty] [float] NULL,
	[KilledQty] [float] NULL,
	[ActiveQty] [float] NULL,
 CONSTRAINT [PK_PoolOrders] PRIMARY KEY CLUSTERED 
(
	[PoolID] ASC
)WITH FILLFACTOR = 90 ON [PRIMARY]
) ON [PRIMARY]
GO
SET ANSI_PADDING OFF
GO
CREATE UNIQUE NONCLUSTERED INDEX [IX_PoolOrders_BrokerID] ON [PoolOrders] 
(
	[BrokerPoolID] ASC
)WITH FILLFACTOR = 90 ON [PRIMARY]
GO
CREATE NONCLUSTERED INDEX [IX_PoolOrders_Date] ON [PoolOrders] 
(
	[LoadDate] ASC
)WITH FILLFACTOR = 90 ON [PRIMARY]
GO

SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [RatingAgencies](
	[AgencyID] [int] IDENTITY(1,1) NOT NULL,
	[AgencyCode] [varchar](20) COLLATE Cyrillic_General_CI_AS NOT NULL,
	[AgencyName] [varchar](128) COLLATE Cyrillic_General_CI_AS NULL,
 CONSTRAINT [PK_RatingAgencies] PRIMARY KEY CLUSTERED 
(
	[AgencyID] ASC
) ON [PRIMARY]
) ON [PRIMARY]
GO
SET ANSI_PADDING OFF
GO
CREATE UNIQUE NONCLUSTERED INDEX [IX_RatingAgencies_AgencyCode] ON [RatingAgencies] 
(
	[AgencyCode] ASC
) ON [PRIMARY]
GO

SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [RatingScales](
	[RatingID] [int] IDENTITY(1,1) NOT NULL,
	[AgencyID] [int] NOT NULL,
	[National] [int] NOT NULL,
	[Rating] [varchar](20) COLLATE Cyrillic_General_CI_AS NOT NULL,
	[Position] [int] NOT NULL,
 CONSTRAINT [PK_RatingScales] PRIMARY KEY CLUSTERED 
(
	[RatingID] ASC
) ON [PRIMARY]
) ON [PRIMARY]
GO
SET ANSI_PADDING OFF
GO
CREATE UNIQUE NONCLUSTERED INDEX [IX_RatingScales_AgencyNational] ON [RatingScales] 
(
	[AgencyID] ASC,
	[National] ASC,
	[Rating] ASC
) ON [PRIMARY]
GO

SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [Restrictions](
	[ID] [int] NOT NULL,
	[RestType] [char](1) COLLATE Cyrillic_General_CI_AS NULL,
	[Client] [varchar](20) COLLATE Cyrillic_General_CS_AS NULL,
	[Mode] [varchar](10) COLLATE Cyrillic_General_CI_AS NULL,
	[Limit] [float] NULL,
	[SecGroupID] [int] NULL,
	[CoSecGroupID] [int] NULL,
	[disabled] [DisabledFlag] NOT NULL,
	[Value] [decimal](19, 4) NULL,
	[NoCheck] [int] NULL,
	[TMUserID] [int] NULL,
	[TMSessionID] [varchar](40) COLLATE Cyrillic_General_CI_AS NULL,
	[TMCounter] [int] NULL,
	[LimitKind] [int] NULL,
	[RestrCode] [varchar](12) NULL,
	[RestrName] [varchar](50) NULL,
 CONSTRAINT [PK_Restrictions] PRIMARY KEY CLUSTERED 
(
	[ID] ASC
) ON [PRIMARY]
) ON [PRIMARY]
GO

SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [SecGrMemb](
	[GroupID] [int] NULL,
	[MembType] [char](1) COLLATE Cyrillic_General_CI_AS NULL,
	[MembCode] [varchar](20) COLLATE Cyrillic_General_CI_AS NULL,
	[MembClass] [varchar](20) COLLATE Cyrillic_General_CI_AS NULL,
	[MembID] [int] NULL
) ON [PRIMARY]
GO

SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [SecGroups](
	[ID] [int] NOT NULL,
	[SecGCode] [varchar](64) COLLATE Cyrillic_General_CI_AS NULL,
	[SecGName] [varchar](255) COLLATE Cyrillic_General_CI_AS NULL,
	[disabled] [DisabledFlag] NOT NULL,
	[Filter] [varchar](10) COLLATE Cyrillic_General_CI_AS NULL,
	[mode] [varchar](10) COLLATE Cyrillic_General_CI_AS NULL,
	[RAgencies] [int] NULL,
	[ListLevel] [int] NULL,
 CONSTRAINT [PK_SecGroups] PRIMARY KEY CLUSTERED 
(
	[ID] ASC
) ON [PRIMARY]
) ON [PRIMARY]
GO

SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [SecMinQt](
	[ClassCode] [varchar](12) COLLATE Cyrillic_General_CI_AS NOT NULL,
	[SecCode] [varchar](12) COLLATE Cyrillic_General_CI_AS NOT NULL,
	[MinQty] [int] NOT NULL
) ON [PRIMARY]
GO

SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [StopOrders](
	[OrderID] [int] NOT NULL,
	[GroupOrderID] [int] NOT NULL,
	[StopStyle] [int] NULL,
	[Buy] [BuySell] NOT NULL,
	[ML] [char](1) COLLATE Cyrillic_General_CI_AS NOT NULL,
	[TradeDate] [int] NOT NULL,
	[TradeTime] [int] NOT NULL,
	[SecCode] [varchar](12) COLLATE Cyrillic_General_CI_AS NOT NULL,
	[ClassCode] [varchar](12) COLLATE Cyrillic_General_CI_AS NOT NULL,
	[ASecCode] [varchar](12) COLLATE Cyrillic_General_CI_AS NULL,
	[AClassCode] [varchar](12) COLLATE Cyrillic_General_CI_AS NULL,
	[StopCond] [int] NULL,
	[TransFlags] [int] NULL,
	[ClientCode] [varchar](12) COLLATE Cyrillic_General_CS_AS NOT NULL,
	[StopPrice] [float] NOT NULL,
	[Price] [float] NOT NULL,
	[LinkedPrice] [float] NULL,
	[Offset] [float] NULL,
	[Spread] [float] NULL,
	[Qty] [float] NOT NULL,
	[Balance] [float] NULL,
	[StopOrderNum] [float] NOT NULL,
	[LinkedOrderNum] [float] NOT NULL,
	[BaseOrderNum] [float] NULL,
	[CoOrderNum] [float] NULL,
	[Status] [char](1) COLLATE Cyrillic_General_CI_AS NULL,
	[Result] [char](1) COLLATE Cyrillic_General_CI_AS NOT NULL,
	[Expire] [int] NULL,
	[StopPrice2] [float] NULL,
	[ActiveFromTime] [int] NULL,
	[ActiveToTime] [int] NULL,
	[TrdAcc] [varchar](12) COLLATE Cyrillic_General_CI_AS NULL,
 CONSTRAINT [StopOrders_PK] PRIMARY KEY NONCLUSTERED 
(
	[OrderID] ASC
) ON [PRIMARY]
) ON [PRIMARY]
GO

SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [SystemCounters](
	[TableName] [varchar](32) COLLATE Cyrillic_General_CI_AS NOT NULL,
	[Counter] [int] NOT NULL,
 CONSTRAINT [PK_SystemCounters] PRIMARY KEY CLUSTERED 
(
	[TableName] ASC
) ON [PRIMARY]
) ON [PRIMARY]
GO

SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [SystemData](
	[KeyName] [varchar](20) COLLATE Cyrillic_General_CI_AS NULL,
	[KeyValue] [varchar](50) COLLATE Cyrillic_General_CI_AS NULL
) ON [PRIMARY]
GO

/* Различные настройки таблиц */

ALTER TABLE [SecGrMemb] ADD  CONSTRAINT [DF_SecGrMemb_MembID]  DEFAULT ((-1)) FOR [MembID]
GO
ALTER TABLE [SecMinQt] ADD  CONSTRAINT [DF__SecMinQt__MinQty__0F975522]  DEFAULT (1) FOR [MinQty]
GO
ALTER TABLE [Clients] ADD  CONSTRAINT [DF_Clients_GroupID]  DEFAULT (0) FOR [GroupID]
GO
ALTER TABLE [Clients] ADD  CONSTRAINT [DF_Clients_Num]  DEFAULT (0) FOR [Num]
GO
ALTER TABLE [Clients] ADD  CONSTRAINT [DF_Clients_Weight]  DEFAULT ((-1)) FOR [Weight]
GO
ALTER TABLE [Orders] ADD  CONSTRAINT [DF_Orders_GroupOrderID]  DEFAULT (0) FOR [GroupOrderID]
GO
ALTER TABLE [Orders] ADD  CONSTRAINT [DF_Orders_TradeDate]  DEFAULT (0) FOR [TradeDate]
GO
ALTER TABLE [Orders] ADD  CONSTRAINT [DF_Orders_TradeTime]  DEFAULT (0) FOR [TradeTime]
GO
ALTER TABLE [Orders] ADD  CONSTRAINT [DF_Orders_Price]  DEFAULT (0) FOR [Price]
GO
ALTER TABLE [Orders] ADD  CONSTRAINT [DF_Orders_Qty]  DEFAULT (0) FOR [Qty]
GO
ALTER TABLE [Orders] ADD  CONSTRAINT [DF_Orders_BalanceQty]  DEFAULT (0) FOR [BalanceQty]
GO
ALTER TABLE [Orders] ADD  CONSTRAINT [DF_Orders_OrderNum]  DEFAULT ((-1)) FOR [OrderNum]
GO
ALTER TABLE [Orders] ADD  CONSTRAINT [DF_Orders_Status]  DEFAULT ('0') FOR [Status]
GO
ALTER TABLE [Orders] ADD  CONSTRAINT [DF_Orders_Result]  DEFAULT ('0') FOR [Result]
GO
ALTER TABLE [Restrictions] ADD CONSTRAINT [DF_Restrictions_LimitKind] DEFAULT (0) FOR [LimitKind]
GO
ALTER TABLE [StopOrders] ADD  CONSTRAINT [DF_StopOrder_GroupOrderID]  DEFAULT (0) FOR [GroupOrderID]
GO
ALTER TABLE [StopOrders] ADD  CONSTRAINT [DF_StopOrder_StopStyle]  DEFAULT (0) FOR [StopStyle]
GO
ALTER TABLE [StopOrders] ADD  CONSTRAINT [DF_StopOrder_TradeDate]  DEFAULT (0) FOR [TradeDate]
GO
ALTER TABLE [StopOrders] ADD  CONSTRAINT [DF_StopOrder_TradeTime]  DEFAULT (0) FOR [TradeTime]
GO
ALTER TABLE [StopOrders] ADD  CONSTRAINT [DF_StopOrder_StopCond]  DEFAULT (0) FOR [StopCond]
GO
ALTER TABLE [StopOrders] ADD  CONSTRAINT [DF_StopOrder_TransFlags]  DEFAULT (0) FOR [TransFlags]
GO
ALTER TABLE [StopOrders] ADD  CONSTRAINT [DF_StopOrder_StopPrice]  DEFAULT (0) FOR [StopPrice]
GO
ALTER TABLE [StopOrders] ADD  CONSTRAINT [DF_StopOrder_Price]  DEFAULT (0) FOR [Price]
GO
ALTER TABLE [StopOrders] ADD  CONSTRAINT [DF_StopOrder_LinkedPrice]  DEFAULT (0) FOR [LinkedPrice]
GO
ALTER TABLE [StopOrders] ADD  CONSTRAINT [DF_StopOrder_Offset]  DEFAULT (0) FOR [Offset]
GO
ALTER TABLE [StopOrders] ADD  CONSTRAINT [DF_StopOrder_Spread]  DEFAULT (0) FOR [Spread]
GO
ALTER TABLE [StopOrders] ADD  CONSTRAINT [DF_StopOrders_Qty]  DEFAULT (0) FOR [Qty]
GO
ALTER TABLE [StopOrders] ADD  CONSTRAINT [DF_StopOrder_Balance]  DEFAULT (0) FOR [Balance]
GO
ALTER TABLE [StopOrders] ADD  CONSTRAINT [DF_StopOrder_StopOrderNum]  DEFAULT ((-1)) FOR [StopOrderNum]
GO
ALTER TABLE [StopOrders] ADD  CONSTRAINT [DF_StopOrder_LinkedOrderNum]  DEFAULT ((-1)) FOR [LinkedOrderNum]
GO
ALTER TABLE [StopOrders] ADD  CONSTRAINT [DF_StopOrder_BaseOrderNum]  DEFAULT ((-1)) FOR [BaseOrderNum]
GO
ALTER TABLE [StopOrders] ADD  CONSTRAINT [DF_StopOrder_CoOrderNum]  DEFAULT ((-1)) FOR [CoOrderNum]
GO
ALTER TABLE [StopOrders] ADD  CONSTRAINT [DF_StopOrder_Status]  DEFAULT ('0') FOR [Status]
GO
ALTER TABLE [StopOrders] ADD  CONSTRAINT [DF_StopOrder_Result]  DEFAULT ('0') FOR [Result]
GO
ALTER TABLE [GroupOrders] ADD  CONSTRAINT [DF__GroupOrde__Group__4AB81AF0]  DEFAULT (0) FOR [GroupID]
GO
ALTER TABLE [GroupOrders] ADD  CONSTRAINT [DF__GroupOrde__Trade__4BAC3F29]  DEFAULT (0) FOR [TradeDate]
GO
ALTER TABLE [GroupOrders] ADD  CONSTRAINT [DF__GroupOrde__Trade__4CA06362]  DEFAULT (0) FOR [TradeTime]
GO
ALTER TABLE [GroupOrders] ADD  CONSTRAINT [DF__GroupOrde__Price__4D94879B]  DEFAULT (0) FOR [Price]
GO
ALTER TABLE [GroupOrders] ADD  CONSTRAINT [DF__GroupOrders__Qty__4E88ABD4]  DEFAULT (0) FOR [Qty]
GO
ALTER TABLE [GroupOrders] ADD  CONSTRAINT [DF__GroupOrde__RealQ__4F7CD00D]  DEFAULT (0) FOR [RealQty]
GO
ALTER TABLE [GroupOrders] ADD  CONSTRAINT [DF__GroupOrde__Balan__5070F446]  DEFAULT (0) FOR [BalanceQty]
GO
ALTER TABLE [GroupOrders] ADD  CONSTRAINT [DF__GroupOrde__Kille__5165187F]  DEFAULT (0) FOR [KilledQty]
GO
ALTER TABLE [GroupOrders] ADD  CONSTRAINT [DF__GroupOrde__Statu__52593CB8]  DEFAULT ('0') FOR [Status]
GO
ALTER TABLE [GroupOrders] ADD  CONSTRAINT [DF__GroupOrde__Resul__534D60F1]  DEFAULT ('0') FOR [Result]
GO
ALTER TABLE [GroupOrders] ADD  CONSTRAINT [DF__GroupOrde__Order__5441852A]  DEFAULT (0) FOR [OrdersCount]
GO
ALTER TABLE [GroupStopOrders] ADD  CONSTRAINT [DF__GroupStop__Group__32E0915F]  DEFAULT (0) FOR [GroupID]
GO
ALTER TABLE [GroupStopOrders] ADD  CONSTRAINT [DF__GroupStop__StopS__33D4B598]  DEFAULT (0) FOR [StopStyle]
GO
ALTER TABLE [GroupStopOrders] ADD  CONSTRAINT [DF__GroupStop__Trade__34C8D9D1]  DEFAULT (0) FOR [TradeDate]
GO
ALTER TABLE [GroupStopOrders] ADD  CONSTRAINT [DF__GroupStop__Trade__35BCFE0A]  DEFAULT (0) FOR [TradeTime]
GO
ALTER TABLE [GroupStopOrders] ADD  CONSTRAINT [DF__GroupStop__StopC__36B12243]  DEFAULT (0) FOR [StopCond]
GO
ALTER TABLE [GroupStopOrders] ADD  CONSTRAINT [DF__GroupStop__Trans__37A5467C]  DEFAULT (0) FOR [TransFlags]
GO
ALTER TABLE [GroupStopOrders] ADD  CONSTRAINT [DF__GroupStop__StopP__38996AB5]  DEFAULT (0) FOR [StopPrice]
GO
ALTER TABLE [GroupStopOrders] ADD  CONSTRAINT [DF__GroupStop__Price__398D8EEE]  DEFAULT (0) FOR [Price]
GO
ALTER TABLE [GroupStopOrders] ADD  CONSTRAINT [DF__GroupStop__Linke__3A81B327]  DEFAULT (0) FOR [LinkedPrice]
GO
ALTER TABLE [GroupStopOrders] ADD  CONSTRAINT [DF__GroupStop__Offse__3B75D760]  DEFAULT (0) FOR [Offset]
GO
ALTER TABLE [GroupStopOrders] ADD  CONSTRAINT [DF__GroupStop__Sprea__3C69FB99]  DEFAULT (0) FOR [Spread]
GO
ALTER TABLE [GroupStopOrders] ADD  CONSTRAINT [DF__GroupStopOr__Qty__3D5E1FD2]  DEFAULT (0) FOR [Qty]
GO
ALTER TABLE [GroupStopOrders] ADD  CONSTRAINT [DF__GroupStop__RealQ__3E52440B]  DEFAULT (0) FOR [RealQty]
GO
ALTER TABLE [GroupStopOrders] ADD  CONSTRAINT [DF__GroupStop__Balan__3F466844]  DEFAULT (0) FOR [BalanceQty]
GO
ALTER TABLE [GroupStopOrders] ADD  CONSTRAINT [DF__GroupStop__Kille__403A8C7D]  DEFAULT (0) FOR [KilledQty]
GO
ALTER TABLE [GroupStopOrders] ADD  CONSTRAINT [DF__GroupStop__BaseO__412EB0B6]  DEFAULT ((-1)) FOR [BaseOrderNum]
GO
ALTER TABLE [GroupStopOrders] ADD  CONSTRAINT [DF__GroupStop__Statu__4222D4EF]  DEFAULT ('0') FOR [Status]
GO
ALTER TABLE [GroupStopOrders] ADD  CONSTRAINT [DF__GroupStop__Resul__4316F928]  DEFAULT ('0') FOR [Result]
GO
ALTER TABLE [GroupStopOrders] ADD  CONSTRAINT [DF__GroupStop__Order__440B1D61]  DEFAULT (0) FOR [OrdersCount]
GO
ALTER TABLE [GroupStopOrders] ADD  CONSTRAINT [DF__GroupStop__Linke__44FF419A]  DEFAULT ((-1)) FOR [LinkedGrOrder]
GO
ALTER TABLE [GroupStopOrders] ADD  CONSTRAINT [DF__GroupStop__CoOrd__45F365D3]  DEFAULT ((-1)) FOR [CoOrderNum]
GO
ALTER TABLE [NegOrders] ADD  CONSTRAINT [DF__NegOrders__Group__286302EC]  DEFAULT (0) FOR [GroupOrderID]
GO
ALTER TABLE [NegOrders] ADD  CONSTRAINT [DF__NegOrders__Trade__29572725]  DEFAULT (0) FOR [TradeDate]
GO
ALTER TABLE [NegOrders] ADD  CONSTRAINT [DF__NegOrders__Trade__2A4B4B5E]  DEFAULT (0) FOR [TradeTime]
GO
ALTER TABLE [NegOrders] ADD  CONSTRAINT [DF__NegOrders__Price__2B3F6F97]  DEFAULT (0) FOR [Price]
GO
ALTER TABLE [NegOrders] ADD  CONSTRAINT [DF__NegOrders__Vozm__2C3393D0]  DEFAULT (0) FOR [Vozm]
GO
ALTER TABLE [NegOrders] ADD  CONSTRAINT [DF__NegOrders__Qty__2D27B809]  DEFAULT (0) FOR [Qty]
GO
ALTER TABLE [NegOrders] ADD  CONSTRAINT [DF__NegOrders__Order__2E1BDC42]  DEFAULT (0) FOR [OrderNum]
GO
ALTER TABLE [GroupNegOrders] ADD  CONSTRAINT [DF__GroupNegO__Group__59063A47]  DEFAULT (0) FOR [GroupID]
GO
ALTER TABLE [GroupNegOrders] ADD  CONSTRAINT [DF__GroupNegO__Trade__59FA5E80]  DEFAULT (0) FOR [TradeDate]
GO
ALTER TABLE [GroupNegOrders] ADD  CONSTRAINT [DF__GroupNegO__Trade__5AEE82B9]  DEFAULT (0) FOR [TradeTime]
GO
ALTER TABLE [GroupNegOrders] ADD  CONSTRAINT [DF__GroupNegO__Price__5BE2A6F2]  DEFAULT (0) FOR [Price]
GO
ALTER TABLE [GroupNegOrders] ADD  CONSTRAINT [DF__GroupNegOr__Vozm__5CD6CB2B]  DEFAULT (0) FOR [Vozm]
GO
ALTER TABLE [GroupNegOrders] ADD  CONSTRAINT [DF__GroupNegOrd__Qty__5DCAEF64]  DEFAULT (0) FOR [Qty]
GO
ALTER TABLE [GroupNegOrders] ADD  CONSTRAINT [DF__GroupNegO__RealQ__5EBF139D]  DEFAULT (0) FOR [RealQty]
GO
ALTER TABLE [GroupNegOrders] ADD  CONSTRAINT [DF__GroupNegO__Kille__5FB337D6]  DEFAULT (0) FOR [KilledQty]
GO
ALTER TABLE [GroupNegOrders] ADD  CONSTRAINT [DF__GroupNegO__Order__60A75C0F]  DEFAULT (0) FOR [OrdersCount]
GO
ALTER TABLE [GroupDesc] ADD  CONSTRAINT [DF_GroupDesc_DefWeight]  DEFAULT ((-1)) FOR [DefWeight]
GO
ALTER TABLE [GroupDesc] ADD  CONSTRAINT [DF_GroupDesc_SplitOrders]  DEFAULT (1) FOR [SplitOrders]
GO
ALTER TABLE [SecMinQt]  WITH CHECK ADD  CONSTRAINT [CK_SecMinQt_MinQty] CHECK  (([MinQty] >= 1))
GO
ALTER TABLE [SecMinQt] CHECK CONSTRAINT [CK_SecMinQt_MinQty]
GO
ALTER TABLE [Clients]  WITH NOCHECK ADD  CONSTRAINT [Clients_FK00] FOREIGN KEY([GroupID])
REFERENCES [GroupDesc] ([GroupID])
GO
ALTER TABLE [Clients] CHECK CONSTRAINT [Clients_FK00]
GO
ALTER TABLE [LoadedSecuritiesClientPrices] WITH NOCHECK ADD CONSTRAINT [FK_LoadedSecuritiesClientPrices_LoadedSecurities] FOREIGN KEY([SecID])
REFERENCES [LoadedSecurities]([SecID])
GO
ALTER TABLE [Orders]  WITH NOCHECK ADD  CONSTRAINT [Orders_FK00] FOREIGN KEY([GroupOrderID])
REFERENCES [GroupOrders] ([ID])
GO
ALTER TABLE [Orders] CHECK CONSTRAINT [Orders_FK00]
GO
ALTER TABLE [OrdersInPool]  WITH NOCHECK ADD  CONSTRAINT [FK_OrdersInPool_PoolOrders] FOREIGN KEY([PoolID])
REFERENCES [PoolOrders] ([PoolID])
GO
ALTER TABLE [OrdersInPool] CHECK CONSTRAINT [FK_OrdersInPool_PoolOrders]
GO
ALTER TABLE [GroupOrders]  WITH NOCHECK ADD  CONSTRAINT [GroupOrders_FK00] FOREIGN KEY([GroupID])
REFERENCES [GroupDesc] ([GroupID])
GO
ALTER TABLE [GroupOrders] CHECK CONSTRAINT [GroupOrders_FK00]
GO

/* Хранимые процедуры */

SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [TM_CreateOrderInPool]
  @PoolID int,
  @OrderType char(1),
  @ClientCode varchar(12),
  @ClassCode varchar(12),
  @SecCode varchar(12),
  @Price float,
  @Qty float,
  @Buy char(1),
  @ML char(1),
  @SendQty float,
  @ExecQty float,
  @RejectQty float,
  @KillQty float,
  @ActiveQty float,
  @Comment varchar(20),
  @OrderID int OUTPUT
AS
  begin tran;
    -- вставляем запись
    insert into [OrdersInPool] (PoolID, OrderType, ClientCode, ClassCode, SecCode, Price, Qty, Buy, ML, SendQty, ExecQty,
                                                        RejectQty, KillQty, ActiveQty, Comment)
    values (@PoolID, @OrderType, @ClientCode, @ClassCode, @SecCode, @Price, @Qty, @Buy, @ML, @SendQty, @ExecQty,
                                                        @RejectQty, @KillQty, @ActiveQty, @Comment);
    -- определим ID новой записи
    set @OrderID = @@IDENTITY;
  commit tran;
GO

CREATE PROCEDURE [DeleteRestriction]
  @ID int , -- идентификатор ограничения, которое необходимо удалить
  @Res int OUTPUT  -- 1 - успешно, 0 - неуспешно
AS
   set @Res = 0;

  if not exists (select * from Restrictions where [ID]=@ID and disabled='n')
    return;

  update Restrictions
  set disabled='y'
  where [ID]=@ID and disabled='n';

  set @Res=1;
GO

CREATE PROCEDURE [TM_CreateStopOrder]
  @GroupOrderID int,
  @StopStyle int,
  @TradeDate int,
  @TradeTime int,
  @Buy char(1),
  @ML char(1),
  @SecCode varchar(12),
  @ClassCode varchar(12),
  @ASecCode varchar(12),
  @AClassCode varchar(12),
  @StopCond int,
  @TransFlags int,
  @ClientCode varchar(12),
  @TrdAcc varchar(12),
  @StopPrice float,
  @Price float,
  @LinkedPrice float,
  @Offset float,
  @Spread float,
  @Qty float,
  @Balance float,
  @StopOrderNum float,
  @LinkedOrderNum float,
  @BaseOrderNum float,
  @CoOrderNum float,
  @Status char(1),
  @Result char(1),
  @Expire int,
  @StopPrice2 float,
  @ActiveFromTime int,
  @ActiveToTime int,
  @StopOrderID int OUTPUT
AS
  begin tran;
    -- определим ID новой записи
    set @StopOrderID = (select max(OrderID)+1 from StopOrders);
    if @StopOrderID is NULL
      set @StopOrderID=1;
    -- вставляем запись
    insert into [StopOrders] (OrderID, GroupOrderID, StopStyle, TradeDate, TradeTime, Buy, ML, SecCode, ClassCode, ASecCode, AClassCode,
                                                                  StopCond, TransFlags, ClientCode, TrdAcc, StopPrice, Price, LinkedPrice, Offset, Spread, Qty, Balance,
                                                                  StopOrderNum, LinkedOrderNum, BaseOrderNum, CoOrderNum, Status, Result, [Expire], StopPrice2, ActiveFromTime, ActiveToTime)
    values (@StopOrderID, @GroupOrderID, @StopStyle, @TradeDate, @TradeTime, @Buy, @ML, @SecCode, @ClassCode, @ASecCode, @AClassCode,
                                                                  @StopCond, @TransFlags, @ClientCode, @TrdAcc, @StopPrice, @Price, @LinkedPrice, @Offset, @Spread, @Qty, @Balance,
                                                                  @StopOrderNum, @LinkedOrderNum, @BaseOrderNum, @CoOrderNum, @Status, @Result, @Expire, @StopPrice2, @ActiveFromTime, @ActiveToTime);
  commit tran;
GO

CREATE PROCEDURE [TM_CreateRatingAgency]
  @AgencyCode varchar(20),
  @AgencyName varchar(128),
  @AgencyID int OUTPUT
AS
  begin tran;
    -- вставляем запись
    insert into [RatingAgencies] (AgencyCode, AgencyName)
    values (@AgencyCode, @AgencyName);
    -- определим ID новой записи
    set @AgencyID = @@IDENTITY;
  commit tran;
GO

CREATE PROCEDURE [CreateNewSecGroupMember] 
  @SecGroupID int, -- идентификатор группы инструментов, в которую добавляется элемент
  @MemberType char(1), -- тип элемента:
                       -- <S> - инструмент
                       -- <C> - класс инструментов
                       -- <G> - группа инструментов
                       -- <E> - все инструменты, кроме указанной группы инструментов
                       -- <R> - рейтинг от некоторого рейтингового агентства
  @MemberCode varchar(20), -- для элементов типа <S> - код инструмента
                           -- для элементов типа <C> - код класса инструментов
                           -- для элементов типа  <R> - код агентства
                           -- для прочих элементов пустая строка
  @MemberClass varchar(20), -- для элементов типа <S> - код класса инструментов (в который входит инструмент)
                            -- для элементов типа <R> - рейтинг
                            -- для прочих элементов пустая строка
  @MemberID int, -- для элементов типа <G> и <E> - идентификатор группы инструментов
                 -- для элементов типа  <R> - тип шкалы (0 для международной, 1 для национальной)
                 -- для прочих элементов указывается -1
  @Success int OUTPUT -- возвращает 1 в случае успеха и 0 в противном случае
AS
BEGIN
  declare @GroupModeRatings int;
  declare @RMode varchar(10);
  set NOCOUNT ON;
	
  set @Success = 0;

  if not exists (select * from SecGroups where [ID]=@SecGroupID and disabled='n')
    return;

  set @RMode = (select [Mode] from SecGroups where [ID]=@SecGroupID and disabled='n');

  if charindex('R', @RMode)=0
    set @GroupModeRatings=0
  else
    set @GroupModeRatings=1;

  if @MemberType='R' begin
    -- проверка на корректность типа группы инструментов
    if @GroupModeRatings=0
      return;
    -- проверка на корректность кода рейтингового агентства и наличия указанного рейтинга
    if not exists (select * from RatingAgencies where AgencyCode=@MemberCode)
      return;
    if not exists (select rs.* from RatingAgencies ra, RatingScales rs
                   where ra.AgencyID=rs.AgencyID and ra.AgencyCode=@MemberCode and
                         rs.Rating=@MemberClass and rs.[National]=@MemberID)
      return;
  end
  else begin
    -- проверка на корректность типа группы инструментов
    if @GroupModeRatings=1
      return;
  end
	
  insert into SecGrMemb (GroupID, MembType, MembCode, MembClass, MembID)
  values (@SecGroupID, @MemberType, @MemberCode, @MemberClass, @MemberID);

  set @Success = 1;
END
GO

CREATE PROCEDURE [DeleteSecGroupMember]
  @SecGroupID int, -- идентификатор группы инструментов, в которую добавляется элемент
  @MemberType char(1), -- тип элемента:
                       -- <S> - инструмент
                       -- <C> - класс инструментов
                       -- <G> - группа инструментов
                       -- <E> - все инструменты, кроме указанной группы инструментов
                       -- <R> - рейтинг от некоторого рейтингового агентства
  @MemberCode varchar(20), -- для элементов типа <S> - код инструмента
                           -- для элементов типа <C> - код класса инструментов
                           -- для элементов типа  <R> - код агентства
                           -- для прочих элементов пустая строка
  @MemberClass varchar(20), -- для элементов типа <S> - код класса инструментов (в который входит инструмент)
                            -- для элементов типа <R> - рейтинг
                            -- для прочих элементов пустая строка
  @MemberID int, -- для элементов типа <G> и <E> - идентификатор группы инструментов
                 -- для элементов типа  <R> - тип шкалы (0 для международной, 1 для национальной)
                 -- для прочих элементов указывается -1
  @Success int OUTPUT -- возвращает 1 в случае успеха и 0 в противном случае
AS
BEGIN
  set NOCOUNT ON;
	
  set @Success = 0;

  delete from SecGrMemb
  where GroupID=@SecGroupID and MembType=@MemberType and
        MembCode=@MemberCode and MembClass=@MemberClass and
        membID=@MemberID;
        
  if @@ROWCOUNT=1
    set @Success = 1;
END
GO

CREATE PROCEDURE [TM_CreateRatingScale]
  @AgencyID int,
  @National int,
  @Rating varchar(20),
  @Position int,
  @RatingID int OUTPUT
AS
  begin tran;
    -- вставляем запись
    insert into [RatingScales] (AgencyID, [National], Rating, [Position])
    values (@AgencyID, @National, @Rating, @Position);
    -- определим ID новой записи
    set @RatingID = @@IDENTITY;
  commit tran;
GO

CREATE PROCEDURE [TM_GetCounter]
  @TableName varchar(32),
  @Counter int OUTPUT
AS
  begin tran;
    -- читаем текущее значение счётчика
    set @Counter = (select Counter from SystemCounters where TableName=@TableName);
    if @Counter is NULL begin
      -- добавляем новую запись
      insert into SystemCounters (TableName, Counter)
      values (@TableName, 1);
    end
    else begin
      -- увеличиваем счётчик
      update SystemCounters
      set Counter = @Counter+1
      where TableName=@TableName;
    end
    -- читаем новое значение счётчика
    set @Counter = (select Counter from SystemCounters where TableName=@TableName);
  commit tran;
GO

CREATE PROCEDURE [TM_CreatePool]
  @BrokerPoolID varchar(32),
  @PoolName varchar(128),
  @LoadDate int,
  @LoadTime int,
  @ExpireDate int,
  @Source varchar(250),
  @Status varchar(10),
  @KillTime int,
  @TotalQty float,
  @SendQty float,
  @ExecQty float,
  @RejectQty  float,
  @KilledQty float,
  @ActiveQty float,
  @PoolID int OUTPUT
AS
  begin tran;
    -- вставляем запись
    insert into [PoolOrders] (BrokerPoolID, PoolName, LoadDate, LoadTime, [ExpireDate], Source, Status, KillTime, TotalQty,
                                                   SendQty, ExecQty, RejectQty, KilledQty, ActiveQty)
    values (@BrokerPoolID, @PoolName, @LoadDate, @LoadTime, @ExpireDate, @Source, @Status, @KillTime, @TotalQty,
                                                   @SendQty, @ExecQty, @RejectQty, @KilledQty, @ActiveQty);
    -- определим ID новой записи
    set @PoolID = @@IDENTITY;
  commit tran;
GO

CREATE PROCEDURE [TM_CreateRestriction]
  @RestType char(1),
  @Client varchar(20),
  @Mode varchar(10),
  @Limit float,
  @SecGroupID int,
  @CoSecGroupID int,
  @Value decimal(19,4),
  @TMUserID int,
  @TMSessionID varchar(40),
  @RestrID int OUTPUT,
  @TMCounter int OUTPUT
AS
  begin tran;
    -- определим ID новой записи
    set @RestrID = (select max([ID])+1 from Restrictions);
    if @RestrID is NULL
      set @RestrID=1;
    -- определим новое значение счётчика
    exec TM_GetCounter 'RESTRICTIONS', @TMCounter OUTPUT;
    -- вставляем запись
    insert into [Restrictions] ([ID], RestType, Client, Mode, Limit, SecGroupID, CoSecGroupID, disabled, [Value], [NoCheck], TMUserID, TMSessionID, TMCounter)
    values (@RestrID, @RestType, @Client, @Mode, @Limit, @SecGroupID, @CoSecGroupID, 'n', @Value, 0, @TMUserID, @TMSessionID, @TMCounter);
  commit tran;
GO

CREATE PROCEDURE [CreateNewRestriction]
  @OnClient int, -- 0 - ограничение на группу, 1 - ограничение на клиента
  @ClientCode varchar(64), -- код клиента, не более 12 символов (код группы клиентов, не более 64 символов)
  @RestrType int,  -- тип ограничения (полный список см. ниже)
  @Sign char(1)=NULL, -- "<" для ограничения сверху, ">" для ограничения снизу
  @Limit float=0, -- величина ограничения
  @SecGroupID int, -- идентификатор группы инструментов, к которой применимо ограничение
  @CoSecGroupID int=-1, -- идентификатор группы инструментов, по отношению к стоимости которой проверяется выполнение ограничения
  @ID int OUTPUT,  -- возвращает идентификатор созданного ограничения
  @ModeSummary int=0, -- для ограничений на группу, 0 - на индивидуальные активы клиентов, 1 - на суммарные активы группы клиентов
  @NotUseAccInt int=0, -- учёт НКД в расчётах, 0 - учитывается, 1 - не учитывается
  @ModeEmitent int=0, -- для ограничений типа 3, 0 - объём обращения по инструменту, 1 - по эмитенту
  @ModeAnySecurity int=0, -- для ограничений типа 4,5,6, 0 - любые инструменты, 1 - из указанной группы инструментов
  @ModeAnyEmitent int=0, -- для ограничений типа 12,13,14, 0 - любые инструменты, 1 - из указанной группы инструментов (с группировкой по эмитентам)
  @LimitKind int=0, -- срок расчётов, для которого задано ограничение (или -1 если оно применимо для всех сроков расчётов)
  @RestrCode varchar(12)=NULL, -- код ограничения
  @RestrName varchar(50)=NULL -- наименование ограничения
/*  типы ограничений:
  0 - Отношение оценки стоимости группы инструментов к стоимости  портфеля
  1 - Отношение оценки стоимости группы инструментов к стоимости другой группы инструментов
  2 - Оценка стоимости группы инструментов
  3 - Отношение оценки стоимости группы инструментов к полному объёму обращения этой группы инструментов
  4 - Отношение оценки стоимости любого инструмента к стоимости портфеля
  5 - Отношение оценки стоимости любого инструмента к стоимости другой группы инструментов.
  6 - Оценка стоимости любого инструмента.
  7 - Количество инструментов (в штуках) из некоторой группы инструментов.
  8 - Запрет на проведение операций с инструментами из группы инструментов
  9 - Ограничение на отклонение портфеля от эталонного значения (абсолютное значение)
  10 - Ограничение на отклонение портфеля от эталонного значения (на величину доли от оценки эталонного портфеля) 
  11 - Отношение оценки стоимости инструментов любого эмитента к стоимости портфеля.
  12 - Отношение оценки стоимости инструментов любого эмитента к стоимости другой группы инструментов.
  13 - Оценка стоимости инструментов любого эмитента.  */
AS
  declare @RType char(1);
  declare @RLimit float;
  declare @RValue float;
  declare @RSign varchar(10);
  declare @TMSessionID varchar(40);
  declare @TMCounter int;

  set NOCOUNT ON;

  set @ID=-1;

  if (@RestrType<0) or (@RestrType>13)
    return;

  if (@RestrType in (0,1,2,3,7,8)) and (@SecGroupID<2000000000) begin
    -- проверим наличие указанной группы инструментов
    if not exists (select * from SecGroups where [ID]=@SecGroupID)
      return;
  end

  if (@RestrType in (1,5,12)) and (@CoSecGroupID<2000000000) begin
    -- проверим наличие указанной группы инструментов
    if not exists (select * from SecGroups where [ID]=@CoSecGroupID)
      return;
  end

  if ltrim(rtrim(@RestrCode))=''
    set @RestrCode=NULL;

  if (@RestrCode is NOT NULL) begin
    -- проверим уникальность кода ограничения
	if exists (select * from Restrictions where (RestrCode is NOT NULL) and (RestrCode=@RestrCode))
	  return;
  end;

  if (@RestrType<>8) and (@Sign is NULL)
    return;

  if (@RestrType<>8) and (@Limit is NULL)
    return;

  if  @RestrType=0 begin
    --   0 - Отношение оценки стоимости группы инструментов к стоимости  портфеля
    if @OnClient=1 
      set @RType='C'
    else
      set @RType='G';
    set @RSign = @Sign;
    set @RLimit = @Limit;
    set @RValue = NULL;
    set @CoSecGroupID = NULL;
  end
  else if @RestrType=1 begin
    -- 1 - Отношение оценки стоимости группы инструментов к стоимости другой группы инструментов
    if @OnClient=1 
      set @RType='c'
    else
      set @RType='g';
    set @RSign = @Sign;
    set @RLimit = @Limit;
    set @RValue = NULL;
  end
  else if @RestrType=2 begin
    -- 2 - Оценка стоимости группы инструментов
    if @OnClient=1 
      set @RType='C'
    else
      set @RType='G';
    set @RSign = @Sign+'A';
    set @RLimit = NULL;
    set @RValue = @Limit;
    set @CoSecGroupID = NULL;
  end
  else if @RestrType=3 begin
    --  3 - Отношение оценки стоимости группы инструментов к полному объёму обращения этой группы инструментов
    if @OnClient=1 
      set @RType='C'
    else
      set @RType='G';
    set @RSign = @Sign+'V';
    set @RLimit = @Limit;
    set @RValue = NULL;
    set @CoSecGroupID = NULL;
  end
  else if @RestrType=4 begin
    --  4 - Отношение оценки стоимости любого инструмента к стоимости портфеля
    if @OnClient=1 
      set @RType='C'
    else
      set @RType='G';
    set @RSign = @Sign+'E';
    set @RLimit = @Limit;
    set @RValue = NULL;
    if @ModeAnySecurity=0
      set @SecGroupID = -1;
    set @CoSecGroupID = -1;
  end
  else if @RestrType=5 begin
    --  5 - Отношение оценки стоимости любого инструмента к стоимости другой группы инструментов
    if @OnClient=1 
      set @RType='C'
    else
      set @RType='G';
    set @RSign = @Sign+'E';
    set @RLimit = @Limit;
    set @RValue = NULL;
    if @ModeAnySecurity=0
      set @SecGroupID = -1;
  end
  else if @RestrType=6 begin
    --  6 - Оценка стоимости любого инструмента
    if @OnClient=1 
      set @RType='C'
    else
      set @RType='G';
    set @RSign = @Sign+'E';
    set @RLimit = NULL;
    set @RValue = @Limit;
    if @ModeAnySecurity=0
      set @SecGroupID = -1;
    set @CoSecGroupID = -1;
  end
  else if @RestrType=7 begin
    -- 7 - Количество инструментов (в штуках) из некоторой группы инструментов
    if @OnClient=1 
      set @RType='C'
    else
      set @RType='G';
    set @RSign = @Sign+'C';
    set @RLimit = -1;
    set @RValue = @Limit;
    set @CoSecGroupID = -1;
  end
  else if @RestrType=8 begin
    --  8 - Запрет на проведение операций с инструментами из группы инструментов
    if @OnClient=1 
      set @RType='C'
    else
      set @RType='G';
    set @RSign = '!';
    set @RLimit = NULL;
    set @RValue = NULL;
    set @CoSecGroupID = NULL;
  end
  else if @RestrType=9 begin
    --  9 - Ограничение на отклонение портфеля от эталонного значения (абсолютное значение)
    if @OnClient=1 
      set @RType='C'
    else
      set @RType='G';
    set @RSign = @Sign+'DA';
    set @RLimit = NULL;
    set @RValue = @Limit;
    set @SecGroupID = -1;
    set @CoSecGroupID = -1;
  end
  else if @RestrType=10 begin
    --  10 - Ограничение на отклонение портфеля от эталонного значения (на величину доли от оценки эталонного портфеля)  */
    if @OnClient=1 
      set @RType='C'
    else
      set @RType='G';
    set @RSign = @Sign+'D';
    set @RLimit = @Limit;
    set @RValue = NULL;
    set @SecGroupID = -1;
    set @CoSecGroupID = -1;
  end
  else if @RestrType=11 begin
    --  11 - Отношение оценки стоимости инструментов любого эмитента к стоимости портфеля
    if @OnClient=1 
      set @RType='C'
    else
      set @RType='G';
    set @RSign = @Sign+'EJ';
    set @RLimit = @Limit;
    set @RValue = -1;
    if @ModeAnyEmitent=0
      set @SecGroupID = -1;
    set @CoSecGroupID = -1;
  end
  else if @RestrType=12 begin
    --  12 - Отношение оценки стоимости инструментов любого эмитента к стоимости другой группы инструментов
    if @OnClient=1 
      set @RType='C'
    else
      set @RType='G';
    set @RSign = @Sign+'EJ';
    set @RLimit = @Limit;
    set @RValue = -1;
    if @ModeAnyEmitent=0
      set @SecGroupID = -1;
  end
  else if @RestrType=13 begin
    --  13 - Оценка стоимости инструментов любого эмитента
    if @OnClient=1 
      set @RType='C'
    else
      set @RType='G';
    set @RSign = @Sign+'EJ';
    set @RLimit = -1;
    set @RValue = @Limit;
    if @ModeAnyEmitent=0
      set @SecGroupID = -1;
    set @CoSecGroupID = -1;
  end
  else
    return;
    
  -- тип учёта активов в группе инструментов
  if @OnClient=2 and @ModeSummary=1
    set @RSign = @RSign+'S';

  -- режим учёта НКД
  if @NotUseAccInt=1
    set @RSign = @RSign+'I';

  -- режим учёта объёма обращения
  if @RestrType=3 and @ModeEmitent=1
    set @RSign = @RSign+'K';

  set @TMSessionID = 'stored proc ('+user_name()+')';

  exec [TM_CreateRestriction] @RType, @ClientCode, @RSign, @RLimit,
                              @SecGroupID, @CoSecGroupID, @RValue,
                              0, @TMSessionID, @ID OUTPUT, @TMCounter OUTPUT,
                              @LimitKind, @RestrCode, @RestrName;
GO

CREATE PROCEDURE [TM_CreateSecGroup]
  @SecGCode varchar(64),
  @SecGName varchar(255),
  @Filter varchar(10),
  @Mode varchar(10),
  @RAgencies int,
  @ListLevel int=NULL,
  @GroupID int OUTPUT
AS
  begin tran;
    -- определим ID новой записи
    set @GroupID = (select max([ID])+1 from SecGroups);
    if @GroupID is NULL
      set @GroupID=1;
    if @ListLevel is NULL
      set @ListLevel=1;
    -- вставляем запись
    insert into [SecGroups] ([ID], SecGCode, SecGName, disabled, Filter,
           ListLevel, [mode], RAgencies)
    values (@GroupID, @SecGCode, @SecGName, 'n', @Filter,
           @ListLevel, @Mode, @RAgencies);
  commit tran;
GO

CREATE PROCEDURE [ModifySecGroup]
  @SecGroupID int, -- идентификатор группы инструментов
  @SecGroupName varchar(255)=NULL, -- наименование группы инструментов
  @ModeLogicalAnd int=NULL, -- режим группировки: 0 - объединение, 1 - пересечение
  @ListLevel int=NULL, -- уровень листинга: -1 - не задан, 0,1,2,3 - указывается уровень листинга
  @Success int OUTPUT -- возвращает 1 в случае успеха и 0 в противном случае
AS
BEGIN
  declare @RSecGroupName varchar(255);
  declare @RMode varchar(10);
  declare @RListLevel int;

  set NOCOUNT ON;

  set @Success = 0;
  
  if not exists (select * from SecGroups where [ID]=@SecGroupID and disabled='n')
    return;
    
  set @RSecGroupName = (select SecGName from SecGroups where [ID]=@SecGroupID and disabled='n');
  set @RMode = (select [Mode] from SecGroups where [ID]=@SecGroupID and disabled='n');
  set @RListLevel = (select ListLevel from SecGroups where [ID]=@SecGroupID and disabled='n');
  
  if @SecGroupName is NOT NULL
    set @RSecGroupName = @SecGroupName;
    
  if (@ModeLogicalAnd is NOT NULL) begin
    set @RMode = replace(@RMode, 'A', '');
    if @ModeLogicalAnd=1
      set @RMode = 'A' + @RMode;
  end
  
  if (@ListLevel is NOT NULL)
	set @RListLevel = @ListLevel;

  update SecGroups
  set SecGName=@RSecGroupName, Mode=@RMode, ListLevel=@RListLevel
  where [ID]=@SecGroupID and disabled='n';

  set @Success=1;
END
GO

CREATE PROCEDURE [DeleteSecGroup]
  @SecGroupID int, -- идентификатор группы инструментов
  @Success int OUTPUT -- возвращает 1 в случае успеха и 0 в противном случае
AS
BEGIN
  SET NOCOUNT ON;

  set @Success = 0;
    
  if not exists (select * from SecGroups where [ID]=@SecGroupID and disabled='n')
    return;

  update SecGroups
  set [disabled]='y'
  where [ID]=@SecGroupID and [disabled]='n';

  set @Success=1;
END
GO

CREATE PROCEDURE [TM_CreateGroupOrder]
  @GroupID int,
  @TradeDate int,
  @TradeTime int,
  @Buy char(1),
  @ML char(1),
  @SecCode varchar(12),
  @ClassCode varchar(12),
  @Price float,
  @Qty float,
  @RealQty float,
  @BalanceQty float,
  @KilledQty float,
  @Status char(1),
  @Result char(1),
  @OrdersCount int,
  @Flags varchar(10),
  @PoolID int,
  @Value float,
  @VisibleQty float,
  @TMUserID int,
  @TMSessionID varchar(40),
  @GroupOrderID int OUTPUT,
  @TMCounter int OUTPUT
AS
  begin tran;
    -- определим ID новой записи
    set @GroupOrderID = (select max([ID])+1 from GroupOrders);
    if @GroupOrderID is NULL
      set @GroupOrderID=1;
    -- определим новое значение счётчика
    exec TM_GetCounter 'GROUPORDERS', @TMCounter OUTPUT;
    -- вставляем запись
    insert into [GroupOrders] ([ID], GroupID, TradeDate, TradeTime, Buy, ML, SecCode, ClassCode, Price, Qty,
                                                                  RealQty, BalanceQty, KilledQty, Status, Result, OrdersCount, Flags, PoolID, Value, VisibleQty,
                                                                  TMUserID, TMSessionID, TMCounter)
    values (@GroupOrderID, @GroupID, @TradeDate, @TradeTime, @Buy, @ML, @SecCode, @ClassCode, @Price, @Qty,
                                                                  @RealQty, @BalanceQty, @KilledQty, @Status, @Result, @OrdersCount, @Flags, @PoolID, @Value, @VisibleQty,
                                                                  @TMUserID, @TMSessionID, @TMCounter);
  commit tran;
GO

CREATE PROCEDURE [TM_CreateOrder]
  @GroupOrderID int,
  @TradeDate int,
  @TradeTime int,
  @Buy char(1),
  @ML char(1),
  @SecCode varchar(12),
  @ClassCode varchar(12),
  @ClientCode varchar(12),
  @TrdAcc varchar(12),
  @Price float,
  @Qty float,
  @BalanceQty float,
  @OrderNum float,
  @Status char(1),
  @Result char(1),
  @OrderInPoolID int,
  @Value float,
  @VisibleQty float,
  @TMUserID int,
  @TMSessionID varchar(40),
  @OrderID int OUTPUT,
  @TMCounter int OUTPUT
AS
  begin tran;
    -- определим ID новой записи
    set @OrderID = (select max([OrderID])+1 from Orders);
    if @OrderID is NULL
      set @OrderID=1;
    -- определим новое значение счётчика
    exec TM_GetCounter 'ORDERS', @TMCounter OUTPUT;
    -- вставляем запись
    insert into [Orders] (OrderID, GroupOrderID, Buy, ML, TradeDate, TradeTime, SecCode, ClassCode, ClientCode, TrdAcc,
                                                                  Price, Qty, BalanceQty, OrderNum, Status, Result, OrderInPoolID, Value, VisibleQty,
                                                                  TMUserID, TMSessionID, TMCounter)
    values (@OrderID, @GroupOrderID, @Buy, @ML, @TradeDate, @TradeTime, @SecCode, @ClassCode, @ClientCode, @TrdAcc,
                                                                  @Price, @Qty, @BalanceQty, @OrderNum, @Status, @Result, @OrderInPoolID, @Value, @VisibleQty,
                                                                  @TMUserID, @TMSessionID, @TMCounter);
  commit tran;
GO

CREATE PROCEDURE [EditRestriction]
  @ID int , -- идентифифкатор ограничения, которое необходимо изменить
  @RestrType int,  -- тип ограничения (полный список см. ниже)
  @Sign char(1)=NULL, -- новое направление: "<" для ограничения сверху, ">" для ограничения снизу
  @Limit float=NULL, -- новая величина ограничения
  @SecGroupID int=NULL, -- идентификатор группы инструментов, к которой применимо ограничение
  @Res int OUTPUT,  -- 1 - успешно, 0 - неуспешно
  @NoCheck int=NULL, -- 1 - ограничение не проверяется, 0 - проверяется
  @LimitKind int=NULL, -- срок расчётов, для которого задано ограничение (или -1 если оно применимо для всех сроков расчётов)
  @RestrCode varchar(12)=NULL, -- код ограничения
  @RestrName varchar(50)=NULL -- наименование ограничения
/*  типы ограничений:
  0 - Отношение оценки стоимости группы инструментов к стоимости  портфеля
  1 - Отношение оценки стоимости группы инструментов к стоимости другой группы инструментов
  2 - Оценка стоимости группы инструментов
  3 - Отношение оценки стоимости группы инструментов к полному объёму обращения этой группы инструментов
  4 - Отношение оценки стоимости любого инструмента к стоимости портфеля
  5 - Отношение оценки стоимости любого инструмента к стоимости другой группы инструментов.
  6 - Оценка стоимости любого инструмента.
  7 - Количество инструментов (в штуках) из некоторой группы инструментов.
  8 - Запрет на проведение операций с инструментами из группы инструментов
  9 - Ограничение на отклонение портфеля от эталонного значения (абсолютное значение)
  10 - Ограничение на отклонение портфеля от эталонного значения (на величину доли от оценки эталонного портфеля) 
  11 - Отношение оценки стоимости инструментов любого эмитента к стоимости портфеля.
  12 - Отношение оценки стоимости инструментов любого эмитента к стоимости другой группы инструментов.
  13 - Оценка стоимости инструментов любого эмитента.  */
AS
  declare @RLimit float;
  declare @RValue float;
  declare @RSign varchar(10);
  declare @RSecGroupID int;
  declare @RNoCheck int;
  declare @RLimitKind int;
  declare @RRestrCode varchar(12);
  declare @RRestrName varchar(50);

  set NOCOUNT ON;

  set @Res = 0;

  if (@RestrType<0) or (@RestrType>13)
    return;

  if not exists (select * from Restrictions where [ID]=@ID and disabled='n')
    return;

  set @RSign = (select Mode from Restrictions where [ID]=@ID and disabled='n');
  set @RLimit = (select Limit from Restrictions where [ID]=@ID and disabled='n');
  set @RValue = (select Value from Restrictions where [ID]=@ID and disabled='n');
  set @RSecGroupID = (select SecGroupID from Restrictions where [ID]=@ID and disabled='n');
  set @RNoCheck = (select [NoCheck] from Restrictions where [ID]=@ID and disabled='n');
  set @RLimitKind = (select LimitKind from Restrictions where [ID]=@ID and disabled='n');
  set @RRestrCode = (select RestrCode from Restrictions where [ID]=@ID and disabled='n');
  set @RRestrName = (select RestrName from Restrictions where [ID]=@ID and disabled='n');

  if  @RestrType=0 begin
    --   0 - Отношение оценки стоимости группы инструментов к стоимости  портфеля
    if @Limit is NOT NULL begin
      set @RLimit = @Limit;
      set @RValue = NULL;
    end
    if @SecGroupID is NOT NULL
      set @RSecGroupID = @SecGroupID;
  end
  else if @RestrType=1 begin
    -- 1 - Отношение оценки стоимости группы инструментов к стоимости другой группы инструментов
    if @Limit is NOT NULL begin
      set @RLimit = @Limit;
      set @RValue = NULL;
    end
    if @SecGroupID is NOT NULL
      set @RSecGroupID = @SecGroupID;
  end
  else if @RestrType=2 begin
    -- 2 - Оценка стоимости группы инструментов
    if @Limit is NOT NULL begin
      set @RLimit = NULL;
      set @RValue = @Limit;
    end
    if @SecGroupID is NOT NULL
      set @RSecGroupID = @SecGroupID;
  end
  else if @RestrType=3 begin
    --  3 - Отношение оценки стоимости группы инструментов к полному объёму обращения этой группы инструментов
    if @Limit is NOT NULL begin
      set @RLimit = @Limit;
      set @RValue = NULL;
    end
    if @SecGroupID is NOT NULL
      set @RSecGroupID = @SecGroupID;
  end
  else if @RestrType=4 begin
    --  4 - Отношение оценки стоимости любого инструмента к стоимости портфеля
    if @Limit is NOT NULL begin
      set @RLimit = @Limit;
      set @RValue = NULL;
    end
    if @SecGroupID is NOT NULL
      set @RSecGroupID = @SecGroupID;
  end
  else if @RestrType=5 begin
    --  5 - Отношение оценки стоимости любого инструмента к стоимости другой группы инструментов
    if @Limit is NOT NULL begin
      set @RLimit = @Limit;
      set @RValue = NULL;
    end
    if @SecGroupID is NOT NULL
      set @RSecGroupID = @SecGroupID;
  end
  else if @RestrType=6 begin
    --  6 - Оценка стоимости любого инструмента
    if @Limit is NOT NULL begin
      set @RLimit = NULL;
      set @RValue = @Limit;
    end
    if @SecGroupID is NOT NULL
      set @RSecGroupID = @SecGroupID;
  end
  else if @RestrType=7 begin
    --  7 - Количество инструментов (в штуках) из некоторой группы инструментов
    if @Limit is NOT NULL begin
      set @RLimit = -1;
      set @RValue = @Limit;
    end
    if @SecGroupID is NOT NULL
      set @RSecGroupID = @SecGroupID;
  end
  else if @RestrType=8 begin
    --  8 - Запрет на проведение операций с инструментами из группы инструментов
    if @SecGroupID is NOT NULL
      set @RSecGroupID = @SecGroupID;
  end
  else if @RestrType=9 begin
    --  9 - Ограничение на отклонение портфеля от эталонного значения (абсолютное значение)
    if @Limit is NOT NULL begin
      set @RLimit = NULL;
      set @RValue = @Limit;
    end
    set @RSecGroupID = -1;
  end
  else if @RestrType=10 begin
    --  10 - Ограничение на отклонение портфеля от эталонного значения (на величину доли от оценки эталонного портфеля)  */
    if @Limit is NOT NULL begin
      set @RLimit = @Limit;
      set @RValue = NULL;
    end
    set @RSecGroupID = -1;
  end
  else if @RestrType=11 begin
    --  11 - Отношение оценки стоимости инструментов любого эмитента к стоимости портфеля
    if @Limit is NOT NULL begin
      set @RLimit = @Limit;
      set @RValue = -1;
    end
    if @SecGroupID is NOT NULL
      set @RSecGroupID = @SecGroupID;
  end
  else if @RestrType=12 begin
    --  12 - Отношение оценки стоимости инструментов любого эмитента к стоимости другой группы инструментов
    if @Limit is NOT NULL begin
      set @RLimit = @Limit;
      set @RValue = -1;
    end
    if @SecGroupID is NOT NULL
      set @RSecGroupID = @SecGroupID;
  end
  else if @RestrType=13 begin
    --  13 - Оценка стоимости инструментов любого эмитента
    if @Limit is NOT NULL begin
      set @RLimit = -1;
      set @RValue = @Limit;
    end
    if @SecGroupID is NOT NULL
      set @RSecGroupID = @SecGroupID;
  end
  else
    return;
    
  if @Sign is NOT NULL begin
    set @RSign = replace(@RSign, '<', '^');
    set @RSign = replace(@RSign, '>', '^');
    set @RSign = replace(@RSign, '!', '^');
    set @RSign = replace(@RSign, '^', @Sign);
  end 

  if @NoCheck is NOT NULL
    set @RNoCheck = @NoCheck;

  if @LimitKind is NOT NULL
    set @RLimitKind = @LimitKind;

  if @RestrName is NOT NULL
    set @RRestrName = @RestrName;

  if (@RestrCode is NOT NULL) and 
     (ltrim(rtrim(@RestrCode))<>'') and
     ((@RRestrCode is NULL) or (ltrim(rtrim(@RRestrCode))=''))
	set @RRestrCode=@RestrCode;

  update Restrictions
  set Mode=@RSign, Limit=@RLimit, Value=@RValue, SecGroupID=@RSecGroupID,
      [NoCheck]=@RNoCheck, LimitKind=@RLimitKind, RestrCode=@RRestrCode,
	  RestrName=@RRestrName
  where [ID]=@ID and disabled='n';

  set @Res=1;
GO

CREATE PROCEDURE [TM_CreateClientGroup]
  @GroupCode varchar(64),
  @GroupName varchar(255),
  @Mode varchar(10),
  @DefWeight float,
  @SplitOrders int,
  @GroupID int OUTPUT
AS
  begin tran;
    -- вставляем запись
    insert into [GroupDesc] (GroupCode, GroupName, disabled, [Mode], DefWeight, SplitOrders)
    values (@GroupCode, @GroupName, 'n', @Mode, @DefWeight, @SplitOrders);
    -- определим ID новой записи
    set @GroupID = @@IDENTITY;
  commit tran;
GO

CREATE PROCEDURE [TM_CreateExportOrder]
  @OrderID int,
  @GroupOrderID int,
  @OrderType int,
  @TradeDate int,
  @SendDate int,
  @SendTime int,
  @OrderTime int,
  @Buy char(1),
  @ML char(1),
  @SecCode varchar(12),
  @ClassCode varchar(12),
  @ClientCode varchar(12),
  @TrdAcc varchar(12),
  @Price float,
  @Qty float,
  @Balance float,
  @Status int,
  @UserGroupID int,
  @UserGroupCode varchar(64),
  @PoolID int,
  @BrokerPoolID varchar(32),
  @VisibleQty float,
  @ExportOrderID int OUTPUT,
  @RepoValue float=0,
  @Discount float=0,
  @DiscountUpper float=0,
  @DiscountLower float=0,
  @RepoRate float=0,
  @RepoTerm int=0
AS
  begin tran;
    -- определим ID новой записи
    set @ExportOrderID = (select max([ID])+1 from ExportOrder);
    if @ExportOrderID is NULL
      set @ExportOrderID=1;
    -- вставляем запись
    insert into [ExportOrder] ([ID], OrderID, GroupOrderID, OrderType, TradeDate, SendDate, SendTime, OrderTime, Status, UserGroupID, UserGroupCode,
                                     PoolID, BrokerPoolID, ClientCode, TrdAcc, Price, Qty, Balance, VisibleQty, Buy, ML, ClassCode, SecCode,
                                     RepoValue, Discount, DiscountUpper, DiscountLower, RepoRate, RepoTerm)
    values (@ExportOrderID, @OrderID, @GroupOrderID, @OrderType, @TradeDate, @SendDate, @SendTime, @OrderTime, @Status, @UserGroupID, @UserGroupCode,
                                     @PoolID, @BrokerPoolID, @ClientCode, @TrdAcc, @Price, @Qty, @Balance, @VisibleQty, @Buy, @ML, @ClassCode, @SecCode,
                                     @RepoValue, @Discount, @DiscountUpper, @DiscountLower, @RepoRate, @RepoTerm);
  commit tran;
GO

CREATE PROCEDURE [TM_CreateGroupNegOrder]
  @GroupID int,
  @TradeDate int,
  @TradeTime int,
  @Buy char(1),
  @SecCode varchar(12),
  @ClassCode varchar(12),
  @CPFirmID varchar(12),
  @SettleCode varchar(12),
  @MatchRef varchar(10),
  @Price float,
  @Vozm float,
  @Qty float,
  @RealQty float,
  @KilledQty float,
  @Status char(1),
  @Result char(1),
  @OrdersCount int,
  @GroupNegOrderID int OUTPUT,
  @RepoValue float=0,
  @RealRepoValue float=0,
  @Discount float=0,
  @DiscountUpper float=0,
  @DiscountLower float=0,
  @RepoRate float=0,
  @RepoTerm int=0,
  @OrderType int=0,
  @Flags int=0,
  @TMUserID int,
  @TMSessionID varchar(40),
  @TMCounter int OUTPUT
AS
  begin tran;
    -- определим ID новой записи
    set @GroupNegOrderID = (select max([ID])+1 from GroupNegOrders);
    if @GroupNegOrderID is NULL
      set @GroupNegOrderID=1;
    -- определим новое значение счётчика
    exec TM_GetCounter 'GROUPNEGORDERS', @TMCounter OUTPUT;
    -- вставляем запись
    insert into [GroupNegOrders] ([ID], GroupID, TradeDate, TradeTime, Buy, SecCode, ClassCode, CPFirmID, SettleCode, MatchRef,
                                                       Price, Vozm, Qty, RealQty, KilledQty, Status, Result, OrdersCount,
                                                       RepoValue, RealRepoValue, Discount, DiscountUpper, DiscountLower,
                                                       RepoRate, RepoTerm, OrderType, Flags, TMUserID, TMSessionID, TMCounter)
    values (@GroupNegOrderID, @GroupID, @TradeDate, @TradeTime, @Buy, @SecCode, @ClassCode, @CPFirmID, @SettleCode, @MatchRef,
                                                       @Price, @Vozm, @Qty, @RealQty, @KilledQty, @Status, @Result, @OrdersCount,
                                                       @RepoValue, @RealRepoValue, @Discount, @DiscountUpper, @DiscountLower,
                                                       @RepoRate, @RepoTerm, @OrderType, @Flags, @TMUserID, @TMSessionID, @TMCounter);
  commit tran;
GO

CREATE PROCEDURE [TM_CreateGroupStopOrder]
  @GroupID int,
  @StopStyle int,
  @TradeDate int,
  @TradeTime int,
  @Buy char(1),
  @ML char(1),
  @SecCode varchar(12),
  @ClassCode varchar(12),
  @ASecCode varchar(12),
  @AClassCode varchar(12),
  @StopCond int,
  @TransFlags int,
  @StopPrice float,
  @Price float,
  @LinkedPrice float,
  @Offset float,
  @Spread float,
  @Qty float,
  @RealQty float,
  @BalanceQty float,
  @KilledQty float,
  @BaseOrderNum float,
  @Status char(1),
  @Result char(1),
  @OrdersCount int,
  @LinkedGrOrder int,
  @CoOrderNum float,
  @Expire int,
  @StopPrice2 float,
  @ActiveFromTime int,
  @ActiveToTime int,
  @GroupStopOrderID int OUTPUT
AS
  begin tran;
    -- определим ID новой записи
    set @GroupStopOrderID = (select max([ID])+1 from GroupStopOrders);
    if @GroupStopOrderID is NULL
      set @GroupStopOrderID=1;
    -- вставляем запись
    insert into [GroupStopOrders] ([ID], GroupID, StopStyle, TradeDate, TradeTime, Buy, ML, SecCode, ClassCode, ASecCode, AClassCode,
                                                                  StopCond, TransFlags, StopPrice, Price, LinkedPrice, Offset, Spread, Qty, RealQty, BalanceQty, KilledQty,
                                                                  BaseOrderNum, Status, Result, OrdersCount, LinkedGrOrder, CoOrderNum, [Expire], StopPrice2, ActiveFromTime, ActiveToTime)
    values (@GroupStopOrderID, @GroupID, @StopStyle, @TradeDate, @TradeTime, @Buy, @ML, @SecCode, @ClassCode, @ASecCode, @AClassCode,
                                                                  @StopCond, @TransFlags, @StopPrice, @Price, @LinkedPrice, @Offset, @Spread, @Qty, @RealQty, @BalanceQty, @KilledQty,
                                                                  @BaseOrderNum, @Status, @Result, @OrdersCount, @LinkedGrOrder, @CoOrderNum, @Expire, @StopPrice2, @ActiveFromTime, @ActiveToTime);
  commit tran;
GO

CREATE PROCEDURE [TM_CreateNegOrder]
  @GroupOrderID int,
  @TradeDate int,
  @TradeTime int,
  @Buy char(1),
  @SecCode varchar(12),
  @ClassCode varchar(12),
  @ClientCode varchar(12),
  @TrdAcc varchar(12),
  @CPFirmID varchar(12),
  @SettleCode varchar(12),
  @MatchRef varchar(10),
  @Price float,
  @Vozm float,
  @Qty float,
  @OrderNum float,
  @Status char(1),
  @Result char(1),
  @NegOrderID int OUTPUT,
  @RepoValue float=0,
  @Discount float=0,
  @DiscountUpper float=0,
  @DiscountLower float=0,
  @RepoRate float=0,
  @RepoTerm int=0,
  @Flags int=0,
  @TMUserID int,
  @TMSessionID varchar(40),
  @TMCounter int OUTPUT
AS
BEGIN
  begin tran;
    -- определим ID новой записи
    set @NegOrderID = (select max(OrderID)+1 from NegOrders);
    if @NegOrderID is NULL
      set @NegOrderID=1;
    -- определим новое значение счётчика
    exec TM_GetCounter 'NEGORDERS', @TMCounter OUTPUT;
    -- вставляем запись
    insert into [NegOrders] (OrderID, GroupOrderID, TradeDate, TradeTime, Buy, SecCode, ClassCode, ClientCode, TrdAcc,
                                                       CPFirmID, SettleCode, MatchRef, Price, Vozm, Qty, OrderNum, Status, Result,
                                                       RepoValue, Discount, DiscountUpper, DiscountLower,
                                                       RepoRate, RepoTerm, Flags, TMUserID, TMSessionID, TMCounter)
    values (@NegOrderID, @GroupOrderID, @TradeDate, @TradeTime, @Buy, @SecCode, @ClassCode, @ClientCode, @TrdAcc,
                                                       @CPFirmID, @SettleCode, @MatchRef, @Price, @Vozm, @Qty, @OrderNum, @Status, @Result,
                                                       @RepoValue, @Discount, @DiscountUpper, @DiscountLower,
                                                       @RepoRate, @RepoTerm, @Flags, @TMUserID, @TMSessionID, @TMCounter);
  commit tran;
END
GO

CREATE PROCEDURE [TM_SetNewImportEvent]
  @ImportType varchar(32),
  @TMUserID int,
  @TMSessionID varchar(40),
  @TMCounter int OUTPUT
AS
  declare @ImportID int;
  begin tran;
    -- определим ID новой записи
    set @ImportID = (select max([ID])+1 from ImportLog);
    if @ImportID is NULL
      set @ImportID=1;
    -- определим новое значение счётчика
    exec TM_GetCounter 'IMPORTLOG', @TMCounter OUTPUT;
    -- вставляем запись
    insert into [ImportLog] ([ID], ImportType,
	                               TMUserID, TMSessionID, TMCounter)
    values (@ImportID, @ImportType, @TMUserID, @TMSessionID, @TMCounter);
  commit tran;
GO


/* Меняем уже имеющиеся хранимые процедуры  */

ALTER PROCEDURE [TM_CreateRestriction]
  @RestType char(1),
  @Client varchar(20),
  @Mode varchar(10),
  @Limit float,
  @SecGroupID int,
  @CoSecGroupID int,
  @Value decimal(19,4),
  @TMUserID int,
  @TMSessionID varchar(40),
  @RestrID int OUTPUT,
  @TMCounter int OUTPUT,
  @LimitKind int=0,
  @RestrCode varchar(12)=NULL,
  @RestrName varchar(50)=NULL
AS
  begin tran;
    -- определим ID новой записи
    set @RestrID = (select max([ID])+1 from Restrictions);
    if @RestrID is NULL
      set @RestrID=1;
    -- определим новое значение счётчика
    exec TM_GetCounter 'RESTRICTIONS', @TMCounter OUTPUT;
    -- вставляем запись
    insert into [Restrictions] ([ID], RestType, Client, Mode, Limit,
	                                  SecGroupID, CoSecGroupID, disabled,
									  [Value], [NoCheck], LimitKind, RestrCode, RestrName,
									  TMUserID, TMSessionID, TMCounter)
    values (@RestrID, @RestType, @Client, @Mode, @Limit,
	        @SecGroupID, @CoSecGroupID, 'n',
			@Value, 0, @LimitKind, @RestrCode, @RestrName,
			@TMUserID, @TMSessionID, @TMCounter);
  commit tran;
GO

CREATE PROCEDURE [CreateNewSecGroup]
  @SecGroupCode varchar(64), -- код группы инструментов
  @SecGroupName varchar(255), -- наименование группы инструментов
  @ModeLogicalAnd int, -- режим группировки элементов группы: 0 - объединение, 1 - пересечение
  @ModeRatings int, -- 1 - основанн на рейтингах по эмитентам или отдельным инструментам, 0 - иначе
  @RAgencies int, -- для групп, основанных на рейтингах, содержит минимальное количество требуемых рейтинговых агентств, иначе равно -1
  @ListLevel int=NULL, -- уровень листинга: -1 - не задан, 0,1,2,3 - указывается уровень листинга
  @SecGroupID int OUTPUT -- возвращает идентификатор созданной группы
AS
BEGIN
  declare @RMode varchar(10);
  
  set NOCOUNT ON;

  set @SecGroupID=-1;

  if (@ModeLogicalAnd=1) and (@ModeRatings=1)
    return;

  if @ListLevel is NULL
    set @ListLevel=-1;

  if (@listLevel < -1) or (@ListLevel > 3) or ((@ListLevel > -1) and (@ModeRatings=1))
	return;

  set @RMode='';
  
  if @ModeLogicalAnd=1
    set @RMode = @RMode + 'A';

  if @ModeRatings=1
    set @RMode = @RMode + 'R';
	
  exec [TM_CreateSecGroup] @SecGroupCode, @SecGroupName, '', 
                           @RMode, @RAgencies, @ListLevel, @SecGroupID OUTPUT;
	
END
GO

CREATE OR ALTER PROCEDURE [dbo].[TM_AddClientToGroup]
	@GroupCode varchar(64),
	@ClientCode varchar(20),
	@Weight int,
	@Comment varchar(255),
	@GroupId int OUTPUT,
	@ClientNum int OUTPUT
AS
	begin tran

	set @GroupId = (select [GroupID] from [dbo].[GroupDesc] where [GroupCode] = @GroupCode)
	if @GroupId is NOT NULL begin
		declare @TempGroupId int
		set @TempGroupId = (select [GroupID] from [dbo].[Clients] where [ClientCode] = @ClientCode and [GroupID] = @GroupId)
		
		if @TempGroupId is NULL begin
			set @ClientNum = (select max([Num])+1 from [dbo].[Clients] where [GroupID] = @GroupId)

			if @ClientNum is NULL
				set @ClientNum = 1

			insert into [dbo].[Clients]([ClientCode], [GroupID], [Num], [Weight], [Comment])
				values (@ClientCode, @GroupId, @ClientNum, @Weight, @Comment)
		end
	end

	commit tran
GO

CREATE OR ALTER PROCEDURE [dbo].[TM_DeleteClientFromGroup]
	@GroupCode varchar(64),
	@ClientCode varchar(20),
	@Success int OUTPUT
AS
	begin tran

	declare @GroupId int
	
	set @GroupId = (select [GroupID] from [dbo].[GroupDesc] where [GroupCode] = @GroupCode)

	if @GroupId is NOT NULL begin
		delete from [dbo].[Clients] where [GroupID] = @GroupId and [ClientCode] = @ClientCode
		set @Success = 1
	end

	commit tran
GO

CREATE OR ALTER PROCEDURE [dbo].[TM_DeleteClientGroup]
	@GroupCode varchar(64),
	@Success int OUTPUT
AS
	begin tran

	set @Success = 0

	declare @GroupId int

	set @GroupId = (select [GroupID] from [dbo].[GroupDesc] where [GroupCode] = @GroupCode)

	if @GroupId is NOT NULL begin
		update [dbo].[GroupDesc] set [disabled]='y' where [GroupID] = @GroupId
		set @Success = 1
	end

	commit tran
GO


/* Права на таблицы и хранимые процедуры */

GRANT EXECUTE ON [TM_CreateOrderInPool] TO [tm_admin] AS [dbo]
GO
GRANT EXECUTE ON [TM_CreateOrderInPool] TO [tm_user] AS [dbo]
GO
GRANT EXECUTE ON [TM_SetNewImportEvent] TO [tm_admin] AS [dbo]
GO
GRANT EXECUTE ON [TM_SetNewImportEvent] TO [tm_user] AS [dbo]
GO
GRANT SELECT ON [RatingAgencies] TO [tm_admin] AS [dbo]
GO
GRANT INSERT ON [RatingAgencies] TO [tm_admin] AS [dbo]
GO
GRANT DELETE ON [RatingAgencies] TO [tm_admin] AS [dbo]
GO
GRANT UPDATE ON [RatingAgencies] TO [tm_admin] AS [dbo]
GO
GRANT REFERENCES ON [RatingAgencies] TO [tm_admin] AS [dbo]
GO
GRANT SELECT ON [RatingAgencies] TO [tm_user] AS [dbo]
GO
GRANT SELECT ON [RatingAgencies] ([AgencyID]) TO [tm_admin] AS [dbo]
GO
GRANT UPDATE ON [RatingAgencies] ([AgencyID]) TO [tm_admin] AS [dbo]
GO
GRANT REFERENCES ON [RatingAgencies] ([AgencyID]) TO [tm_admin] AS [dbo]
GO
GRANT SELECT ON [RatingAgencies] ([AgencyID]) TO [tm_user] AS [dbo]
GO
GRANT SELECT ON [RatingAgencies] ([AgencyCode]) TO [tm_admin] AS [dbo]
GO
GRANT UPDATE ON [RatingAgencies] ([AgencyCode]) TO [tm_admin] AS [dbo]
GO
GRANT REFERENCES ON [RatingAgencies] ([AgencyCode]) TO [tm_admin] AS [dbo]
GO
GRANT SELECT ON [RatingAgencies] ([AgencyCode]) TO [tm_user] AS [dbo]
GO
GRANT SELECT ON [RatingAgencies] ([AgencyName]) TO [tm_admin] AS [dbo]
GO
GRANT UPDATE ON [RatingAgencies] ([AgencyName]) TO [tm_admin] AS [dbo]
GO
GRANT REFERENCES ON [RatingAgencies] ([AgencyName]) TO [tm_admin] AS [dbo]
GO
GRANT SELECT ON [RatingAgencies] ([AgencyName]) TO [tm_user] AS [dbo]
GO
GRANT SELECT ON [SecGrMemb] TO [tm_admin] AS [dbo]
GO
GRANT INSERT ON [SecGrMemb] TO [tm_admin] AS [dbo]
GO
GRANT DELETE ON [SecGrMemb] TO [tm_admin] AS [dbo]
GO
GRANT UPDATE ON [SecGrMemb] TO [tm_admin] AS [dbo]
GO
GRANT REFERENCES ON [SecGrMemb] TO [tm_admin] AS [dbo]
GO
GRANT SELECT ON [SecGrMemb] TO [tm_user] AS [dbo]
GO
GRANT INSERT ON [SecGrMemb] TO [tm_user] AS [dbo]
GO
GRANT DELETE ON [SecGrMemb] TO [tm_user] AS [dbo]
GO
GRANT UPDATE ON [SecGrMemb] TO [tm_user] AS [dbo]
GO
GRANT SELECT ON [SecGrMemb] ([GroupID]) TO [tm_admin] AS [dbo]
GO
GRANT UPDATE ON [SecGrMemb] ([GroupID]) TO [tm_admin] AS [dbo]
GO
GRANT REFERENCES ON [SecGrMemb] ([GroupID]) TO [tm_admin] AS [dbo]
GO
GRANT SELECT ON [SecGrMemb] ([GroupID]) TO [tm_user] AS [dbo]
GO
GRANT UPDATE ON [SecGrMemb] ([GroupID]) TO [tm_user] AS [dbo]
GO
GRANT SELECT ON [SecGrMemb] ([MembType]) TO [tm_admin] AS [dbo]
GO
GRANT UPDATE ON [SecGrMemb] ([MembType]) TO [tm_admin] AS [dbo]
GO
GRANT REFERENCES ON [SecGrMemb] ([MembType]) TO [tm_admin] AS [dbo]
GO
GRANT SELECT ON [SecGrMemb] ([MembType]) TO [tm_user] AS [dbo]
GO
GRANT UPDATE ON [SecGrMemb] ([MembType]) TO [tm_user] AS [dbo]
GO
GRANT SELECT ON [SecGrMemb] ([MembCode]) TO [tm_admin] AS [dbo]
GO
GRANT UPDATE ON [SecGrMemb] ([MembCode]) TO [tm_admin] AS [dbo]
GO
GRANT REFERENCES ON [SecGrMemb] ([MembCode]) TO [tm_admin] AS [dbo]
GO
GRANT SELECT ON [SecGrMemb] ([MembCode]) TO [tm_user] AS [dbo]
GO
GRANT UPDATE ON [SecGrMemb] ([MembCode]) TO [tm_user] AS [dbo]
GO
GRANT SELECT ON [SecGrMemb] ([MembClass]) TO [tm_admin] AS [dbo]
GO
GRANT UPDATE ON [SecGrMemb] ([MembClass]) TO [tm_admin] AS [dbo]
GO
GRANT REFERENCES ON [SecGrMemb] ([MembClass]) TO [tm_admin] AS [dbo]
GO
GRANT SELECT ON [SecGrMemb] ([MembClass]) TO [tm_user] AS [dbo]
GO
GRANT UPDATE ON [SecGrMemb] ([MembClass]) TO [tm_user] AS [dbo]
GO
GRANT SELECT ON [SecGrMemb] ([MembID]) TO [tm_admin] AS [dbo]
GO
GRANT UPDATE ON [SecGrMemb] ([MembID]) TO [tm_admin] AS [dbo]
GO
GRANT REFERENCES ON [SecGrMemb] ([MembID]) TO [tm_admin] AS [dbo]
GO
GRANT SELECT ON [SecGrMemb] ([MembID]) TO [tm_user] AS [dbo]
GO
GRANT UPDATE ON [SecGrMemb] ([MembID]) TO [tm_user] AS [dbo]
GO
GRANT SELECT ON [RatingScales] TO [tm_admin] AS [dbo]
GO
GRANT INSERT ON [RatingScales] TO [tm_admin] AS [dbo]
GO
GRANT DELETE ON [RatingScales] TO [tm_admin] AS [dbo]
GO
GRANT UPDATE ON [RatingScales] TO [tm_admin] AS [dbo]
GO
GRANT REFERENCES ON [RatingScales] TO [tm_admin] AS [dbo]
GO
GRANT SELECT ON [RatingScales] TO [tm_user] AS [dbo]
GO
GRANT SELECT ON [RatingScales] ([RatingID]) TO [tm_admin] AS [dbo]
GO
GRANT UPDATE ON [RatingScales] ([RatingID]) TO [tm_admin] AS [dbo]
GO
GRANT REFERENCES ON [RatingScales] ([RatingID]) TO [tm_admin] AS [dbo]
GO
GRANT SELECT ON [RatingScales] ([RatingID]) TO [tm_user] AS [dbo]
GO
GRANT SELECT ON [RatingScales] ([AgencyID]) TO [tm_admin] AS [dbo]
GO
GRANT UPDATE ON [RatingScales] ([AgencyID]) TO [tm_admin] AS [dbo]
GO
GRANT REFERENCES ON [RatingScales] ([AgencyID]) TO [tm_admin] AS [dbo]
GO
GRANT SELECT ON [RatingScales] ([AgencyID]) TO [tm_user] AS [dbo]
GO
GRANT SELECT ON [RatingScales] ([National]) TO [tm_admin] AS [dbo]
GO
GRANT UPDATE ON [RatingScales] ([National]) TO [tm_admin] AS [dbo]
GO
GRANT REFERENCES ON [RatingScales] ([National]) TO [tm_admin] AS [dbo]
GO
GRANT SELECT ON [RatingScales] ([National]) TO [tm_user] AS [dbo]
GO
GRANT SELECT ON [RatingScales] ([Rating]) TO [tm_admin] AS [dbo]
GO
GRANT UPDATE ON [RatingScales] ([Rating]) TO [tm_admin] AS [dbo]
GO
GRANT REFERENCES ON [RatingScales] ([Rating]) TO [tm_admin] AS [dbo]
GO
GRANT SELECT ON [RatingScales] ([Rating]) TO [tm_user] AS [dbo]
GO
GRANT SELECT ON [RatingScales] ([Position]) TO [tm_admin] AS [dbo]
GO
GRANT UPDATE ON [RatingScales] ([Position]) TO [tm_admin] AS [dbo]
GO
GRANT REFERENCES ON [RatingScales] ([Position]) TO [tm_admin] AS [dbo]
GO
GRANT SELECT ON [RatingScales] ([Position]) TO [tm_user] AS [dbo]
GO
GRANT SELECT ON [SecMinQt] TO [tm_admin] AS [dbo]
GO
GRANT INSERT ON [SecMinQt] TO [tm_admin] AS [dbo]
GO
GRANT DELETE ON [SecMinQt] TO [tm_admin] AS [dbo]
GO
GRANT UPDATE ON [SecMinQt] TO [tm_admin] AS [dbo]
GO
GRANT REFERENCES ON [SecMinQt] TO [tm_admin] AS [dbo]
GO
GRANT SELECT ON [SecMinQt] TO [tm_user] AS [dbo]
GO
GRANT INSERT ON [SecMinQt] TO [tm_user] AS [dbo]
GO
GRANT DELETE ON [SecMinQt] TO [tm_user] AS [dbo]
GO
GRANT UPDATE ON [SecMinQt] TO [tm_user] AS [dbo]
GO
GRANT SELECT ON [SecMinQt] ([ClassCode]) TO [tm_admin] AS [dbo]
GO
GRANT UPDATE ON [SecMinQt] ([ClassCode]) TO [tm_admin] AS [dbo]
GO
GRANT REFERENCES ON [SecMinQt] ([ClassCode]) TO [tm_admin] AS [dbo]
GO
GRANT SELECT ON [SecMinQt] ([ClassCode]) TO [tm_user] AS [dbo]
GO
GRANT UPDATE ON [SecMinQt] ([ClassCode]) TO [tm_user] AS [dbo]
GO
GRANT SELECT ON [SecMinQt] ([SecCode]) TO [tm_admin] AS [dbo]
GO
GRANT UPDATE ON [SecMinQt] ([SecCode]) TO [tm_admin] AS [dbo]
GO
GRANT REFERENCES ON [SecMinQt] ([SecCode]) TO [tm_admin] AS [dbo]
GO
GRANT SELECT ON [SecMinQt] ([SecCode]) TO [tm_user] AS [dbo]
GO
GRANT UPDATE ON [SecMinQt] ([SecCode]) TO [tm_user] AS [dbo]
GO
GRANT SELECT ON [SecMinQt] ([MinQty]) TO [tm_admin] AS [dbo]
GO
GRANT UPDATE ON [SecMinQt] ([MinQty]) TO [tm_admin] AS [dbo]
GO
GRANT REFERENCES ON [SecMinQt] ([MinQty]) TO [tm_admin] AS [dbo]
GO
GRANT SELECT ON [SecMinQt] ([MinQty]) TO [tm_user] AS [dbo]
GO
GRANT UPDATE ON [SecMinQt] ([MinQty]) TO [tm_user] AS [dbo]
GO
GRANT SELECT ON [SystemCounters] TO [tm_admin] AS [dbo]
GO
GRANT INSERT ON [SystemCounters] TO [tm_admin] AS [dbo]
GO
GRANT DELETE ON [SystemCounters] TO [tm_admin] AS [dbo]
GO
GRANT UPDATE ON [SystemCounters] TO [tm_admin] AS [dbo]
GO
GRANT REFERENCES ON [SystemCounters] TO [tm_admin] AS [dbo]
GO
GRANT SELECT ON [SystemCounters] TO [tm_user] AS [dbo]
GO
GRANT INSERT ON [SystemCounters] TO [tm_user] AS [dbo]
GO
GRANT DELETE ON [SystemCounters] TO [tm_user] AS [dbo]
GO
GRANT UPDATE ON [SystemCounters] TO [tm_user] AS [dbo]
GO
GRANT SELECT ON [SystemCounters] ([TableName]) TO [tm_admin] AS [dbo]
GO
GRANT UPDATE ON [SystemCounters] ([TableName]) TO [tm_admin] AS [dbo]
GO
GRANT REFERENCES ON [SystemCounters] ([TableName]) TO [tm_admin] AS [dbo]
GO
GRANT SELECT ON [SystemCounters] ([TableName]) TO [tm_user] AS [dbo]
GO
GRANT UPDATE ON [SystemCounters] ([TableName]) TO [tm_user] AS [dbo]
GO
GRANT SELECT ON [SystemCounters] ([Counter]) TO [tm_admin] AS [dbo]
GO
GRANT UPDATE ON [SystemCounters] ([Counter]) TO [tm_admin] AS [dbo]
GO
GRANT REFERENCES ON [SystemCounters] ([Counter]) TO [tm_admin] AS [dbo]
GO
GRANT SELECT ON [SystemCounters] ([Counter]) TO [tm_user] AS [dbo]
GO
GRANT UPDATE ON [SystemCounters] ([Counter]) TO [tm_user] AS [dbo]
GO
GRANT SELECT ON [SystemData] TO [tm_admin] AS [dbo]
GO
GRANT INSERT ON [SystemData] TO [tm_admin] AS [dbo]
GO
GRANT DELETE ON [SystemData] TO [tm_admin] AS [dbo]
GO
GRANT UPDATE ON [SystemData] TO [tm_admin] AS [dbo]
GO
GRANT REFERENCES ON [SystemData] TO [tm_admin] AS [dbo]
GO
GRANT SELECT ON [SystemData] TO [tm_user] AS [dbo]
GO
GRANT SELECT ON [SystemData] ([KeyName]) TO [tm_admin] AS [dbo]
GO
GRANT UPDATE ON [SystemData] ([KeyName]) TO [tm_admin] AS [dbo]
GO
GRANT REFERENCES ON [SystemData] ([KeyName]) TO [tm_admin] AS [dbo]
GO
GRANT SELECT ON [SystemData] ([KeyName]) TO [tm_user] AS [dbo]
GO
GRANT SELECT ON [SystemData] ([KeyValue]) TO [tm_admin] AS [dbo]
GO
GRANT UPDATE ON [SystemData] ([KeyValue]) TO [tm_admin] AS [dbo]
GO
GRANT REFERENCES ON [SystemData] ([KeyValue]) TO [tm_admin] AS [dbo]
GO
GRANT SELECT ON [SystemData] ([KeyValue]) TO [tm_user] AS [dbo]
GO
GRANT SELECT ON [PoolOrders] TO [tm_admin] AS [dbo]
GO
GRANT INSERT ON [PoolOrders] TO [tm_admin] AS [dbo]
GO
GRANT DELETE ON [PoolOrders] TO [tm_admin] AS [dbo]
GO
GRANT UPDATE ON [PoolOrders] TO [tm_admin] AS [dbo]
GO
GRANT REFERENCES ON [PoolOrders] TO [tm_admin] AS [dbo]
GO
GRANT SELECT ON [PoolOrders] TO [tm_user] AS [dbo]
GO
GRANT INSERT ON [PoolOrders] TO [tm_user] AS [dbo]
GO
GRANT DELETE ON [PoolOrders] TO [tm_user] AS [dbo]
GO
GRANT UPDATE ON [PoolOrders] TO [tm_user] AS [dbo]
GO
GRANT SELECT ON [PoolOrders] ([PoolID]) TO [tm_admin] AS [dbo]
GO
GRANT UPDATE ON [PoolOrders] ([PoolID]) TO [tm_admin] AS [dbo]
GO
GRANT REFERENCES ON [PoolOrders] ([PoolID]) TO [tm_admin] AS [dbo]
GO
GRANT SELECT ON [PoolOrders] ([PoolID]) TO [tm_user] AS [dbo]
GO
GRANT UPDATE ON [PoolOrders] ([PoolID]) TO [tm_user] AS [dbo]
GO
GRANT SELECT ON [PoolOrders] ([BrokerPoolID]) TO [tm_admin] AS [dbo]
GO
GRANT UPDATE ON [PoolOrders] ([BrokerPoolID]) TO [tm_admin] AS [dbo]
GO
GRANT REFERENCES ON [PoolOrders] ([BrokerPoolID]) TO [tm_admin] AS [dbo]
GO
GRANT SELECT ON [PoolOrders] ([BrokerPoolID]) TO [tm_user] AS [dbo]
GO
GRANT UPDATE ON [PoolOrders] ([BrokerPoolID]) TO [tm_user] AS [dbo]
GO
GRANT SELECT ON [PoolOrders] ([PoolName]) TO [tm_admin] AS [dbo]
GO
GRANT UPDATE ON [PoolOrders] ([PoolName]) TO [tm_admin] AS [dbo]
GO
GRANT REFERENCES ON [PoolOrders] ([PoolName]) TO [tm_admin] AS [dbo]
GO
GRANT SELECT ON [PoolOrders] ([PoolName]) TO [tm_user] AS [dbo]
GO
GRANT UPDATE ON [PoolOrders] ([PoolName]) TO [tm_user] AS [dbo]
GO
GRANT SELECT ON [PoolOrders] ([LoadDate]) TO [tm_admin] AS [dbo]
GO
GRANT UPDATE ON [PoolOrders] ([LoadDate]) TO [tm_admin] AS [dbo]
GO
GRANT REFERENCES ON [PoolOrders] ([LoadDate]) TO [tm_admin] AS [dbo]
GO
GRANT SELECT ON [PoolOrders] ([LoadDate]) TO [tm_user] AS [dbo]
GO
GRANT UPDATE ON [PoolOrders] ([LoadDate]) TO [tm_user] AS [dbo]
GO
GRANT SELECT ON [PoolOrders] ([LoadTime]) TO [tm_admin] AS [dbo]
GO
GRANT UPDATE ON [PoolOrders] ([LoadTime]) TO [tm_admin] AS [dbo]
GO
GRANT REFERENCES ON [PoolOrders] ([LoadTime]) TO [tm_admin] AS [dbo]
GO
GRANT SELECT ON [PoolOrders] ([LoadTime]) TO [tm_user] AS [dbo]
GO
GRANT UPDATE ON [PoolOrders] ([LoadTime]) TO [tm_user] AS [dbo]
GO
GRANT SELECT ON [PoolOrders] ([ExpireDate]) TO [tm_admin] AS [dbo]
GO
GRANT UPDATE ON [PoolOrders] ([ExpireDate]) TO [tm_admin] AS [dbo]
GO
GRANT REFERENCES ON [PoolOrders] ([ExpireDate]) TO [tm_admin] AS [dbo]
GO
GRANT SELECT ON [PoolOrders] ([ExpireDate]) TO [tm_user] AS [dbo]
GO
GRANT UPDATE ON [PoolOrders] ([ExpireDate]) TO [tm_user] AS [dbo]
GO
GRANT SELECT ON [PoolOrders] ([Source]) TO [tm_admin] AS [dbo]
GO
GRANT UPDATE ON [PoolOrders] ([Source]) TO [tm_admin] AS [dbo]
GO
GRANT REFERENCES ON [PoolOrders] ([Source]) TO [tm_admin] AS [dbo]
GO
GRANT SELECT ON [PoolOrders] ([Source]) TO [tm_user] AS [dbo]
GO
GRANT UPDATE ON [PoolOrders] ([Source]) TO [tm_user] AS [dbo]
GO
GRANT SELECT ON [PoolOrders] ([Status]) TO [tm_admin] AS [dbo]
GO
GRANT UPDATE ON [PoolOrders] ([Status]) TO [tm_admin] AS [dbo]
GO
GRANT REFERENCES ON [PoolOrders] ([Status]) TO [tm_admin] AS [dbo]
GO
GRANT SELECT ON [PoolOrders] ([Status]) TO [tm_user] AS [dbo]
GO
GRANT UPDATE ON [PoolOrders] ([Status]) TO [tm_user] AS [dbo]
GO
GRANT SELECT ON [PoolOrders] ([KillTime]) TO [tm_admin] AS [dbo]
GO
GRANT UPDATE ON [PoolOrders] ([KillTime]) TO [tm_admin] AS [dbo]
GO
GRANT REFERENCES ON [PoolOrders] ([KillTime]) TO [tm_admin] AS [dbo]
GO
GRANT SELECT ON [PoolOrders] ([KillTime]) TO [tm_user] AS [dbo]
GO
GRANT UPDATE ON [PoolOrders] ([KillTime]) TO [tm_user] AS [dbo]
GO
GRANT SELECT ON [PoolOrders] ([TotalQty]) TO [tm_admin] AS [dbo]
GO
GRANT UPDATE ON [PoolOrders] ([TotalQty]) TO [tm_admin] AS [dbo]
GO
GRANT REFERENCES ON [PoolOrders] ([TotalQty]) TO [tm_admin] AS [dbo]
GO
GRANT SELECT ON [PoolOrders] ([TotalQty]) TO [tm_user] AS [dbo]
GO
GRANT UPDATE ON [PoolOrders] ([TotalQty]) TO [tm_user] AS [dbo]
GO
GRANT SELECT ON [PoolOrders] ([SendQty]) TO [tm_admin] AS [dbo]
GO
GRANT UPDATE ON [PoolOrders] ([SendQty]) TO [tm_admin] AS [dbo]
GO
GRANT REFERENCES ON [PoolOrders] ([SendQty]) TO [tm_admin] AS [dbo]
GO
GRANT SELECT ON [PoolOrders] ([SendQty]) TO [tm_user] AS [dbo]
GO
GRANT UPDATE ON [PoolOrders] ([SendQty]) TO [tm_user] AS [dbo]
GO
GRANT SELECT ON [PoolOrders] ([ExecQty]) TO [tm_admin] AS [dbo]
GO
GRANT UPDATE ON [PoolOrders] ([ExecQty]) TO [tm_admin] AS [dbo]
GO
GRANT REFERENCES ON [PoolOrders] ([ExecQty]) TO [tm_admin] AS [dbo]
GO
GRANT SELECT ON [PoolOrders] ([ExecQty]) TO [tm_user] AS [dbo]
GO
GRANT UPDATE ON [PoolOrders] ([ExecQty]) TO [tm_user] AS [dbo]
GO
GRANT SELECT ON [PoolOrders] ([RejectQty]) TO [tm_admin] AS [dbo]
GO
GRANT UPDATE ON [PoolOrders] ([RejectQty]) TO [tm_admin] AS [dbo]
GO
GRANT REFERENCES ON [PoolOrders] ([RejectQty]) TO [tm_admin] AS [dbo]
GO
GRANT SELECT ON [PoolOrders] ([RejectQty]) TO [tm_user] AS [dbo]
GO
GRANT UPDATE ON [PoolOrders] ([RejectQty]) TO [tm_user] AS [dbo]
GO
GRANT SELECT ON [PoolOrders] ([KilledQty]) TO [tm_admin] AS [dbo]
GO
GRANT UPDATE ON [PoolOrders] ([KilledQty]) TO [tm_admin] AS [dbo]
GO
GRANT REFERENCES ON [PoolOrders] ([KilledQty]) TO [tm_admin] AS [dbo]
GO
GRANT SELECT ON [PoolOrders] ([KilledQty]) TO [tm_user] AS [dbo]
GO
GRANT UPDATE ON [PoolOrders] ([KilledQty]) TO [tm_user] AS [dbo]
GO
GRANT SELECT ON [PoolOrders] ([ActiveQty]) TO [tm_admin] AS [dbo]
GO
GRANT UPDATE ON [PoolOrders] ([ActiveQty]) TO [tm_admin] AS [dbo]
GO
GRANT REFERENCES ON [PoolOrders] ([ActiveQty]) TO [tm_admin] AS [dbo]
GO
GRANT SELECT ON [PoolOrders] ([ActiveQty]) TO [tm_user] AS [dbo]
GO
GRANT UPDATE ON [PoolOrders] ([ActiveQty]) TO [tm_user] AS [dbo]
GO
GRANT EXECUTE ON [DeleteRestriction] TO [tm_admin] AS [dbo]
GO
GRANT EXECUTE ON [DeleteRestriction] TO [tm_user] AS [dbo]
GO
GRANT EXECUTE ON [TM_CreateStopOrder] TO [tm_admin] AS [dbo]
GO
GRANT EXECUTE ON [TM_CreateStopOrder] TO [tm_user] AS [dbo]
GO
GRANT SELECT ON [Clients] TO [tm_admin] AS [dbo]
GO
GRANT INSERT ON [Clients] TO [tm_admin] AS [dbo]
GO
GRANT DELETE ON [Clients] TO [tm_admin] AS [dbo]
GO
GRANT UPDATE ON [Clients] TO [tm_admin] AS [dbo]
GO
GRANT REFERENCES ON [Clients] TO [tm_admin] AS [dbo]
GO
GRANT SELECT ON [Clients] TO [tm_user] AS [dbo]
GO
GRANT SELECT ON [Clients] ([ClientCode]) TO [tm_admin] AS [dbo]
GO
GRANT UPDATE ON [Clients] ([ClientCode]) TO [tm_admin] AS [dbo]
GO
GRANT REFERENCES ON [Clients] ([ClientCode]) TO [tm_admin] AS [dbo]
GO
GRANT SELECT ON [Clients] ([ClientCode]) TO [tm_user] AS [dbo]
GO
GRANT SELECT ON [Clients] ([GroupID]) TO [tm_admin] AS [dbo]
GO
GRANT UPDATE ON [Clients] ([GroupID]) TO [tm_admin] AS [dbo]
GO
GRANT REFERENCES ON [Clients] ([GroupID]) TO [tm_admin] AS [dbo]
GO
GRANT SELECT ON [Clients] ([GroupID]) TO [tm_user] AS [dbo]
GO
GRANT SELECT ON [Clients] ([Num]) TO [tm_admin] AS [dbo]
GO
GRANT UPDATE ON [Clients] ([Num]) TO [tm_admin] AS [dbo]
GO
GRANT REFERENCES ON [Clients] ([Num]) TO [tm_admin] AS [dbo]
GO
GRANT SELECT ON [Clients] ([Num]) TO [tm_user] AS [dbo]
GO
GRANT SELECT ON [Clients] ([Weight]) TO [tm_admin] AS [dbo]
GO
GRANT UPDATE ON [Clients] ([Weight]) TO [tm_admin] AS [dbo]
GO
GRANT REFERENCES ON [Clients] ([Weight]) TO [tm_admin] AS [dbo]
GO
GRANT SELECT ON [Clients] ([Weight]) TO [tm_user] AS [dbo]
GO
GRANT SELECT ON [Clients] ([Comment]) TO [tm_admin] AS [dbo]
GO
GRANT UPDATE ON [Clients] ([Comment]) TO [tm_admin] AS [dbo]
GO
GRANT REFERENCES ON [Clients] ([Comment]) TO [tm_admin] AS [dbo]
GO
GRANT SELECT ON [Clients] ([Comment]) TO [tm_user] AS [dbo]
GO
GRANT EXECUTE ON [TM_CreateRatingAgency] TO [tm_admin] AS [dbo]
GO
GRANT EXECUTE ON [TM_CreateRatingAgency] TO [tm_user] AS [dbo]
GO
GRANT EXECUTE ON [CreateNewSecGroupMember] TO [tm_admin] AS [dbo]
GO
GRANT EXECUTE ON [CreateNewSecGroupMember] TO [tm_user] AS [dbo]
GO
GRANT EXECUTE ON [DeleteSecGroupMember] TO [tm_admin] AS [dbo]
GO
GRANT EXECUTE ON [DeleteSecGroupMember] TO [tm_user] AS [dbo]
GO
GRANT EXECUTE ON [TM_CreateRatingScale] TO [tm_admin] AS [dbo]
GO
GRANT EXECUTE ON [TM_CreateRatingScale] TO [tm_user] AS [dbo]
GO
GRANT EXECUTE ON [TM_GetCounter] TO [tm_admin] AS [dbo]
GO
GRANT EXECUTE ON [TM_GetCounter] TO [tm_user] AS [dbo]
GO
GRANT EXECUTE ON [TM_CreatePool] TO [tm_admin] AS [dbo]
GO
GRANT EXECUTE ON [TM_CreatePool] TO [tm_user] AS [dbo]
GO
GRANT SELECT ON [Orders] TO [tm_admin] AS [dbo]
GO
GRANT INSERT ON [Orders] TO [tm_admin] AS [dbo]
GO
GRANT DELETE ON [Orders] TO [tm_admin] AS [dbo]
GO
GRANT UPDATE ON [Orders] TO [tm_admin] AS [dbo]
GO
GRANT REFERENCES ON [Orders] TO [tm_admin] AS [dbo]
GO
GRANT SELECT ON [Orders] TO [tm_user] AS [dbo]
GO
GRANT INSERT ON [Orders] TO [tm_user] AS [dbo]
GO
GRANT DELETE ON [Orders] TO [tm_user] AS [dbo]
GO
GRANT UPDATE ON [Orders] TO [tm_user] AS [dbo]
GO
GRANT SELECT ON [Orders] ([OrderID]) TO [tm_admin] AS [dbo]
GO
GRANT UPDATE ON [Orders] ([OrderID]) TO [tm_admin] AS [dbo]
GO
GRANT REFERENCES ON [Orders] ([OrderID]) TO [tm_admin] AS [dbo]
GO
GRANT SELECT ON [Orders] ([OrderID]) TO [tm_user] AS [dbo]
GO
GRANT UPDATE ON [Orders] ([OrderID]) TO [tm_user] AS [dbo]
GO
GRANT SELECT ON [Orders] ([GroupOrderID]) TO [tm_admin] AS [dbo]
GO
GRANT UPDATE ON [Orders] ([GroupOrderID]) TO [tm_admin] AS [dbo]
GO
GRANT REFERENCES ON [Orders] ([GroupOrderID]) TO [tm_admin] AS [dbo]
GO
GRANT SELECT ON [Orders] ([GroupOrderID]) TO [tm_user] AS [dbo]
GO
GRANT UPDATE ON [Orders] ([GroupOrderID]) TO [tm_user] AS [dbo]
GO
GRANT SELECT ON [Orders] ([Buy]) TO [tm_admin] AS [dbo]
GO
GRANT UPDATE ON [Orders] ([Buy]) TO [tm_admin] AS [dbo]
GO
GRANT REFERENCES ON [Orders] ([Buy]) TO [tm_admin] AS [dbo]
GO
GRANT SELECT ON [Orders] ([Buy]) TO [tm_user] AS [dbo]
GO
GRANT UPDATE ON [Orders] ([Buy]) TO [tm_user] AS [dbo]
GO
GRANT SELECT ON [Orders] ([ML]) TO [tm_admin] AS [dbo]
GO
GRANT UPDATE ON [Orders] ([ML]) TO [tm_admin] AS [dbo]
GO
GRANT REFERENCES ON [Orders] ([ML]) TO [tm_admin] AS [dbo]
GO
GRANT SELECT ON [Orders] ([ML]) TO [tm_user] AS [dbo]
GO
GRANT UPDATE ON [Orders] ([ML]) TO [tm_user] AS [dbo]
GO
GRANT SELECT ON [Orders] ([TradeDate]) TO [tm_admin] AS [dbo]
GO
GRANT UPDATE ON [Orders] ([TradeDate]) TO [tm_admin] AS [dbo]
GO
GRANT REFERENCES ON [Orders] ([TradeDate]) TO [tm_admin] AS [dbo]
GO
GRANT SELECT ON [Orders] ([TradeDate]) TO [tm_user] AS [dbo]
GO
GRANT UPDATE ON [Orders] ([TradeDate]) TO [tm_user] AS [dbo]
GO
GRANT SELECT ON [Orders] ([TradeTime]) TO [tm_admin] AS [dbo]
GO
GRANT UPDATE ON [Orders] ([TradeTime]) TO [tm_admin] AS [dbo]
GO
GRANT REFERENCES ON [Orders] ([TradeTime]) TO [tm_admin] AS [dbo]
GO
GRANT SELECT ON [Orders] ([TradeTime]) TO [tm_user] AS [dbo]
GO
GRANT UPDATE ON [Orders] ([TradeTime]) TO [tm_user] AS [dbo]
GO
GRANT SELECT ON [Orders] ([SecCode]) TO [tm_admin] AS [dbo]
GO
GRANT UPDATE ON [Orders] ([SecCode]) TO [tm_admin] AS [dbo]
GO
GRANT REFERENCES ON [Orders] ([SecCode]) TO [tm_admin] AS [dbo]
GO
GRANT SELECT ON [Orders] ([SecCode]) TO [tm_user] AS [dbo]
GO
GRANT UPDATE ON [Orders] ([SecCode]) TO [tm_user] AS [dbo]
GO
GRANT SELECT ON [Orders] ([ClassCode]) TO [tm_admin] AS [dbo]
GO
GRANT UPDATE ON [Orders] ([ClassCode]) TO [tm_admin] AS [dbo]
GO
GRANT REFERENCES ON [Orders] ([ClassCode]) TO [tm_admin] AS [dbo]
GO
GRANT SELECT ON [Orders] ([ClassCode]) TO [tm_user] AS [dbo]
GO
GRANT UPDATE ON [Orders] ([ClassCode]) TO [tm_user] AS [dbo]
GO
GRANT SELECT ON [Orders] ([ClientCode]) TO [tm_admin] AS [dbo]
GO
GRANT UPDATE ON [Orders] ([ClientCode]) TO [tm_admin] AS [dbo]
GO
GRANT REFERENCES ON [Orders] ([ClientCode]) TO [tm_admin] AS [dbo]
GO
GRANT SELECT ON [Orders] ([ClientCode]) TO [tm_user] AS [dbo]
GO
GRANT UPDATE ON [Orders] ([ClientCode]) TO [tm_user] AS [dbo]
GO
GRANT SELECT ON [Orders] ([TrdAcc]) TO [tm_admin] AS [dbo]
GO
GRANT UPDATE ON [Orders] ([TrdAcc]) TO [tm_admin] AS [dbo]
GO
GRANT REFERENCES ON [Orders] ([TrdAcc]) TO [tm_admin] AS [dbo]
GO
GRANT SELECT ON [Orders] ([TrdAcc]) TO [tm_user] AS [dbo]
GO
GRANT UPDATE ON [Orders] ([TrdAcc]) TO [tm_user] AS [dbo]
GO
GRANT SELECT ON [Orders] ([Price]) TO [tm_admin] AS [dbo]
GO
GRANT UPDATE ON [Orders] ([Price]) TO [tm_admin] AS [dbo]
GO
GRANT REFERENCES ON [Orders] ([Price]) TO [tm_admin] AS [dbo]
GO
GRANT SELECT ON [Orders] ([Price]) TO [tm_user] AS [dbo]
GO
GRANT UPDATE ON [Orders] ([Price]) TO [tm_user] AS [dbo]
GO
GRANT SELECT ON [Orders] ([Qty]) TO [tm_admin] AS [dbo]
GO
GRANT UPDATE ON [Orders] ([Qty]) TO [tm_admin] AS [dbo]
GO
GRANT REFERENCES ON [Orders] ([Qty]) TO [tm_admin] AS [dbo]
GO
GRANT SELECT ON [Orders] ([Qty]) TO [tm_user] AS [dbo]
GO
GRANT UPDATE ON [Orders] ([Qty]) TO [tm_user] AS [dbo]
GO
GRANT SELECT ON [Orders] ([BalanceQty]) TO [tm_admin] AS [dbo]
GO
GRANT UPDATE ON [Orders] ([BalanceQty]) TO [tm_admin] AS [dbo]
GO
GRANT REFERENCES ON [Orders] ([BalanceQty]) TO [tm_admin] AS [dbo]
GO
GRANT SELECT ON [Orders] ([BalanceQty]) TO [tm_user] AS [dbo]
GO
GRANT UPDATE ON [Orders] ([BalanceQty]) TO [tm_user] AS [dbo]
GO
GRANT SELECT ON [Orders] ([OrderNum]) TO [tm_admin] AS [dbo]
GO
GRANT UPDATE ON [Orders] ([OrderNum]) TO [tm_admin] AS [dbo]
GO
GRANT REFERENCES ON [Orders] ([OrderNum]) TO [tm_admin] AS [dbo]
GO
GRANT SELECT ON [Orders] ([OrderNum]) TO [tm_user] AS [dbo]
GO
GRANT UPDATE ON [Orders] ([OrderNum]) TO [tm_user] AS [dbo]
GO
GRANT SELECT ON [Orders] ([Status]) TO [tm_admin] AS [dbo]
GO
GRANT UPDATE ON [Orders] ([Status]) TO [tm_admin] AS [dbo]
GO
GRANT REFERENCES ON [Orders] ([Status]) TO [tm_admin] AS [dbo]
GO
GRANT SELECT ON [Orders] ([Status]) TO [tm_user] AS [dbo]
GO
GRANT UPDATE ON [Orders] ([Status]) TO [tm_user] AS [dbo]
GO
GRANT SELECT ON [Orders] ([Result]) TO [tm_admin] AS [dbo]
GO
GRANT UPDATE ON [Orders] ([Result]) TO [tm_admin] AS [dbo]
GO
GRANT REFERENCES ON [Orders] ([Result]) TO [tm_admin] AS [dbo]
GO
GRANT SELECT ON [Orders] ([Result]) TO [tm_user] AS [dbo]
GO
GRANT UPDATE ON [Orders] ([Result]) TO [tm_user] AS [dbo]
GO
GRANT SELECT ON [Orders] ([OrderInPoolID]) TO [tm_admin] AS [dbo]
GO
GRANT UPDATE ON [Orders] ([OrderInPoolID]) TO [tm_admin] AS [dbo]
GO
GRANT REFERENCES ON [Orders] ([OrderInPoolID]) TO [tm_admin] AS [dbo]
GO
GRANT SELECT ON [Orders] ([OrderInPoolID]) TO [tm_user] AS [dbo]
GO
GRANT UPDATE ON [Orders] ([OrderInPoolID]) TO [tm_user] AS [dbo]
GO
GRANT SELECT ON [Orders] ([Value]) TO [tm_admin] AS [dbo]
GO
GRANT UPDATE ON [Orders] ([Value]) TO [tm_admin] AS [dbo]
GO
GRANT REFERENCES ON [Orders] ([Value]) TO [tm_admin] AS [dbo]
GO
GRANT SELECT ON [Orders] ([Value]) TO [tm_user] AS [dbo]
GO
GRANT UPDATE ON [Orders] ([Value]) TO [tm_user] AS [dbo]
GO
GRANT SELECT ON [Orders] ([VisibleQty]) TO [tm_admin] AS [dbo]
GO
GRANT UPDATE ON [Orders] ([VisibleQty]) TO [tm_admin] AS [dbo]
GO
GRANT REFERENCES ON [Orders] ([VisibleQty]) TO [tm_admin] AS [dbo]
GO
GRANT SELECT ON [Orders] ([VisibleQty]) TO [tm_user] AS [dbo]
GO
GRANT UPDATE ON [Orders] ([VisibleQty]) TO [tm_user] AS [dbo]
GO
GRANT SELECT ON [Orders] ([TMUserID]) TO [tm_admin] AS [dbo]
GO
GRANT UPDATE ON [Orders] ([TMUserID]) TO [tm_admin] AS [dbo]
GO
GRANT REFERENCES ON [Orders] ([TMUserID]) TO [tm_admin] AS [dbo]
GO
GRANT SELECT ON [Orders] ([TMUserID]) TO [tm_user] AS [dbo]
GO
GRANT UPDATE ON [Orders] ([TMUserID]) TO [tm_user] AS [dbo]
GO
GRANT SELECT ON [Orders] ([TMSessionID]) TO [tm_admin] AS [dbo]
GO
GRANT UPDATE ON [Orders] ([TMSessionID]) TO [tm_admin] AS [dbo]
GO
GRANT REFERENCES ON [Orders] ([TMSessionID]) TO [tm_admin] AS [dbo]
GO
GRANT SELECT ON [Orders] ([TMSessionID]) TO [tm_user] AS [dbo]
GO
GRANT UPDATE ON [Orders] ([TMSessionID]) TO [tm_user] AS [dbo]
GO
GRANT SELECT ON [Orders] ([TMCounter]) TO [tm_admin] AS [dbo]
GO
GRANT UPDATE ON [Orders] ([TMCounter]) TO [tm_admin] AS [dbo]
GO
GRANT REFERENCES ON [Orders] ([TMCounter]) TO [tm_admin] AS [dbo]
GO
GRANT SELECT ON [Orders] ([TMCounter]) TO [tm_user] AS [dbo]
GO
GRANT UPDATE ON [Orders] ([TMCounter]) TO [tm_user] AS [dbo]
GO
GRANT SELECT ON [OrdersInPool] TO [tm_admin] AS [dbo]
GO
GRANT INSERT ON [OrdersInPool] TO [tm_admin] AS [dbo]
GO
GRANT DELETE ON [OrdersInPool] TO [tm_admin] AS [dbo]
GO
GRANT UPDATE ON [OrdersInPool] TO [tm_admin] AS [dbo]
GO
GRANT REFERENCES ON [OrdersInPool] TO [tm_admin] AS [dbo]
GO
GRANT SELECT ON [OrdersInPool] TO [tm_user] AS [dbo]
GO
GRANT INSERT ON [OrdersInPool] TO [tm_user] AS [dbo]
GO
GRANT DELETE ON [OrdersInPool] TO [tm_user] AS [dbo]
GO
GRANT UPDATE ON [OrdersInPool] TO [tm_user] AS [dbo]
GO
GRANT SELECT ON [OrdersInPool] ([OrderID]) TO [tm_admin] AS [dbo]
GO
GRANT UPDATE ON [OrdersInPool] ([OrderID]) TO [tm_admin] AS [dbo]
GO
GRANT REFERENCES ON [OrdersInPool] ([OrderID]) TO [tm_admin] AS [dbo]
GO
GRANT SELECT ON [OrdersInPool] ([OrderID]) TO [tm_user] AS [dbo]
GO
GRANT UPDATE ON [OrdersInPool] ([OrderID]) TO [tm_user] AS [dbo]
GO
GRANT SELECT ON [OrdersInPool] ([PoolID]) TO [tm_admin] AS [dbo]
GO
GRANT UPDATE ON [OrdersInPool] ([PoolID]) TO [tm_admin] AS [dbo]
GO
GRANT REFERENCES ON [OrdersInPool] ([PoolID]) TO [tm_admin] AS [dbo]
GO
GRANT SELECT ON [OrdersInPool] ([PoolID]) TO [tm_user] AS [dbo]
GO
GRANT UPDATE ON [OrdersInPool] ([PoolID]) TO [tm_user] AS [dbo]
GO
GRANT SELECT ON [OrdersInPool] ([OrderType]) TO [tm_admin] AS [dbo]
GO
GRANT UPDATE ON [OrdersInPool] ([OrderType]) TO [tm_admin] AS [dbo]
GO
GRANT REFERENCES ON [OrdersInPool] ([OrderType]) TO [tm_admin] AS [dbo]
GO
GRANT SELECT ON [OrdersInPool] ([OrderType]) TO [tm_user] AS [dbo]
GO
GRANT UPDATE ON [OrdersInPool] ([OrderType]) TO [tm_user] AS [dbo]
GO
GRANT SELECT ON [OrdersInPool] ([ClientCode]) TO [tm_admin] AS [dbo]
GO
GRANT UPDATE ON [OrdersInPool] ([ClientCode]) TO [tm_admin] AS [dbo]
GO
GRANT REFERENCES ON [OrdersInPool] ([ClientCode]) TO [tm_admin] AS [dbo]
GO
GRANT SELECT ON [OrdersInPool] ([ClientCode]) TO [tm_user] AS [dbo]
GO
GRANT UPDATE ON [OrdersInPool] ([ClientCode]) TO [tm_user] AS [dbo]
GO
GRANT SELECT ON [OrdersInPool] ([ClassCode]) TO [tm_admin] AS [dbo]
GO
GRANT UPDATE ON [OrdersInPool] ([ClassCode]) TO [tm_admin] AS [dbo]
GO
GRANT REFERENCES ON [OrdersInPool] ([ClassCode]) TO [tm_admin] AS [dbo]
GO
GRANT SELECT ON [OrdersInPool] ([ClassCode]) TO [tm_user] AS [dbo]
GO
GRANT UPDATE ON [OrdersInPool] ([ClassCode]) TO [tm_user] AS [dbo]
GO
GRANT SELECT ON [OrdersInPool] ([SecCode]) TO [tm_admin] AS [dbo]
GO
GRANT UPDATE ON [OrdersInPool] ([SecCode]) TO [tm_admin] AS [dbo]
GO
GRANT REFERENCES ON [OrdersInPool] ([SecCode]) TO [tm_admin] AS [dbo]
GO
GRANT SELECT ON [OrdersInPool] ([SecCode]) TO [tm_user] AS [dbo]
GO
GRANT UPDATE ON [OrdersInPool] ([SecCode]) TO [tm_user] AS [dbo]
GO
GRANT SELECT ON [OrdersInPool] ([Price]) TO [tm_admin] AS [dbo]
GO
GRANT UPDATE ON [OrdersInPool] ([Price]) TO [tm_admin] AS [dbo]
GO
GRANT REFERENCES ON [OrdersInPool] ([Price]) TO [tm_admin] AS [dbo]
GO
GRANT SELECT ON [OrdersInPool] ([Price]) TO [tm_user] AS [dbo]
GO
GRANT UPDATE ON [OrdersInPool] ([Price]) TO [tm_user] AS [dbo]
GO
GRANT SELECT ON [OrdersInPool] ([Qty]) TO [tm_admin] AS [dbo]
GO
GRANT UPDATE ON [OrdersInPool] ([Qty]) TO [tm_admin] AS [dbo]
GO
GRANT REFERENCES ON [OrdersInPool] ([Qty]) TO [tm_admin] AS [dbo]
GO
GRANT SELECT ON [OrdersInPool] ([Qty]) TO [tm_user] AS [dbo]
GO
GRANT UPDATE ON [OrdersInPool] ([Qty]) TO [tm_user] AS [dbo]
GO
GRANT SELECT ON [OrdersInPool] ([Buy]) TO [tm_admin] AS [dbo]
GO
GRANT UPDATE ON [OrdersInPool] ([Buy]) TO [tm_admin] AS [dbo]
GO
GRANT REFERENCES ON [OrdersInPool] ([Buy]) TO [tm_admin] AS [dbo]
GO
GRANT SELECT ON [OrdersInPool] ([Buy]) TO [tm_user] AS [dbo]
GO
GRANT UPDATE ON [OrdersInPool] ([Buy]) TO [tm_user] AS [dbo]
GO
GRANT SELECT ON [OrdersInPool] ([ML]) TO [tm_admin] AS [dbo]
GO
GRANT UPDATE ON [OrdersInPool] ([ML]) TO [tm_admin] AS [dbo]
GO
GRANT REFERENCES ON [OrdersInPool] ([ML]) TO [tm_admin] AS [dbo]
GO
GRANT SELECT ON [OrdersInPool] ([ML]) TO [tm_user] AS [dbo]
GO
GRANT UPDATE ON [OrdersInPool] ([ML]) TO [tm_user] AS [dbo]
GO
GRANT SELECT ON [OrdersInPool] ([SendQty]) TO [tm_admin] AS [dbo]
GO
GRANT UPDATE ON [OrdersInPool] ([SendQty]) TO [tm_admin] AS [dbo]
GO
GRANT REFERENCES ON [OrdersInPool] ([SendQty]) TO [tm_admin] AS [dbo]
GO
GRANT SELECT ON [OrdersInPool] ([SendQty]) TO [tm_user] AS [dbo]
GO
GRANT UPDATE ON [OrdersInPool] ([SendQty]) TO [tm_user] AS [dbo]
GO
GRANT SELECT ON [OrdersInPool] ([ExecQty]) TO [tm_admin] AS [dbo]
GO
GRANT UPDATE ON [OrdersInPool] ([ExecQty]) TO [tm_admin] AS [dbo]
GO
GRANT REFERENCES ON [OrdersInPool] ([ExecQty]) TO [tm_admin] AS [dbo]
GO
GRANT SELECT ON [OrdersInPool] ([ExecQty]) TO [tm_user] AS [dbo]
GO
GRANT UPDATE ON [OrdersInPool] ([ExecQty]) TO [tm_user] AS [dbo]
GO
GRANT SELECT ON [OrdersInPool] ([RejectQty]) TO [tm_admin] AS [dbo]
GO
GRANT UPDATE ON [OrdersInPool] ([RejectQty]) TO [tm_admin] AS [dbo]
GO
GRANT REFERENCES ON [OrdersInPool] ([RejectQty]) TO [tm_admin] AS [dbo]
GO
GRANT SELECT ON [OrdersInPool] ([RejectQty]) TO [tm_user] AS [dbo]
GO
GRANT UPDATE ON [OrdersInPool] ([RejectQty]) TO [tm_user] AS [dbo]
GO
GRANT SELECT ON [OrdersInPool] ([KillQty]) TO [tm_admin] AS [dbo]
GO
GRANT UPDATE ON [OrdersInPool] ([KillQty]) TO [tm_admin] AS [dbo]
GO
GRANT REFERENCES ON [OrdersInPool] ([KillQty]) TO [tm_admin] AS [dbo]
GO
GRANT SELECT ON [OrdersInPool] ([KillQty]) TO [tm_user] AS [dbo]
GO
GRANT UPDATE ON [OrdersInPool] ([KillQty]) TO [tm_user] AS [dbo]
GO
GRANT SELECT ON [OrdersInPool] ([ActiveQty]) TO [tm_admin] AS [dbo]
GO
GRANT UPDATE ON [OrdersInPool] ([ActiveQty]) TO [tm_admin] AS [dbo]
GO
GRANT REFERENCES ON [OrdersInPool] ([ActiveQty]) TO [tm_admin] AS [dbo]
GO
GRANT SELECT ON [OrdersInPool] ([ActiveQty]) TO [tm_user] AS [dbo]
GO
GRANT UPDATE ON [OrdersInPool] ([ActiveQty]) TO [tm_user] AS [dbo]
GO
GRANT SELECT ON [OrdersInPool] ([Comment]) TO [tm_admin] AS [dbo]
GO
GRANT UPDATE ON [OrdersInPool] ([Comment]) TO [tm_admin] AS [dbo]
GO
GRANT REFERENCES ON [OrdersInPool] ([Comment]) TO [tm_admin] AS [dbo]
GO
GRANT SELECT ON [OrdersInPool] ([Comment]) TO [tm_user] AS [dbo]
GO
GRANT UPDATE ON [OrdersInPool] ([Comment]) TO [tm_user] AS [dbo]
GO
GRANT SELECT ON [StopOrders] TO [tm_admin] AS [dbo]
GO
GRANT INSERT ON [StopOrders] TO [tm_admin] AS [dbo]
GO
GRANT DELETE ON [StopOrders] TO [tm_admin] AS [dbo]
GO
GRANT UPDATE ON [StopOrders] TO [tm_admin] AS [dbo]
GO
GRANT REFERENCES ON [StopOrders] TO [tm_admin] AS [dbo]
GO
GRANT SELECT ON [StopOrders] TO [tm_user] AS [dbo]
GO
GRANT INSERT ON [StopOrders] TO [tm_user] AS [dbo]
GO
GRANT DELETE ON [StopOrders] TO [tm_user] AS [dbo]
GO
GRANT UPDATE ON [StopOrders] TO [tm_user] AS [dbo]
GO
GRANT SELECT ON [StopOrders] ([OrderID]) TO [tm_admin] AS [dbo]
GO
GRANT UPDATE ON [StopOrders] ([OrderID]) TO [tm_admin] AS [dbo]
GO
GRANT REFERENCES ON [StopOrders] ([OrderID]) TO [tm_admin] AS [dbo]
GO
GRANT SELECT ON [StopOrders] ([OrderID]) TO [tm_user] AS [dbo]
GO
GRANT UPDATE ON [StopOrders] ([OrderID]) TO [tm_user] AS [dbo]
GO
GRANT SELECT ON [StopOrders] ([GroupOrderID]) TO [tm_admin] AS [dbo]
GO
GRANT UPDATE ON [StopOrders] ([GroupOrderID]) TO [tm_admin] AS [dbo]
GO
GRANT REFERENCES ON [StopOrders] ([GroupOrderID]) TO [tm_admin] AS [dbo]
GO
GRANT SELECT ON [StopOrders] ([GroupOrderID]) TO [tm_user] AS [dbo]
GO
GRANT UPDATE ON [StopOrders] ([GroupOrderID]) TO [tm_user] AS [dbo]
GO
GRANT SELECT ON [StopOrders] ([StopStyle]) TO [tm_admin] AS [dbo]
GO
GRANT UPDATE ON [StopOrders] ([StopStyle]) TO [tm_admin] AS [dbo]
GO
GRANT REFERENCES ON [StopOrders] ([StopStyle]) TO [tm_admin] AS [dbo]
GO
GRANT SELECT ON [StopOrders] ([StopStyle]) TO [tm_user] AS [dbo]
GO
GRANT UPDATE ON [StopOrders] ([StopStyle]) TO [tm_user] AS [dbo]
GO
GRANT SELECT ON [StopOrders] ([Buy]) TO [tm_admin] AS [dbo]
GO
GRANT UPDATE ON [StopOrders] ([Buy]) TO [tm_admin] AS [dbo]
GO
GRANT REFERENCES ON [StopOrders] ([Buy]) TO [tm_admin] AS [dbo]
GO
GRANT SELECT ON [StopOrders] ([Buy]) TO [tm_user] AS [dbo]
GO
GRANT UPDATE ON [StopOrders] ([Buy]) TO [tm_user] AS [dbo]
GO
GRANT SELECT ON [StopOrders] ([ML]) TO [tm_admin] AS [dbo]
GO
GRANT UPDATE ON [StopOrders] ([ML]) TO [tm_admin] AS [dbo]
GO
GRANT REFERENCES ON [StopOrders] ([ML]) TO [tm_admin] AS [dbo]
GO
GRANT SELECT ON [StopOrders] ([ML]) TO [tm_user] AS [dbo]
GO
GRANT UPDATE ON [StopOrders] ([ML]) TO [tm_user] AS [dbo]
GO
GRANT SELECT ON [StopOrders] ([TradeDate]) TO [tm_admin] AS [dbo]
GO
GRANT UPDATE ON [StopOrders] ([TradeDate]) TO [tm_admin] AS [dbo]
GO
GRANT REFERENCES ON [StopOrders] ([TradeDate]) TO [tm_admin] AS [dbo]
GO
GRANT SELECT ON [StopOrders] ([TradeDate]) TO [tm_user] AS [dbo]
GO
GRANT UPDATE ON [StopOrders] ([TradeDate]) TO [tm_user] AS [dbo]
GO
GRANT SELECT ON [StopOrders] ([TradeTime]) TO [tm_admin] AS [dbo]
GO
GRANT UPDATE ON [StopOrders] ([TradeTime]) TO [tm_admin] AS [dbo]
GO
GRANT REFERENCES ON [StopOrders] ([TradeTime]) TO [tm_admin] AS [dbo]
GO
GRANT SELECT ON [StopOrders] ([TradeTime]) TO [tm_user] AS [dbo]
GO
GRANT UPDATE ON [StopOrders] ([TradeTime]) TO [tm_user] AS [dbo]
GO
GRANT SELECT ON [StopOrders] ([SecCode]) TO [tm_admin] AS [dbo]
GO
GRANT UPDATE ON [StopOrders] ([SecCode]) TO [tm_admin] AS [dbo]
GO
GRANT REFERENCES ON [StopOrders] ([SecCode]) TO [tm_admin] AS [dbo]
GO
GRANT SELECT ON [StopOrders] ([SecCode]) TO [tm_user] AS [dbo]
GO
GRANT UPDATE ON [StopOrders] ([SecCode]) TO [tm_user] AS [dbo]
GO
GRANT SELECT ON [StopOrders] ([ClassCode]) TO [tm_admin] AS [dbo]
GO
GRANT UPDATE ON [StopOrders] ([ClassCode]) TO [tm_admin] AS [dbo]
GO
GRANT REFERENCES ON [StopOrders] ([ClassCode]) TO [tm_admin] AS [dbo]
GO
GRANT SELECT ON [StopOrders] ([ClassCode]) TO [tm_user] AS [dbo]
GO
GRANT UPDATE ON [StopOrders] ([ClassCode]) TO [tm_user] AS [dbo]
GO
GRANT SELECT ON [StopOrders] ([ASecCode]) TO [tm_admin] AS [dbo]
GO
GRANT UPDATE ON [StopOrders] ([ASecCode]) TO [tm_admin] AS [dbo]
GO
GRANT REFERENCES ON [StopOrders] ([ASecCode]) TO [tm_admin] AS [dbo]
GO
GRANT SELECT ON [StopOrders] ([ASecCode]) TO [tm_user] AS [dbo]
GO
GRANT UPDATE ON [StopOrders] ([ASecCode]) TO [tm_user] AS [dbo]
GO
GRANT SELECT ON [StopOrders] ([AClassCode]) TO [tm_admin] AS [dbo]
GO
GRANT UPDATE ON [StopOrders] ([AClassCode]) TO [tm_admin] AS [dbo]
GO
GRANT REFERENCES ON [StopOrders] ([AClassCode]) TO [tm_admin] AS [dbo]
GO
GRANT SELECT ON [StopOrders] ([AClassCode]) TO [tm_user] AS [dbo]
GO
GRANT UPDATE ON [StopOrders] ([AClassCode]) TO [tm_user] AS [dbo]
GO
GRANT SELECT ON [StopOrders] ([StopCond]) TO [tm_admin] AS [dbo]
GO
GRANT UPDATE ON [StopOrders] ([StopCond]) TO [tm_admin] AS [dbo]
GO
GRANT REFERENCES ON [StopOrders] ([StopCond]) TO [tm_admin] AS [dbo]
GO
GRANT SELECT ON [StopOrders] ([StopCond]) TO [tm_user] AS [dbo]
GO
GRANT UPDATE ON [StopOrders] ([StopCond]) TO [tm_user] AS [dbo]
GO
GRANT SELECT ON [StopOrders] ([TransFlags]) TO [tm_admin] AS [dbo]
GO
GRANT UPDATE ON [StopOrders] ([TransFlags]) TO [tm_admin] AS [dbo]
GO
GRANT REFERENCES ON [StopOrders] ([TransFlags]) TO [tm_admin] AS [dbo]
GO
GRANT SELECT ON [StopOrders] ([TransFlags]) TO [tm_user] AS [dbo]
GO
GRANT UPDATE ON [StopOrders] ([TransFlags]) TO [tm_user] AS [dbo]
GO
GRANT SELECT ON [StopOrders] ([ClientCode]) TO [tm_admin] AS [dbo]
GO
GRANT UPDATE ON [StopOrders] ([ClientCode]) TO [tm_admin] AS [dbo]
GO
GRANT REFERENCES ON [StopOrders] ([ClientCode]) TO [tm_admin] AS [dbo]
GO
GRANT SELECT ON [StopOrders] ([ClientCode]) TO [tm_user] AS [dbo]
GO
GRANT UPDATE ON [StopOrders] ([ClientCode]) TO [tm_user] AS [dbo]
GO
GRANT SELECT ON [StopOrders] ([StopPrice]) TO [tm_admin] AS [dbo]
GO
GRANT UPDATE ON [StopOrders] ([StopPrice]) TO [tm_admin] AS [dbo]
GO
GRANT REFERENCES ON [StopOrders] ([StopPrice]) TO [tm_admin] AS [dbo]
GO
GRANT SELECT ON [StopOrders] ([StopPrice]) TO [tm_user] AS [dbo]
GO
GRANT UPDATE ON [StopOrders] ([StopPrice]) TO [tm_user] AS [dbo]
GO
GRANT SELECT ON [StopOrders] ([Price]) TO [tm_admin] AS [dbo]
GO
GRANT UPDATE ON [StopOrders] ([Price]) TO [tm_admin] AS [dbo]
GO
GRANT REFERENCES ON [StopOrders] ([Price]) TO [tm_admin] AS [dbo]
GO
GRANT SELECT ON [StopOrders] ([Price]) TO [tm_user] AS [dbo]
GO
GRANT UPDATE ON [StopOrders] ([Price]) TO [tm_user] AS [dbo]
GO
GRANT SELECT ON [StopOrders] ([LinkedPrice]) TO [tm_admin] AS [dbo]
GO
GRANT UPDATE ON [StopOrders] ([LinkedPrice]) TO [tm_admin] AS [dbo]
GO
GRANT REFERENCES ON [StopOrders] ([LinkedPrice]) TO [tm_admin] AS [dbo]
GO
GRANT SELECT ON [StopOrders] ([LinkedPrice]) TO [tm_user] AS [dbo]
GO
GRANT UPDATE ON [StopOrders] ([LinkedPrice]) TO [tm_user] AS [dbo]
GO
GRANT SELECT ON [StopOrders] ([Offset]) TO [tm_admin] AS [dbo]
GO
GRANT UPDATE ON [StopOrders] ([Offset]) TO [tm_admin] AS [dbo]
GO
GRANT REFERENCES ON [StopOrders] ([Offset]) TO [tm_admin] AS [dbo]
GO
GRANT SELECT ON [StopOrders] ([Offset]) TO [tm_user] AS [dbo]
GO
GRANT UPDATE ON [StopOrders] ([Offset]) TO [tm_user] AS [dbo]
GO
GRANT SELECT ON [StopOrders] ([Spread]) TO [tm_admin] AS [dbo]
GO
GRANT UPDATE ON [StopOrders] ([Spread]) TO [tm_admin] AS [dbo]
GO
GRANT REFERENCES ON [StopOrders] ([Spread]) TO [tm_admin] AS [dbo]
GO
GRANT SELECT ON [StopOrders] ([Spread]) TO [tm_user] AS [dbo]
GO
GRANT UPDATE ON [StopOrders] ([Spread]) TO [tm_user] AS [dbo]
GO
GRANT SELECT ON [StopOrders] ([Qty]) TO [tm_admin] AS [dbo]
GO
GRANT UPDATE ON [StopOrders] ([Qty]) TO [tm_admin] AS [dbo]
GO
GRANT REFERENCES ON [StopOrders] ([Qty]) TO [tm_admin] AS [dbo]
GO
GRANT SELECT ON [StopOrders] ([Qty]) TO [tm_user] AS [dbo]
GO
GRANT UPDATE ON [StopOrders] ([Qty]) TO [tm_user] AS [dbo]
GO
GRANT SELECT ON [StopOrders] ([Balance]) TO [tm_admin] AS [dbo]
GO
GRANT UPDATE ON [StopOrders] ([Balance]) TO [tm_admin] AS [dbo]
GO
GRANT REFERENCES ON [StopOrders] ([Balance]) TO [tm_admin] AS [dbo]
GO
GRANT SELECT ON [StopOrders] ([Balance]) TO [tm_user] AS [dbo]
GO
GRANT UPDATE ON [StopOrders] ([Balance]) TO [tm_user] AS [dbo]
GO
GRANT SELECT ON [StopOrders] ([StopOrderNum]) TO [tm_admin] AS [dbo]
GO
GRANT UPDATE ON [StopOrders] ([StopOrderNum]) TO [tm_admin] AS [dbo]
GO
GRANT REFERENCES ON [StopOrders] ([StopOrderNum]) TO [tm_admin] AS [dbo]
GO
GRANT SELECT ON [StopOrders] ([StopOrderNum]) TO [tm_user] AS [dbo]
GO
GRANT UPDATE ON [StopOrders] ([StopOrderNum]) TO [tm_user] AS [dbo]
GO
GRANT SELECT ON [StopOrders] ([LinkedOrderNum]) TO [tm_admin] AS [dbo]
GO
GRANT UPDATE ON [StopOrders] ([LinkedOrderNum]) TO [tm_admin] AS [dbo]
GO
GRANT REFERENCES ON [StopOrders] ([LinkedOrderNum]) TO [tm_admin] AS [dbo]
GO
GRANT SELECT ON [StopOrders] ([LinkedOrderNum]) TO [tm_user] AS [dbo]
GO
GRANT UPDATE ON [StopOrders] ([LinkedOrderNum]) TO [tm_user] AS [dbo]
GO
GRANT SELECT ON [StopOrders] ([BaseOrderNum]) TO [tm_admin] AS [dbo]
GO
GRANT UPDATE ON [StopOrders] ([BaseOrderNum]) TO [tm_admin] AS [dbo]
GO
GRANT REFERENCES ON [StopOrders] ([BaseOrderNum]) TO [tm_admin] AS [dbo]
GO
GRANT SELECT ON [StopOrders] ([BaseOrderNum]) TO [tm_user] AS [dbo]
GO
GRANT UPDATE ON [StopOrders] ([BaseOrderNum]) TO [tm_user] AS [dbo]
GO
GRANT SELECT ON [StopOrders] ([CoOrderNum]) TO [tm_admin] AS [dbo]
GO
GRANT UPDATE ON [StopOrders] ([CoOrderNum]) TO [tm_admin] AS [dbo]
GO
GRANT REFERENCES ON [StopOrders] ([CoOrderNum]) TO [tm_admin] AS [dbo]
GO
GRANT SELECT ON [StopOrders] ([CoOrderNum]) TO [tm_user] AS [dbo]
GO
GRANT UPDATE ON [StopOrders] ([CoOrderNum]) TO [tm_user] AS [dbo]
GO
GRANT SELECT ON [StopOrders] ([Status]) TO [tm_admin] AS [dbo]
GO
GRANT UPDATE ON [StopOrders] ([Status]) TO [tm_admin] AS [dbo]
GO
GRANT REFERENCES ON [StopOrders] ([Status]) TO [tm_admin] AS [dbo]
GO
GRANT SELECT ON [StopOrders] ([Status]) TO [tm_user] AS [dbo]
GO
GRANT UPDATE ON [StopOrders] ([Status]) TO [tm_user] AS [dbo]
GO
GRANT SELECT ON [StopOrders] ([Result]) TO [tm_admin] AS [dbo]
GO
GRANT UPDATE ON [StopOrders] ([Result]) TO [tm_admin] AS [dbo]
GO
GRANT REFERENCES ON [StopOrders] ([Result]) TO [tm_admin] AS [dbo]
GO
GRANT SELECT ON [StopOrders] ([Result]) TO [tm_user] AS [dbo]
GO
GRANT UPDATE ON [StopOrders] ([Result]) TO [tm_user] AS [dbo]
GO
GRANT SELECT ON [StopOrders] ([Expire]) TO [tm_admin] AS [dbo]
GO
GRANT UPDATE ON [StopOrders] ([Expire]) TO [tm_admin] AS [dbo]
GO
GRANT REFERENCES ON [StopOrders] ([Expire]) TO [tm_admin] AS [dbo]
GO
GRANT SELECT ON [StopOrders] ([Expire]) TO [tm_user] AS [dbo]
GO
GRANT UPDATE ON [StopOrders] ([Expire]) TO [tm_user] AS [dbo]
GO
GRANT SELECT ON [StopOrders] ([StopPrice2]) TO [tm_admin] AS [dbo]
GO
GRANT UPDATE ON [StopOrders] ([StopPrice2]) TO [tm_admin] AS [dbo]
GO
GRANT REFERENCES ON [StopOrders] ([StopPrice2]) TO [tm_admin] AS [dbo]
GO
GRANT SELECT ON [StopOrders] ([StopPrice2]) TO [tm_user] AS [dbo]
GO
GRANT UPDATE ON [StopOrders] ([StopPrice2]) TO [tm_user] AS [dbo]
GO
GRANT SELECT ON [StopOrders] ([ActiveFromTime]) TO [tm_admin] AS [dbo]
GO
GRANT UPDATE ON [StopOrders] ([ActiveFromTime]) TO [tm_admin] AS [dbo]
GO
GRANT REFERENCES ON [StopOrders] ([ActiveFromTime]) TO [tm_admin] AS [dbo]
GO
GRANT SELECT ON [StopOrders] ([ActiveFromTime]) TO [tm_user] AS [dbo]
GO
GRANT UPDATE ON [StopOrders] ([ActiveFromTime]) TO [tm_user] AS [dbo]
GO
GRANT SELECT ON [StopOrders] ([ActiveToTime]) TO [tm_admin] AS [dbo]
GO
GRANT UPDATE ON [StopOrders] ([ActiveToTime]) TO [tm_admin] AS [dbo]
GO
GRANT REFERENCES ON [StopOrders] ([ActiveToTime]) TO [tm_admin] AS [dbo]
GO
GRANT SELECT ON [StopOrders] ([ActiveToTime]) TO [tm_user] AS [dbo]
GO
GRANT UPDATE ON [StopOrders] ([ActiveToTime]) TO [tm_user] AS [dbo]
GO
GRANT SELECT ON [StopOrders] ([TrdAcc]) TO [tm_admin] AS [dbo]
GO
GRANT UPDATE ON [StopOrders] ([TrdAcc]) TO [tm_admin] AS [dbo]
GO
GRANT REFERENCES ON [StopOrders] ([TrdAcc]) TO [tm_admin] AS [dbo]
GO
GRANT SELECT ON [StopOrders] ([TrdAcc]) TO [tm_user] AS [dbo]
GO
GRANT UPDATE ON [StopOrders] ([TrdAcc]) TO [tm_user] AS [dbo]
GO
GRANT SELECT ON [GroupOrders] TO [tm_admin] AS [dbo]
GO
GRANT INSERT ON [GroupOrders] TO [tm_admin] AS [dbo]
GO
GRANT DELETE ON [GroupOrders] TO [tm_admin] AS [dbo]
GO
GRANT UPDATE ON [GroupOrders] TO [tm_admin] AS [dbo]
GO
GRANT REFERENCES ON [GroupOrders] TO [tm_admin] AS [dbo]
GO
GRANT SELECT ON [GroupOrders] TO [tm_user] AS [dbo]
GO
GRANT INSERT ON [GroupOrders] TO [tm_user] AS [dbo]
GO
GRANT DELETE ON [GroupOrders] TO [tm_user] AS [dbo]
GO
GRANT UPDATE ON [GroupOrders] TO [tm_user] AS [dbo]
GO
GRANT SELECT ON [GroupOrders] ([ID]) TO [tm_admin] AS [dbo]
GO
GRANT UPDATE ON [GroupOrders] ([ID]) TO [tm_admin] AS [dbo]
GO
GRANT REFERENCES ON [GroupOrders] ([ID]) TO [tm_admin] AS [dbo]
GO
GRANT SELECT ON [GroupOrders] ([ID]) TO [tm_user] AS [dbo]
GO
GRANT UPDATE ON [GroupOrders] ([ID]) TO [tm_user] AS [dbo]
GO
GRANT SELECT ON [GroupOrders] ([GroupID]) TO [tm_admin] AS [dbo]
GO
GRANT UPDATE ON [GroupOrders] ([GroupID]) TO [tm_admin] AS [dbo]
GO
GRANT REFERENCES ON [GroupOrders] ([GroupID]) TO [tm_admin] AS [dbo]
GO
GRANT SELECT ON [GroupOrders] ([GroupID]) TO [tm_user] AS [dbo]
GO
GRANT UPDATE ON [GroupOrders] ([GroupID]) TO [tm_user] AS [dbo]
GO
GRANT SELECT ON [GroupOrders] ([TradeDate]) TO [tm_admin] AS [dbo]
GO
GRANT UPDATE ON [GroupOrders] ([TradeDate]) TO [tm_admin] AS [dbo]
GO
GRANT REFERENCES ON [GroupOrders] ([TradeDate]) TO [tm_admin] AS [dbo]
GO
GRANT SELECT ON [GroupOrders] ([TradeDate]) TO [tm_user] AS [dbo]
GO
GRANT UPDATE ON [GroupOrders] ([TradeDate]) TO [tm_user] AS [dbo]
GO
GRANT SELECT ON [GroupOrders] ([TradeTime]) TO [tm_admin] AS [dbo]
GO
GRANT UPDATE ON [GroupOrders] ([TradeTime]) TO [tm_admin] AS [dbo]
GO
GRANT REFERENCES ON [GroupOrders] ([TradeTime]) TO [tm_admin] AS [dbo]
GO
GRANT SELECT ON [GroupOrders] ([TradeTime]) TO [tm_user] AS [dbo]
GO
GRANT UPDATE ON [GroupOrders] ([TradeTime]) TO [tm_user] AS [dbo]
GO
GRANT SELECT ON [GroupOrders] ([Buy]) TO [tm_admin] AS [dbo]
GO
GRANT UPDATE ON [GroupOrders] ([Buy]) TO [tm_admin] AS [dbo]
GO
GRANT REFERENCES ON [GroupOrders] ([Buy]) TO [tm_admin] AS [dbo]
GO
GRANT SELECT ON [GroupOrders] ([Buy]) TO [tm_user] AS [dbo]
GO
GRANT UPDATE ON [GroupOrders] ([Buy]) TO [tm_user] AS [dbo]
GO
GRANT SELECT ON [GroupOrders] ([ML]) TO [tm_admin] AS [dbo]
GO
GRANT UPDATE ON [GroupOrders] ([ML]) TO [tm_admin] AS [dbo]
GO
GRANT REFERENCES ON [GroupOrders] ([ML]) TO [tm_admin] AS [dbo]
GO
GRANT SELECT ON [GroupOrders] ([ML]) TO [tm_user] AS [dbo]
GO
GRANT UPDATE ON [GroupOrders] ([ML]) TO [tm_user] AS [dbo]
GO
GRANT SELECT ON [GroupOrders] ([SecCode]) TO [tm_admin] AS [dbo]
GO
GRANT UPDATE ON [GroupOrders] ([SecCode]) TO [tm_admin] AS [dbo]
GO
GRANT REFERENCES ON [GroupOrders] ([SecCode]) TO [tm_admin] AS [dbo]
GO
GRANT SELECT ON [GroupOrders] ([SecCode]) TO [tm_user] AS [dbo]
GO
GRANT UPDATE ON [GroupOrders] ([SecCode]) TO [tm_user] AS [dbo]
GO
GRANT SELECT ON [GroupOrders] ([ClassCode]) TO [tm_admin] AS [dbo]
GO
GRANT UPDATE ON [GroupOrders] ([ClassCode]) TO [tm_admin] AS [dbo]
GO
GRANT REFERENCES ON [GroupOrders] ([ClassCode]) TO [tm_admin] AS [dbo]
GO
GRANT SELECT ON [GroupOrders] ([ClassCode]) TO [tm_user] AS [dbo]
GO
GRANT UPDATE ON [GroupOrders] ([ClassCode]) TO [tm_user] AS [dbo]
GO
GRANT SELECT ON [GroupOrders] ([Price]) TO [tm_admin] AS [dbo]
GO
GRANT UPDATE ON [GroupOrders] ([Price]) TO [tm_admin] AS [dbo]
GO
GRANT REFERENCES ON [GroupOrders] ([Price]) TO [tm_admin] AS [dbo]
GO
GRANT SELECT ON [GroupOrders] ([Price]) TO [tm_user] AS [dbo]
GO
GRANT UPDATE ON [GroupOrders] ([Price]) TO [tm_user] AS [dbo]
GO
GRANT SELECT ON [GroupOrders] ([Qty]) TO [tm_admin] AS [dbo]
GO
GRANT UPDATE ON [GroupOrders] ([Qty]) TO [tm_admin] AS [dbo]
GO
GRANT REFERENCES ON [GroupOrders] ([Qty]) TO [tm_admin] AS [dbo]
GO
GRANT SELECT ON [GroupOrders] ([Qty]) TO [tm_user] AS [dbo]
GO
GRANT UPDATE ON [GroupOrders] ([Qty]) TO [tm_user] AS [dbo]
GO
GRANT SELECT ON [GroupOrders] ([RealQty]) TO [tm_admin] AS [dbo]
GO
GRANT UPDATE ON [GroupOrders] ([RealQty]) TO [tm_admin] AS [dbo]
GO
GRANT REFERENCES ON [GroupOrders] ([RealQty]) TO [tm_admin] AS [dbo]
GO
GRANT SELECT ON [GroupOrders] ([RealQty]) TO [tm_user] AS [dbo]
GO
GRANT UPDATE ON [GroupOrders] ([RealQty]) TO [tm_user] AS [dbo]
GO
GRANT SELECT ON [GroupOrders] ([BalanceQty]) TO [tm_admin] AS [dbo]
GO
GRANT UPDATE ON [GroupOrders] ([BalanceQty]) TO [tm_admin] AS [dbo]
GO
GRANT REFERENCES ON [GroupOrders] ([BalanceQty]) TO [tm_admin] AS [dbo]
GO
GRANT SELECT ON [GroupOrders] ([BalanceQty]) TO [tm_user] AS [dbo]
GO
GRANT UPDATE ON [GroupOrders] ([BalanceQty]) TO [tm_user] AS [dbo]
GO
GRANT SELECT ON [GroupOrders] ([KilledQty]) TO [tm_admin] AS [dbo]
GO
GRANT UPDATE ON [GroupOrders] ([KilledQty]) TO [tm_admin] AS [dbo]
GO
GRANT REFERENCES ON [GroupOrders] ([KilledQty]) TO [tm_admin] AS [dbo]
GO
GRANT SELECT ON [GroupOrders] ([KilledQty]) TO [tm_user] AS [dbo]
GO
GRANT UPDATE ON [GroupOrders] ([KilledQty]) TO [tm_user] AS [dbo]
GO
GRANT SELECT ON [GroupOrders] ([Status]) TO [tm_admin] AS [dbo]
GO
GRANT UPDATE ON [GroupOrders] ([Status]) TO [tm_admin] AS [dbo]
GO
GRANT REFERENCES ON [GroupOrders] ([Status]) TO [tm_admin] AS [dbo]
GO
GRANT SELECT ON [GroupOrders] ([Status]) TO [tm_user] AS [dbo]
GO
GRANT UPDATE ON [GroupOrders] ([Status]) TO [tm_user] AS [dbo]
GO
GRANT SELECT ON [GroupOrders] ([Result]) TO [tm_admin] AS [dbo]
GO
GRANT UPDATE ON [GroupOrders] ([Result]) TO [tm_admin] AS [dbo]
GO
GRANT REFERENCES ON [GroupOrders] ([Result]) TO [tm_admin] AS [dbo]
GO
GRANT SELECT ON [GroupOrders] ([Result]) TO [tm_user] AS [dbo]
GO
GRANT UPDATE ON [GroupOrders] ([Result]) TO [tm_user] AS [dbo]
GO
GRANT SELECT ON [GroupOrders] ([OrdersCount]) TO [tm_admin] AS [dbo]
GO
GRANT UPDATE ON [GroupOrders] ([OrdersCount]) TO [tm_admin] AS [dbo]
GO
GRANT REFERENCES ON [GroupOrders] ([OrdersCount]) TO [tm_admin] AS [dbo]
GO
GRANT SELECT ON [GroupOrders] ([OrdersCount]) TO [tm_user] AS [dbo]
GO
GRANT UPDATE ON [GroupOrders] ([OrdersCount]) TO [tm_user] AS [dbo]
GO
GRANT SELECT ON [GroupOrders] ([Flags]) TO [tm_admin] AS [dbo]
GO
GRANT UPDATE ON [GroupOrders] ([Flags]) TO [tm_admin] AS [dbo]
GO
GRANT REFERENCES ON [GroupOrders] ([Flags]) TO [tm_admin] AS [dbo]
GO
GRANT SELECT ON [GroupOrders] ([Flags]) TO [tm_user] AS [dbo]
GO
GRANT UPDATE ON [GroupOrders] ([Flags]) TO [tm_user] AS [dbo]
GO
GRANT SELECT ON [GroupOrders] ([PoolID]) TO [tm_admin] AS [dbo]
GO
GRANT UPDATE ON [GroupOrders] ([PoolID]) TO [tm_admin] AS [dbo]
GO
GRANT REFERENCES ON [GroupOrders] ([PoolID]) TO [tm_admin] AS [dbo]
GO
GRANT SELECT ON [GroupOrders] ([PoolID]) TO [tm_user] AS [dbo]
GO
GRANT UPDATE ON [GroupOrders] ([PoolID]) TO [tm_user] AS [dbo]
GO
GRANT SELECT ON [GroupOrders] ([Value]) TO [tm_admin] AS [dbo]
GO
GRANT UPDATE ON [GroupOrders] ([Value]) TO [tm_admin] AS [dbo]
GO
GRANT REFERENCES ON [GroupOrders] ([Value]) TO [tm_admin] AS [dbo]
GO
GRANT SELECT ON [GroupOrders] ([Value]) TO [tm_user] AS [dbo]
GO
GRANT UPDATE ON [GroupOrders] ([Value]) TO [tm_user] AS [dbo]
GO
GRANT SELECT ON [GroupOrders] ([TMUserID]) TO [tm_admin] AS [dbo]
GO
GRANT UPDATE ON [GroupOrders] ([TMUserID]) TO [tm_admin] AS [dbo]
GO
GRANT REFERENCES ON [GroupOrders] ([TMUserID]) TO [tm_admin] AS [dbo]
GO
GRANT SELECT ON [GroupOrders] ([TMUserID]) TO [tm_user] AS [dbo]
GO
GRANT UPDATE ON [GroupOrders] ([TMUserID]) TO [tm_user] AS [dbo]
GO
GRANT SELECT ON [GroupOrders] ([TMSessionID]) TO [tm_admin] AS [dbo]
GO
GRANT UPDATE ON [GroupOrders] ([TMSessionID]) TO [tm_admin] AS [dbo]
GO
GRANT REFERENCES ON [GroupOrders] ([TMSessionID]) TO [tm_admin] AS [dbo]
GO
GRANT SELECT ON [GroupOrders] ([TMSessionID]) TO [tm_user] AS [dbo]
GO
GRANT UPDATE ON [GroupOrders] ([TMSessionID]) TO [tm_user] AS [dbo]
GO
GRANT SELECT ON [GroupOrders] ([TMCounter]) TO [tm_admin] AS [dbo]
GO
GRANT UPDATE ON [GroupOrders] ([TMCounter]) TO [tm_admin] AS [dbo]
GO
GRANT REFERENCES ON [GroupOrders] ([TMCounter]) TO [tm_admin] AS [dbo]
GO
GRANT SELECT ON [GroupOrders] ([TMCounter]) TO [tm_user] AS [dbo]
GO
GRANT UPDATE ON [GroupOrders] ([TMCounter]) TO [tm_user] AS [dbo]
GO
GRANT SELECT ON [GroupOrders] ([VisibleQty]) TO [tm_admin] AS [dbo]
GO
GRANT UPDATE ON [GroupOrders] ([VisibleQty]) TO [tm_admin] AS [dbo]
GO
GRANT REFERENCES ON [GroupOrders] ([VisibleQty]) TO [tm_admin] AS [dbo]
GO
GRANT SELECT ON [GroupOrders] ([VisibleQty]) TO [tm_user] AS [dbo]
GO
GRANT UPDATE ON [GroupOrders] ([VisibleQty]) TO [tm_user] AS [dbo]
GO
GRANT SELECT ON [GroupStopOrders] TO [tm_admin] AS [dbo]
GO
GRANT INSERT ON [GroupStopOrders] TO [tm_admin] AS [dbo]
GO
GRANT DELETE ON [GroupStopOrders] TO [tm_admin] AS [dbo]
GO
GRANT UPDATE ON [GroupStopOrders] TO [tm_admin] AS [dbo]
GO
GRANT REFERENCES ON [GroupStopOrders] TO [tm_admin] AS [dbo]
GO
GRANT SELECT ON [GroupStopOrders] TO [tm_user] AS [dbo]
GO
GRANT INSERT ON [GroupStopOrders] TO [tm_user] AS [dbo]
GO
GRANT DELETE ON [GroupStopOrders] TO [tm_user] AS [dbo]
GO
GRANT UPDATE ON [GroupStopOrders] TO [tm_user] AS [dbo]
GO
GRANT SELECT ON [GroupStopOrders] ([ID]) TO [tm_admin] AS [dbo]
GO
GRANT UPDATE ON [GroupStopOrders] ([ID]) TO [tm_admin] AS [dbo]
GO
GRANT REFERENCES ON [GroupStopOrders] ([ID]) TO [tm_admin] AS [dbo]
GO
GRANT SELECT ON [GroupStopOrders] ([ID]) TO [tm_user] AS [dbo]
GO
GRANT UPDATE ON [GroupStopOrders] ([ID]) TO [tm_user] AS [dbo]
GO
GRANT SELECT ON [GroupStopOrders] ([GroupID]) TO [tm_admin] AS [dbo]
GO
GRANT UPDATE ON [GroupStopOrders] ([GroupID]) TO [tm_admin] AS [dbo]
GO
GRANT REFERENCES ON [GroupStopOrders] ([GroupID]) TO [tm_admin] AS [dbo]
GO
GRANT SELECT ON [GroupStopOrders] ([GroupID]) TO [tm_user] AS [dbo]
GO
GRANT UPDATE ON [GroupStopOrders] ([GroupID]) TO [tm_user] AS [dbo]
GO
GRANT SELECT ON [GroupStopOrders] ([StopStyle]) TO [tm_admin] AS [dbo]
GO
GRANT UPDATE ON [GroupStopOrders] ([StopStyle]) TO [tm_admin] AS [dbo]
GO
GRANT REFERENCES ON [GroupStopOrders] ([StopStyle]) TO [tm_admin] AS [dbo]
GO
GRANT SELECT ON [GroupStopOrders] ([StopStyle]) TO [tm_user] AS [dbo]
GO
GRANT UPDATE ON [GroupStopOrders] ([StopStyle]) TO [tm_user] AS [dbo]
GO
GRANT SELECT ON [GroupStopOrders] ([TradeDate]) TO [tm_admin] AS [dbo]
GO
GRANT UPDATE ON [GroupStopOrders] ([TradeDate]) TO [tm_admin] AS [dbo]
GO
GRANT REFERENCES ON [GroupStopOrders] ([TradeDate]) TO [tm_admin] AS [dbo]
GO
GRANT SELECT ON [GroupStopOrders] ([TradeDate]) TO [tm_user] AS [dbo]
GO
GRANT UPDATE ON [GroupStopOrders] ([TradeDate]) TO [tm_user] AS [dbo]
GO
GRANT SELECT ON [GroupStopOrders] ([TradeTime]) TO [tm_admin] AS [dbo]
GO
GRANT UPDATE ON [GroupStopOrders] ([TradeTime]) TO [tm_admin] AS [dbo]
GO
GRANT REFERENCES ON [GroupStopOrders] ([TradeTime]) TO [tm_admin] AS [dbo]
GO
GRANT SELECT ON [GroupStopOrders] ([TradeTime]) TO [tm_user] AS [dbo]
GO
GRANT UPDATE ON [GroupStopOrders] ([TradeTime]) TO [tm_user] AS [dbo]
GO
GRANT SELECT ON [GroupStopOrders] ([Buy]) TO [tm_admin] AS [dbo]
GO
GRANT UPDATE ON [GroupStopOrders] ([Buy]) TO [tm_admin] AS [dbo]
GO
GRANT REFERENCES ON [GroupStopOrders] ([Buy]) TO [tm_admin] AS [dbo]
GO
GRANT SELECT ON [GroupStopOrders] ([Buy]) TO [tm_user] AS [dbo]
GO
GRANT UPDATE ON [GroupStopOrders] ([Buy]) TO [tm_user] AS [dbo]
GO
GRANT SELECT ON [GroupStopOrders] ([ML]) TO [tm_admin] AS [dbo]
GO
GRANT UPDATE ON [GroupStopOrders] ([ML]) TO [tm_admin] AS [dbo]
GO
GRANT REFERENCES ON [GroupStopOrders] ([ML]) TO [tm_admin] AS [dbo]
GO
GRANT SELECT ON [GroupStopOrders] ([ML]) TO [tm_user] AS [dbo]
GO
GRANT UPDATE ON [GroupStopOrders] ([ML]) TO [tm_user] AS [dbo]
GO
GRANT SELECT ON [GroupStopOrders] ([SecCode]) TO [tm_admin] AS [dbo]
GO
GRANT UPDATE ON [GroupStopOrders] ([SecCode]) TO [tm_admin] AS [dbo]
GO
GRANT REFERENCES ON [GroupStopOrders] ([SecCode]) TO [tm_admin] AS [dbo]
GO
GRANT SELECT ON [GroupStopOrders] ([SecCode]) TO [tm_user] AS [dbo]
GO
GRANT UPDATE ON [GroupStopOrders] ([SecCode]) TO [tm_user] AS [dbo]
GO
GRANT SELECT ON [GroupStopOrders] ([ClassCode]) TO [tm_admin] AS [dbo]
GO
GRANT UPDATE ON [GroupStopOrders] ([ClassCode]) TO [tm_admin] AS [dbo]
GO
GRANT REFERENCES ON [GroupStopOrders] ([ClassCode]) TO [tm_admin] AS [dbo]
GO
GRANT SELECT ON [GroupStopOrders] ([ClassCode]) TO [tm_user] AS [dbo]
GO
GRANT UPDATE ON [GroupStopOrders] ([ClassCode]) TO [tm_user] AS [dbo]
GO
GRANT SELECT ON [GroupStopOrders] ([ASecCode]) TO [tm_admin] AS [dbo]
GO
GRANT UPDATE ON [GroupStopOrders] ([ASecCode]) TO [tm_admin] AS [dbo]
GO
GRANT REFERENCES ON [GroupStopOrders] ([ASecCode]) TO [tm_admin] AS [dbo]
GO
GRANT SELECT ON [GroupStopOrders] ([ASecCode]) TO [tm_user] AS [dbo]
GO
GRANT UPDATE ON [GroupStopOrders] ([ASecCode]) TO [tm_user] AS [dbo]
GO
GRANT SELECT ON [GroupStopOrders] ([AClassCode]) TO [tm_admin] AS [dbo]
GO
GRANT UPDATE ON [GroupStopOrders] ([AClassCode]) TO [tm_admin] AS [dbo]
GO
GRANT REFERENCES ON [GroupStopOrders] ([AClassCode]) TO [tm_admin] AS [dbo]
GO
GRANT SELECT ON [GroupStopOrders] ([AClassCode]) TO [tm_user] AS [dbo]
GO
GRANT UPDATE ON [GroupStopOrders] ([AClassCode]) TO [tm_user] AS [dbo]
GO
GRANT SELECT ON [GroupStopOrders] ([StopCond]) TO [tm_admin] AS [dbo]
GO
GRANT UPDATE ON [GroupStopOrders] ([StopCond]) TO [tm_admin] AS [dbo]
GO
GRANT REFERENCES ON [GroupStopOrders] ([StopCond]) TO [tm_admin] AS [dbo]
GO
GRANT SELECT ON [GroupStopOrders] ([StopCond]) TO [tm_user] AS [dbo]
GO
GRANT UPDATE ON [GroupStopOrders] ([StopCond]) TO [tm_user] AS [dbo]
GO
GRANT SELECT ON [GroupStopOrders] ([TransFlags]) TO [tm_admin] AS [dbo]
GO
GRANT UPDATE ON [GroupStopOrders] ([TransFlags]) TO [tm_admin] AS [dbo]
GO
GRANT REFERENCES ON [GroupStopOrders] ([TransFlags]) TO [tm_admin] AS [dbo]
GO
GRANT SELECT ON [GroupStopOrders] ([TransFlags]) TO [tm_user] AS [dbo]
GO
GRANT UPDATE ON [GroupStopOrders] ([TransFlags]) TO [tm_user] AS [dbo]
GO
GRANT SELECT ON [GroupStopOrders] ([StopPrice]) TO [tm_admin] AS [dbo]
GO
GRANT UPDATE ON [GroupStopOrders] ([StopPrice]) TO [tm_admin] AS [dbo]
GO
GRANT REFERENCES ON [GroupStopOrders] ([StopPrice]) TO [tm_admin] AS [dbo]
GO
GRANT SELECT ON [GroupStopOrders] ([StopPrice]) TO [tm_user] AS [dbo]
GO
GRANT UPDATE ON [GroupStopOrders] ([StopPrice]) TO [tm_user] AS [dbo]
GO
GRANT SELECT ON [GroupStopOrders] ([Price]) TO [tm_admin] AS [dbo]
GO
GRANT UPDATE ON [GroupStopOrders] ([Price]) TO [tm_admin] AS [dbo]
GO
GRANT REFERENCES ON [GroupStopOrders] ([Price]) TO [tm_admin] AS [dbo]
GO
GRANT SELECT ON [GroupStopOrders] ([Price]) TO [tm_user] AS [dbo]
GO
GRANT UPDATE ON [GroupStopOrders] ([Price]) TO [tm_user] AS [dbo]
GO
GRANT SELECT ON [GroupStopOrders] ([LinkedPrice]) TO [tm_admin] AS [dbo]
GO
GRANT UPDATE ON [GroupStopOrders] ([LinkedPrice]) TO [tm_admin] AS [dbo]
GO
GRANT REFERENCES ON [GroupStopOrders] ([LinkedPrice]) TO [tm_admin] AS [dbo]
GO
GRANT SELECT ON [GroupStopOrders] ([LinkedPrice]) TO [tm_user] AS [dbo]
GO
GRANT UPDATE ON [GroupStopOrders] ([LinkedPrice]) TO [tm_user] AS [dbo]
GO
GRANT SELECT ON [GroupStopOrders] ([Offset]) TO [tm_admin] AS [dbo]
GO
GRANT UPDATE ON [GroupStopOrders] ([Offset]) TO [tm_admin] AS [dbo]
GO
GRANT REFERENCES ON [GroupStopOrders] ([Offset]) TO [tm_admin] AS [dbo]
GO
GRANT SELECT ON [GroupStopOrders] ([Offset]) TO [tm_user] AS [dbo]
GO
GRANT UPDATE ON [GroupStopOrders] ([Offset]) TO [tm_user] AS [dbo]
GO
GRANT SELECT ON [GroupStopOrders] ([Spread]) TO [tm_admin] AS [dbo]
GO
GRANT UPDATE ON [GroupStopOrders] ([Spread]) TO [tm_admin] AS [dbo]
GO
GRANT REFERENCES ON [GroupStopOrders] ([Spread]) TO [tm_admin] AS [dbo]
GO
GRANT SELECT ON [GroupStopOrders] ([Spread]) TO [tm_user] AS [dbo]
GO
GRANT UPDATE ON [GroupStopOrders] ([Spread]) TO [tm_user] AS [dbo]
GO
GRANT SELECT ON [GroupStopOrders] ([Qty]) TO [tm_admin] AS [dbo]
GO
GRANT UPDATE ON [GroupStopOrders] ([Qty]) TO [tm_admin] AS [dbo]
GO
GRANT REFERENCES ON [GroupStopOrders] ([Qty]) TO [tm_admin] AS [dbo]
GO
GRANT SELECT ON [GroupStopOrders] ([Qty]) TO [tm_user] AS [dbo]
GO
GRANT UPDATE ON [GroupStopOrders] ([Qty]) TO [tm_user] AS [dbo]
GO
GRANT SELECT ON [GroupStopOrders] ([RealQty]) TO [tm_admin] AS [dbo]
GO
GRANT UPDATE ON [GroupStopOrders] ([RealQty]) TO [tm_admin] AS [dbo]
GO
GRANT REFERENCES ON [GroupStopOrders] ([RealQty]) TO [tm_admin] AS [dbo]
GO
GRANT SELECT ON [GroupStopOrders] ([RealQty]) TO [tm_user] AS [dbo]
GO
GRANT UPDATE ON [GroupStopOrders] ([RealQty]) TO [tm_user] AS [dbo]
GO
GRANT SELECT ON [GroupStopOrders] ([BalanceQty]) TO [tm_admin] AS [dbo]
GO
GRANT UPDATE ON [GroupStopOrders] ([BalanceQty]) TO [tm_admin] AS [dbo]
GO
GRANT REFERENCES ON [GroupStopOrders] ([BalanceQty]) TO [tm_admin] AS [dbo]
GO
GRANT SELECT ON [GroupStopOrders] ([BalanceQty]) TO [tm_user] AS [dbo]
GO
GRANT UPDATE ON [GroupStopOrders] ([BalanceQty]) TO [tm_user] AS [dbo]
GO
GRANT SELECT ON [GroupStopOrders] ([KilledQty]) TO [tm_admin] AS [dbo]
GO
GRANT UPDATE ON [GroupStopOrders] ([KilledQty]) TO [tm_admin] AS [dbo]
GO
GRANT REFERENCES ON [GroupStopOrders] ([KilledQty]) TO [tm_admin] AS [dbo]
GO
GRANT SELECT ON [GroupStopOrders] ([KilledQty]) TO [tm_user] AS [dbo]
GO
GRANT UPDATE ON [GroupStopOrders] ([KilledQty]) TO [tm_user] AS [dbo]
GO
GRANT SELECT ON [GroupStopOrders] ([BaseOrderNum]) TO [tm_admin] AS [dbo]
GO
GRANT UPDATE ON [GroupStopOrders] ([BaseOrderNum]) TO [tm_admin] AS [dbo]
GO
GRANT REFERENCES ON [GroupStopOrders] ([BaseOrderNum]) TO [tm_admin] AS [dbo]
GO
GRANT SELECT ON [GroupStopOrders] ([BaseOrderNum]) TO [tm_user] AS [dbo]
GO
GRANT UPDATE ON [GroupStopOrders] ([BaseOrderNum]) TO [tm_user] AS [dbo]
GO
GRANT SELECT ON [GroupStopOrders] ([Status]) TO [tm_admin] AS [dbo]
GO
GRANT UPDATE ON [GroupStopOrders] ([Status]) TO [tm_admin] AS [dbo]
GO
GRANT REFERENCES ON [GroupStopOrders] ([Status]) TO [tm_admin] AS [dbo]
GO
GRANT SELECT ON [GroupStopOrders] ([Status]) TO [tm_user] AS [dbo]
GO
GRANT UPDATE ON [GroupStopOrders] ([Status]) TO [tm_user] AS [dbo]
GO
GRANT SELECT ON [GroupStopOrders] ([Result]) TO [tm_admin] AS [dbo]
GO
GRANT UPDATE ON [GroupStopOrders] ([Result]) TO [tm_admin] AS [dbo]
GO
GRANT REFERENCES ON [GroupStopOrders] ([Result]) TO [tm_admin] AS [dbo]
GO
GRANT SELECT ON [GroupStopOrders] ([Result]) TO [tm_user] AS [dbo]
GO
GRANT UPDATE ON [GroupStopOrders] ([Result]) TO [tm_user] AS [dbo]
GO
GRANT SELECT ON [GroupStopOrders] ([OrdersCount]) TO [tm_admin] AS [dbo]
GO
GRANT UPDATE ON [GroupStopOrders] ([OrdersCount]) TO [tm_admin] AS [dbo]
GO
GRANT REFERENCES ON [GroupStopOrders] ([OrdersCount]) TO [tm_admin] AS [dbo]
GO
GRANT SELECT ON [GroupStopOrders] ([OrdersCount]) TO [tm_user] AS [dbo]
GO
GRANT UPDATE ON [GroupStopOrders] ([OrdersCount]) TO [tm_user] AS [dbo]
GO
GRANT SELECT ON [GroupStopOrders] ([LinkedGrOrder]) TO [tm_admin] AS [dbo]
GO
GRANT UPDATE ON [GroupStopOrders] ([LinkedGrOrder]) TO [tm_admin] AS [dbo]
GO
GRANT REFERENCES ON [GroupStopOrders] ([LinkedGrOrder]) TO [tm_admin] AS [dbo]
GO
GRANT SELECT ON [GroupStopOrders] ([LinkedGrOrder]) TO [tm_user] AS [dbo]
GO
GRANT UPDATE ON [GroupStopOrders] ([LinkedGrOrder]) TO [tm_user] AS [dbo]
GO
GRANT SELECT ON [GroupStopOrders] ([CoOrderNum]) TO [tm_admin] AS [dbo]
GO
GRANT UPDATE ON [GroupStopOrders] ([CoOrderNum]) TO [tm_admin] AS [dbo]
GO
GRANT REFERENCES ON [GroupStopOrders] ([CoOrderNum]) TO [tm_admin] AS [dbo]
GO
GRANT SELECT ON [GroupStopOrders] ([CoOrderNum]) TO [tm_user] AS [dbo]
GO
GRANT UPDATE ON [GroupStopOrders] ([CoOrderNum]) TO [tm_user] AS [dbo]
GO
GRANT SELECT ON [GroupStopOrders] ([Expire]) TO [tm_admin] AS [dbo]
GO
GRANT UPDATE ON [GroupStopOrders] ([Expire]) TO [tm_admin] AS [dbo]
GO
GRANT REFERENCES ON [GroupStopOrders] ([Expire]) TO [tm_admin] AS [dbo]
GO
GRANT SELECT ON [GroupStopOrders] ([Expire]) TO [tm_user] AS [dbo]
GO
GRANT UPDATE ON [GroupStopOrders] ([Expire]) TO [tm_user] AS [dbo]
GO
GRANT SELECT ON [GroupStopOrders] ([StopPrice2]) TO [tm_admin] AS [dbo]
GO
GRANT UPDATE ON [GroupStopOrders] ([StopPrice2]) TO [tm_admin] AS [dbo]
GO
GRANT REFERENCES ON [GroupStopOrders] ([StopPrice2]) TO [tm_admin] AS [dbo]
GO
GRANT SELECT ON [GroupStopOrders] ([StopPrice2]) TO [tm_user] AS [dbo]
GO
GRANT UPDATE ON [GroupStopOrders] ([StopPrice2]) TO [tm_user] AS [dbo]
GO
GRANT SELECT ON [GroupStopOrders] ([ActiveFromTime]) TO [tm_admin] AS [dbo]
GO
GRANT UPDATE ON [GroupStopOrders] ([ActiveFromTime]) TO [tm_admin] AS [dbo]
GO
GRANT REFERENCES ON [GroupStopOrders] ([ActiveFromTime]) TO [tm_admin] AS [dbo]
GO
GRANT SELECT ON [GroupStopOrders] ([ActiveFromTime]) TO [tm_user] AS [dbo]
GO
GRANT UPDATE ON [GroupStopOrders] ([ActiveFromTime]) TO [tm_user] AS [dbo]
GO
GRANT SELECT ON [GroupStopOrders] ([ActiveToTime]) TO [tm_admin] AS [dbo]
GO
GRANT UPDATE ON [GroupStopOrders] ([ActiveToTime]) TO [tm_admin] AS [dbo]
GO
GRANT REFERENCES ON [GroupStopOrders] ([ActiveToTime]) TO [tm_admin] AS [dbo]
GO
GRANT SELECT ON [GroupStopOrders] ([ActiveToTime]) TO [tm_user] AS [dbo]
GO
GRANT UPDATE ON [GroupStopOrders] ([ActiveToTime]) TO [tm_user] AS [dbo]
GO
GRANT SELECT ON [NegOrders] TO [tm_admin] AS [dbo]
GO
GRANT INSERT ON [NegOrders] TO [tm_admin] AS [dbo]
GO
GRANT DELETE ON [NegOrders] TO [tm_admin] AS [dbo]
GO
GRANT UPDATE ON [NegOrders] TO [tm_admin] AS [dbo]
GO
GRANT REFERENCES ON [NegOrders] TO [tm_admin] AS [dbo]
GO
GRANT SELECT ON [NegOrders] TO [tm_user] AS [dbo]
GO
GRANT INSERT ON [NegOrders] TO [tm_user] AS [dbo]
GO
GRANT DELETE ON [NegOrders] TO [tm_user] AS [dbo]
GO
GRANT UPDATE ON [NegOrders] TO [tm_user] AS [dbo]
GO
GRANT SELECT ON [NegOrders] ([OrderId]) TO [tm_admin] AS [dbo]
GO
GRANT UPDATE ON [NegOrders] ([OrderId]) TO [tm_admin] AS [dbo]
GO
GRANT REFERENCES ON [NegOrders] ([OrderId]) TO [tm_admin] AS [dbo]
GO
GRANT SELECT ON [NegOrders] ([OrderId]) TO [tm_user] AS [dbo]
GO
GRANT UPDATE ON [NegOrders] ([OrderId]) TO [tm_user] AS [dbo]
GO
GRANT SELECT ON [NegOrders] ([GroupOrderID]) TO [tm_admin] AS [dbo]
GO
GRANT UPDATE ON [NegOrders] ([GroupOrderID]) TO [tm_admin] AS [dbo]
GO
GRANT REFERENCES ON [NegOrders] ([GroupOrderID]) TO [tm_admin] AS [dbo]
GO
GRANT SELECT ON [NegOrders] ([GroupOrderID]) TO [tm_user] AS [dbo]
GO
GRANT UPDATE ON [NegOrders] ([GroupOrderID]) TO [tm_user] AS [dbo]
GO
GRANT SELECT ON [NegOrders] ([TradeDate]) TO [tm_admin] AS [dbo]
GO
GRANT UPDATE ON [NegOrders] ([TradeDate]) TO [tm_admin] AS [dbo]
GO
GRANT REFERENCES ON [NegOrders] ([TradeDate]) TO [tm_admin] AS [dbo]
GO
GRANT SELECT ON [NegOrders] ([TradeDate]) TO [tm_user] AS [dbo]
GO
GRANT UPDATE ON [NegOrders] ([TradeDate]) TO [tm_user] AS [dbo]
GO
GRANT SELECT ON [NegOrders] ([TradeTime]) TO [tm_admin] AS [dbo]
GO
GRANT UPDATE ON [NegOrders] ([TradeTime]) TO [tm_admin] AS [dbo]
GO
GRANT REFERENCES ON [NegOrders] ([TradeTime]) TO [tm_admin] AS [dbo]
GO
GRANT SELECT ON [NegOrders] ([TradeTime]) TO [tm_user] AS [dbo]
GO
GRANT UPDATE ON [NegOrders] ([TradeTime]) TO [tm_user] AS [dbo]
GO
GRANT SELECT ON [NegOrders] ([Buy]) TO [tm_admin] AS [dbo]
GO
GRANT UPDATE ON [NegOrders] ([Buy]) TO [tm_admin] AS [dbo]
GO
GRANT REFERENCES ON [NegOrders] ([Buy]) TO [tm_admin] AS [dbo]
GO
GRANT SELECT ON [NegOrders] ([Buy]) TO [tm_user] AS [dbo]
GO
GRANT UPDATE ON [NegOrders] ([Buy]) TO [tm_user] AS [dbo]
GO
GRANT SELECT ON [NegOrders] ([ClassCode]) TO [tm_admin] AS [dbo]
GO
GRANT UPDATE ON [NegOrders] ([ClassCode]) TO [tm_admin] AS [dbo]
GO
GRANT REFERENCES ON [NegOrders] ([ClassCode]) TO [tm_admin] AS [dbo]
GO
GRANT SELECT ON [NegOrders] ([ClassCode]) TO [tm_user] AS [dbo]
GO
GRANT UPDATE ON [NegOrders] ([ClassCode]) TO [tm_user] AS [dbo]
GO
GRANT SELECT ON [NegOrders] ([SecCode]) TO [tm_admin] AS [dbo]
GO
GRANT UPDATE ON [NegOrders] ([SecCode]) TO [tm_admin] AS [dbo]
GO
GRANT REFERENCES ON [NegOrders] ([SecCode]) TO [tm_admin] AS [dbo]
GO
GRANT SELECT ON [NegOrders] ([SecCode]) TO [tm_user] AS [dbo]
GO
GRANT UPDATE ON [NegOrders] ([SecCode]) TO [tm_user] AS [dbo]
GO
GRANT SELECT ON [NegOrders] ([ClientCode]) TO [tm_admin] AS [dbo]
GO
GRANT UPDATE ON [NegOrders] ([ClientCode]) TO [tm_admin] AS [dbo]
GO
GRANT REFERENCES ON [NegOrders] ([ClientCode]) TO [tm_admin] AS [dbo]
GO
GRANT SELECT ON [NegOrders] ([ClientCode]) TO [tm_user] AS [dbo]
GO
GRANT UPDATE ON [NegOrders] ([ClientCode]) TO [tm_user] AS [dbo]
GO
GRANT SELECT ON [NegOrders] ([TrdAcc]) TO [tm_admin] AS [dbo]
GO
GRANT UPDATE ON [NegOrders] ([TrdAcc]) TO [tm_admin] AS [dbo]
GO
GRANT REFERENCES ON [NegOrders] ([TrdAcc]) TO [tm_admin] AS [dbo]
GO
GRANT SELECT ON [NegOrders] ([TrdAcc]) TO [tm_user] AS [dbo]
GO
GRANT UPDATE ON [NegOrders] ([TrdAcc]) TO [tm_user] AS [dbo]
GO
GRANT SELECT ON [NegOrders] ([CPFirmId]) TO [tm_admin] AS [dbo]
GO
GRANT UPDATE ON [NegOrders] ([CPFirmId]) TO [tm_admin] AS [dbo]
GO
GRANT REFERENCES ON [NegOrders] ([CPFirmId]) TO [tm_admin] AS [dbo]
GO
GRANT SELECT ON [NegOrders] ([CPFirmId]) TO [tm_user] AS [dbo]
GO
GRANT UPDATE ON [NegOrders] ([CPFirmId]) TO [tm_user] AS [dbo]
GO
GRANT SELECT ON [NegOrders] ([SettleCode]) TO [tm_admin] AS [dbo]
GO
GRANT UPDATE ON [NegOrders] ([SettleCode]) TO [tm_admin] AS [dbo]
GO
GRANT REFERENCES ON [NegOrders] ([SettleCode]) TO [tm_admin] AS [dbo]
GO
GRANT SELECT ON [NegOrders] ([SettleCode]) TO [tm_user] AS [dbo]
GO
GRANT UPDATE ON [NegOrders] ([SettleCode]) TO [tm_user] AS [dbo]
GO
GRANT SELECT ON [NegOrders] ([MatchRef]) TO [tm_admin] AS [dbo]
GO
GRANT UPDATE ON [NegOrders] ([MatchRef]) TO [tm_admin] AS [dbo]
GO
GRANT REFERENCES ON [NegOrders] ([MatchRef]) TO [tm_admin] AS [dbo]
GO
GRANT SELECT ON [NegOrders] ([MatchRef]) TO [tm_user] AS [dbo]
GO
GRANT UPDATE ON [NegOrders] ([MatchRef]) TO [tm_user] AS [dbo]
GO
GRANT SELECT ON [NegOrders] ([Price]) TO [tm_admin] AS [dbo]
GO
GRANT UPDATE ON [NegOrders] ([Price]) TO [tm_admin] AS [dbo]
GO
GRANT REFERENCES ON [NegOrders] ([Price]) TO [tm_admin] AS [dbo]
GO
GRANT SELECT ON [NegOrders] ([Price]) TO [tm_user] AS [dbo]
GO
GRANT UPDATE ON [NegOrders] ([Price]) TO [tm_user] AS [dbo]
GO
GRANT SELECT ON [NegOrders] ([Vozm]) TO [tm_admin] AS [dbo]
GO
GRANT UPDATE ON [NegOrders] ([Vozm]) TO [tm_admin] AS [dbo]
GO
GRANT REFERENCES ON [NegOrders] ([Vozm]) TO [tm_admin] AS [dbo]
GO
GRANT SELECT ON [NegOrders] ([Vozm]) TO [tm_user] AS [dbo]
GO
GRANT UPDATE ON [NegOrders] ([Vozm]) TO [tm_user] AS [dbo]
GO
GRANT SELECT ON [NegOrders] ([Qty]) TO [tm_admin] AS [dbo]
GO
GRANT UPDATE ON [NegOrders] ([Qty]) TO [tm_admin] AS [dbo]
GO
GRANT REFERENCES ON [NegOrders] ([Qty]) TO [tm_admin] AS [dbo]
GO
GRANT SELECT ON [NegOrders] ([Qty]) TO [tm_user] AS [dbo]
GO
GRANT UPDATE ON [NegOrders] ([Qty]) TO [tm_user] AS [dbo]
GO
GRANT SELECT ON [NegOrders] ([OrderNum]) TO [tm_admin] AS [dbo]
GO
GRANT UPDATE ON [NegOrders] ([OrderNum]) TO [tm_admin] AS [dbo]
GO
GRANT REFERENCES ON [NegOrders] ([OrderNum]) TO [tm_admin] AS [dbo]
GO
GRANT SELECT ON [NegOrders] ([OrderNum]) TO [tm_user] AS [dbo]
GO
GRANT UPDATE ON [NegOrders] ([OrderNum]) TO [tm_user] AS [dbo]
GO
GRANT SELECT ON [NegOrders] ([Status]) TO [tm_admin] AS [dbo]
GO
GRANT UPDATE ON [NegOrders] ([Status]) TO [tm_admin] AS [dbo]
GO
GRANT REFERENCES ON [NegOrders] ([Status]) TO [tm_admin] AS [dbo]
GO
GRANT SELECT ON [NegOrders] ([Status]) TO [tm_user] AS [dbo]
GO
GRANT UPDATE ON [NegOrders] ([Status]) TO [tm_user] AS [dbo]
GO
GRANT SELECT ON [NegOrders] ([Result]) TO [tm_admin] AS [dbo]
GO
GRANT UPDATE ON [NegOrders] ([Result]) TO [tm_admin] AS [dbo]
GO
GRANT REFERENCES ON [NegOrders] ([Result]) TO [tm_admin] AS [dbo]
GO
GRANT SELECT ON [NegOrders] ([Result]) TO [tm_user] AS [dbo]
GO
GRANT UPDATE ON [NegOrders] ([Result]) TO [tm_user] AS [dbo]
GO
GRANT SELECT ON [GroupNegOrders] TO [tm_admin] AS [dbo]
GO
GRANT INSERT ON [GroupNegOrders] TO [tm_admin] AS [dbo]
GO
GRANT DELETE ON [GroupNegOrders] TO [tm_admin] AS [dbo]
GO
GRANT UPDATE ON [GroupNegOrders] TO [tm_admin] AS [dbo]
GO
GRANT REFERENCES ON [GroupNegOrders] TO [tm_admin] AS [dbo]
GO
GRANT SELECT ON [GroupNegOrders] TO [tm_user] AS [dbo]
GO
GRANT INSERT ON [GroupNegOrders] TO [tm_user] AS [dbo]
GO
GRANT DELETE ON [GroupNegOrders] TO [tm_user] AS [dbo]
GO
GRANT UPDATE ON [GroupNegOrders] TO [tm_user] AS [dbo]
GO
GRANT SELECT ON [GroupNegOrders] ([ID]) TO [tm_admin] AS [dbo]
GO
GRANT UPDATE ON [GroupNegOrders] ([ID]) TO [tm_admin] AS [dbo]
GO
GRANT REFERENCES ON [GroupNegOrders] ([ID]) TO [tm_admin] AS [dbo]
GO
GRANT SELECT ON [GroupNegOrders] ([ID]) TO [tm_user] AS [dbo]
GO
GRANT UPDATE ON [GroupNegOrders] ([ID]) TO [tm_user] AS [dbo]
GO
GRANT SELECT ON [GroupNegOrders] ([GroupID]) TO [tm_admin] AS [dbo]
GO
GRANT UPDATE ON [GroupNegOrders] ([GroupID]) TO [tm_admin] AS [dbo]
GO
GRANT REFERENCES ON [GroupNegOrders] ([GroupID]) TO [tm_admin] AS [dbo]
GO
GRANT SELECT ON [GroupNegOrders] ([GroupID]) TO [tm_user] AS [dbo]
GO
GRANT UPDATE ON [GroupNegOrders] ([GroupID]) TO [tm_user] AS [dbo]
GO
GRANT SELECT ON [GroupNegOrders] ([TradeDate]) TO [tm_admin] AS [dbo]
GO
GRANT UPDATE ON [GroupNegOrders] ([TradeDate]) TO [tm_admin] AS [dbo]
GO
GRANT REFERENCES ON [GroupNegOrders] ([TradeDate]) TO [tm_admin] AS [dbo]
GO
GRANT SELECT ON [GroupNegOrders] ([TradeDate]) TO [tm_user] AS [dbo]
GO
GRANT UPDATE ON [GroupNegOrders] ([TradeDate]) TO [tm_user] AS [dbo]
GO
GRANT SELECT ON [GroupNegOrders] ([TradeTime]) TO [tm_admin] AS [dbo]
GO
GRANT UPDATE ON [GroupNegOrders] ([TradeTime]) TO [tm_admin] AS [dbo]
GO
GRANT REFERENCES ON [GroupNegOrders] ([TradeTime]) TO [tm_admin] AS [dbo]
GO
GRANT SELECT ON [GroupNegOrders] ([TradeTime]) TO [tm_user] AS [dbo]
GO
GRANT UPDATE ON [GroupNegOrders] ([TradeTime]) TO [tm_user] AS [dbo]
GO
GRANT SELECT ON [GroupNegOrders] ([Buy]) TO [tm_admin] AS [dbo]
GO
GRANT UPDATE ON [GroupNegOrders] ([Buy]) TO [tm_admin] AS [dbo]
GO
GRANT REFERENCES ON [GroupNegOrders] ([Buy]) TO [tm_admin] AS [dbo]
GO
GRANT SELECT ON [GroupNegOrders] ([Buy]) TO [tm_user] AS [dbo]
GO
GRANT UPDATE ON [GroupNegOrders] ([Buy]) TO [tm_user] AS [dbo]
GO
GRANT SELECT ON [GroupNegOrders] ([SecCode]) TO [tm_admin] AS [dbo]
GO
GRANT UPDATE ON [GroupNegOrders] ([SecCode]) TO [tm_admin] AS [dbo]
GO
GRANT REFERENCES ON [GroupNegOrders] ([SecCode]) TO [tm_admin] AS [dbo]
GO
GRANT SELECT ON [GroupNegOrders] ([SecCode]) TO [tm_user] AS [dbo]
GO
GRANT UPDATE ON [GroupNegOrders] ([SecCode]) TO [tm_user] AS [dbo]
GO
GRANT SELECT ON [GroupNegOrders] ([ClassCode]) TO [tm_admin] AS [dbo]
GO
GRANT UPDATE ON [GroupNegOrders] ([ClassCode]) TO [tm_admin] AS [dbo]
GO
GRANT REFERENCES ON [GroupNegOrders] ([ClassCode]) TO [tm_admin] AS [dbo]
GO
GRANT SELECT ON [GroupNegOrders] ([ClassCode]) TO [tm_user] AS [dbo]
GO
GRANT UPDATE ON [GroupNegOrders] ([ClassCode]) TO [tm_user] AS [dbo]
GO
GRANT SELECT ON [GroupNegOrders] ([CPFirmID]) TO [tm_admin] AS [dbo]
GO
GRANT UPDATE ON [GroupNegOrders] ([CPFirmID]) TO [tm_admin] AS [dbo]
GO
GRANT REFERENCES ON [GroupNegOrders] ([CPFirmID]) TO [tm_admin] AS [dbo]
GO
GRANT SELECT ON [GroupNegOrders] ([CPFirmID]) TO [tm_user] AS [dbo]
GO
GRANT UPDATE ON [GroupNegOrders] ([CPFirmID]) TO [tm_user] AS [dbo]
GO
GRANT SELECT ON [GroupNegOrders] ([SettleCode]) TO [tm_admin] AS [dbo]
GO
GRANT UPDATE ON [GroupNegOrders] ([SettleCode]) TO [tm_admin] AS [dbo]
GO
GRANT REFERENCES ON [GroupNegOrders] ([SettleCode]) TO [tm_admin] AS [dbo]
GO
GRANT SELECT ON [GroupNegOrders] ([SettleCode]) TO [tm_user] AS [dbo]
GO
GRANT UPDATE ON [GroupNegOrders] ([SettleCode]) TO [tm_user] AS [dbo]
GO
GRANT SELECT ON [GroupNegOrders] ([MatchRef]) TO [tm_admin] AS [dbo]
GO
GRANT UPDATE ON [GroupNegOrders] ([MatchRef]) TO [tm_admin] AS [dbo]
GO
GRANT REFERENCES ON [GroupNegOrders] ([MatchRef]) TO [tm_admin] AS [dbo]
GO
GRANT SELECT ON [GroupNegOrders] ([MatchRef]) TO [tm_user] AS [dbo]
GO
GRANT UPDATE ON [GroupNegOrders] ([MatchRef]) TO [tm_user] AS [dbo]
GO
GRANT SELECT ON [GroupNegOrders] ([Price]) TO [tm_admin] AS [dbo]
GO
GRANT UPDATE ON [GroupNegOrders] ([Price]) TO [tm_admin] AS [dbo]
GO
GRANT REFERENCES ON [GroupNegOrders] ([Price]) TO [tm_admin] AS [dbo]
GO
GRANT SELECT ON [GroupNegOrders] ([Price]) TO [tm_user] AS [dbo]
GO
GRANT UPDATE ON [GroupNegOrders] ([Price]) TO [tm_user] AS [dbo]
GO
GRANT SELECT ON [GroupNegOrders] ([Vozm]) TO [tm_admin] AS [dbo]
GO
GRANT UPDATE ON [GroupNegOrders] ([Vozm]) TO [tm_admin] AS [dbo]
GO
GRANT REFERENCES ON [GroupNegOrders] ([Vozm]) TO [tm_admin] AS [dbo]
GO
GRANT SELECT ON [GroupNegOrders] ([Vozm]) TO [tm_user] AS [dbo]
GO
GRANT UPDATE ON [GroupNegOrders] ([Vozm]) TO [tm_user] AS [dbo]
GO
GRANT SELECT ON [GroupNegOrders] ([Qty]) TO [tm_admin] AS [dbo]
GO
GRANT UPDATE ON [GroupNegOrders] ([Qty]) TO [tm_admin] AS [dbo]
GO
GRANT REFERENCES ON [GroupNegOrders] ([Qty]) TO [tm_admin] AS [dbo]
GO
GRANT SELECT ON [GroupNegOrders] ([Qty]) TO [tm_user] AS [dbo]
GO
GRANT UPDATE ON [GroupNegOrders] ([Qty]) TO [tm_user] AS [dbo]
GO
GRANT SELECT ON [GroupNegOrders] ([RealQty]) TO [tm_admin] AS [dbo]
GO
GRANT UPDATE ON [GroupNegOrders] ([RealQty]) TO [tm_admin] AS [dbo]
GO
GRANT REFERENCES ON [GroupNegOrders] ([RealQty]) TO [tm_admin] AS [dbo]
GO
GRANT SELECT ON [GroupNegOrders] ([RealQty]) TO [tm_user] AS [dbo]
GO
GRANT UPDATE ON [GroupNegOrders] ([RealQty]) TO [tm_user] AS [dbo]
GO
GRANT SELECT ON [GroupNegOrders] ([KilledQty]) TO [tm_admin] AS [dbo]
GO
GRANT UPDATE ON [GroupNegOrders] ([KilledQty]) TO [tm_admin] AS [dbo]
GO
GRANT REFERENCES ON [GroupNegOrders] ([KilledQty]) TO [tm_admin] AS [dbo]
GO
GRANT SELECT ON [GroupNegOrders] ([KilledQty]) TO [tm_user] AS [dbo]
GO
GRANT UPDATE ON [GroupNegOrders] ([KilledQty]) TO [tm_user] AS [dbo]
GO
GRANT SELECT ON [GroupNegOrders] ([Status]) TO [tm_admin] AS [dbo]
GO
GRANT UPDATE ON [GroupNegOrders] ([Status]) TO [tm_admin] AS [dbo]
GO
GRANT REFERENCES ON [GroupNegOrders] ([Status]) TO [tm_admin] AS [dbo]
GO
GRANT SELECT ON [GroupNegOrders] ([Status]) TO [tm_user] AS [dbo]
GO
GRANT UPDATE ON [GroupNegOrders] ([Status]) TO [tm_user] AS [dbo]
GO
GRANT SELECT ON [GroupNegOrders] ([Result]) TO [tm_admin] AS [dbo]
GO
GRANT UPDATE ON [GroupNegOrders] ([Result]) TO [tm_admin] AS [dbo]
GO
GRANT REFERENCES ON [GroupNegOrders] ([Result]) TO [tm_admin] AS [dbo]
GO
GRANT SELECT ON [GroupNegOrders] ([Result]) TO [tm_user] AS [dbo]
GO
GRANT UPDATE ON [GroupNegOrders] ([Result]) TO [tm_user] AS [dbo]
GO
GRANT SELECT ON [GroupNegOrders] ([OrdersCount]) TO [tm_admin] AS [dbo]
GO
GRANT UPDATE ON [GroupNegOrders] ([OrdersCount]) TO [tm_admin] AS [dbo]
GO
GRANT REFERENCES ON [GroupNegOrders] ([OrdersCount]) TO [tm_admin] AS [dbo]
GO
GRANT SELECT ON [GroupNegOrders] ([OrdersCount]) TO [tm_user] AS [dbo]
GO
GRANT UPDATE ON [GroupNegOrders] ([OrdersCount]) TO [tm_user] AS [dbo]
GO
GRANT SELECT ON [ExportOrder] TO [tm_admin] AS [dbo]
GO
GRANT INSERT ON [ExportOrder] TO [tm_admin] AS [dbo]
GO
GRANT DELETE ON [ExportOrder] TO [tm_admin] AS [dbo]
GO
GRANT UPDATE ON [ExportOrder] TO [tm_admin] AS [dbo]
GO
GRANT SELECT ON [ExportOrder] TO [tm_user] AS [dbo]
GO
GRANT INSERT ON [ExportOrder] TO [tm_user] AS [dbo]
GO
GRANT DELETE ON [ExportOrder] TO [tm_user] AS [dbo]
GO
GRANT UPDATE ON [ExportOrder] TO [tm_user] AS [dbo]
GO
GRANT SELECT ON [ExportOrder] ([ID]) TO [tm_admin] AS [dbo]
GO
GRANT UPDATE ON [ExportOrder] ([ID]) TO [tm_admin] AS [dbo]
GO
GRANT SELECT ON [ExportOrder] ([ID]) TO [tm_user] AS [dbo]
GO
GRANT UPDATE ON [ExportOrder] ([ID]) TO [tm_user] AS [dbo]
GO
GRANT SELECT ON [ExportOrder] ([OrderID]) TO [tm_admin] AS [dbo]
GO
GRANT UPDATE ON [ExportOrder] ([OrderID]) TO [tm_admin] AS [dbo]
GO
GRANT SELECT ON [ExportOrder] ([OrderID]) TO [tm_user] AS [dbo]
GO
GRANT UPDATE ON [ExportOrder] ([OrderID]) TO [tm_user] AS [dbo]
GO
GRANT SELECT ON [ExportOrder] ([GroupOrderID]) TO [tm_admin] AS [dbo]
GO
GRANT UPDATE ON [ExportOrder] ([GroupOrderID]) TO [tm_admin] AS [dbo]
GO
GRANT SELECT ON [ExportOrder] ([GroupOrderID]) TO [tm_user] AS [dbo]
GO
GRANT UPDATE ON [ExportOrder] ([GroupOrderID]) TO [tm_user] AS [dbo]
GO
GRANT SELECT ON [ExportOrder] ([OrderType]) TO [tm_admin] AS [dbo]
GO
GRANT UPDATE ON [ExportOrder] ([OrderType]) TO [tm_admin] AS [dbo]
GO
GRANT SELECT ON [ExportOrder] ([OrderType]) TO [tm_user] AS [dbo]
GO
GRANT UPDATE ON [ExportOrder] ([OrderType]) TO [tm_user] AS [dbo]
GO
GRANT SELECT ON [ExportOrder] ([TradeDate]) TO [tm_admin] AS [dbo]
GO
GRANT UPDATE ON [ExportOrder] ([TradeDate]) TO [tm_admin] AS [dbo]
GO
GRANT SELECT ON [ExportOrder] ([TradeDate]) TO [tm_user] AS [dbo]
GO
GRANT UPDATE ON [ExportOrder] ([TradeDate]) TO [tm_user] AS [dbo]
GO
GRANT SELECT ON [ExportOrder] ([SendDate]) TO [tm_admin] AS [dbo]
GO
GRANT UPDATE ON [ExportOrder] ([SendDate]) TO [tm_admin] AS [dbo]
GO
GRANT SELECT ON [ExportOrder] ([SendDate]) TO [tm_user] AS [dbo]
GO
GRANT UPDATE ON [ExportOrder] ([SendDate]) TO [tm_user] AS [dbo]
GO
GRANT SELECT ON [ExportOrder] ([SendTime]) TO [tm_admin] AS [dbo]
GO
GRANT UPDATE ON [ExportOrder] ([SendTime]) TO [tm_admin] AS [dbo]
GO
GRANT SELECT ON [ExportOrder] ([SendTime]) TO [tm_user] AS [dbo]
GO
GRANT UPDATE ON [ExportOrder] ([SendTime]) TO [tm_user] AS [dbo]
GO
GRANT SELECT ON [ExportOrder] ([OrderTime]) TO [tm_admin] AS [dbo]
GO
GRANT UPDATE ON [ExportOrder] ([OrderTime]) TO [tm_admin] AS [dbo]
GO
GRANT SELECT ON [ExportOrder] ([OrderTime]) TO [tm_user] AS [dbo]
GO
GRANT UPDATE ON [ExportOrder] ([OrderTime]) TO [tm_user] AS [dbo]
GO
GRANT SELECT ON [ExportOrder] ([Status]) TO [tm_admin] AS [dbo]
GO
GRANT UPDATE ON [ExportOrder] ([Status]) TO [tm_admin] AS [dbo]
GO
GRANT SELECT ON [ExportOrder] ([Status]) TO [tm_user] AS [dbo]
GO
GRANT UPDATE ON [ExportOrder] ([Status]) TO [tm_user] AS [dbo]
GO
GRANT SELECT ON [ExportOrder] ([UserGroupID]) TO [tm_admin] AS [dbo]
GO
GRANT UPDATE ON [ExportOrder] ([UserGroupID]) TO [tm_admin] AS [dbo]
GO
GRANT SELECT ON [ExportOrder] ([UserGroupID]) TO [tm_user] AS [dbo]
GO
GRANT UPDATE ON [ExportOrder] ([UserGroupID]) TO [tm_user] AS [dbo]
GO
GRANT SELECT ON [ExportOrder] ([UserGroupCode]) TO [tm_admin] AS [dbo]
GO
GRANT UPDATE ON [ExportOrder] ([UserGroupCode]) TO [tm_admin] AS [dbo]
GO
GRANT SELECT ON [ExportOrder] ([UserGroupCode]) TO [tm_user] AS [dbo]
GO
GRANT UPDATE ON [ExportOrder] ([UserGroupCode]) TO [tm_user] AS [dbo]
GO
GRANT SELECT ON [ExportOrder] ([PoolID]) TO [tm_admin] AS [dbo]
GO
GRANT UPDATE ON [ExportOrder] ([PoolID]) TO [tm_admin] AS [dbo]
GO
GRANT SELECT ON [ExportOrder] ([PoolID]) TO [tm_user] AS [dbo]
GO
GRANT UPDATE ON [ExportOrder] ([PoolID]) TO [tm_user] AS [dbo]
GO
GRANT SELECT ON [ExportOrder] ([BrokerPoolID]) TO [tm_admin] AS [dbo]
GO
GRANT UPDATE ON [ExportOrder] ([BrokerPoolID]) TO [tm_admin] AS [dbo]
GO
GRANT SELECT ON [ExportOrder] ([BrokerPoolID]) TO [tm_user] AS [dbo]
GO
GRANT UPDATE ON [ExportOrder] ([BrokerPoolID]) TO [tm_user] AS [dbo]
GO
GRANT SELECT ON [ExportOrder] ([ClientCode]) TO [tm_admin] AS [dbo]
GO
GRANT UPDATE ON [ExportOrder] ([ClientCode]) TO [tm_admin] AS [dbo]
GO
GRANT SELECT ON [ExportOrder] ([ClientCode]) TO [tm_user] AS [dbo]
GO
GRANT UPDATE ON [ExportOrder] ([ClientCode]) TO [tm_user] AS [dbo]
GO
GRANT SELECT ON [ExportOrder] ([TrdAcc]) TO [tm_admin] AS [dbo]
GO
GRANT UPDATE ON [ExportOrder] ([TrdAcc]) TO [tm_admin] AS [dbo]
GO
GRANT SELECT ON [ExportOrder] ([TrdAcc]) TO [tm_user] AS [dbo]
GO
GRANT UPDATE ON [ExportOrder] ([TrdAcc]) TO [tm_user] AS [dbo]
GO
GRANT SELECT ON [ExportOrder] ([Price]) TO [tm_admin] AS [dbo]
GO
GRANT UPDATE ON [ExportOrder] ([Price]) TO [tm_admin] AS [dbo]
GO
GRANT SELECT ON [ExportOrder] ([Price]) TO [tm_user] AS [dbo]
GO
GRANT UPDATE ON [ExportOrder] ([Price]) TO [tm_user] AS [dbo]
GO
GRANT SELECT ON [ExportOrder] ([Qty]) TO [tm_admin] AS [dbo]
GO
GRANT UPDATE ON [ExportOrder] ([Qty]) TO [tm_admin] AS [dbo]
GO
GRANT SELECT ON [ExportOrder] ([Qty]) TO [tm_user] AS [dbo]
GO
GRANT UPDATE ON [ExportOrder] ([Qty]) TO [tm_user] AS [dbo]
GO
GRANT SELECT ON [ExportOrder] ([Balance]) TO [tm_admin] AS [dbo]
GO
GRANT UPDATE ON [ExportOrder] ([Balance]) TO [tm_admin] AS [dbo]
GO
GRANT SELECT ON [ExportOrder] ([Balance]) TO [tm_user] AS [dbo]
GO
GRANT UPDATE ON [ExportOrder] ([Balance]) TO [tm_user] AS [dbo]
GO
GRANT SELECT ON [ExportOrder] ([Buy]) TO [tm_admin] AS [dbo]
GO
GRANT UPDATE ON [ExportOrder] ([Buy]) TO [tm_admin] AS [dbo]
GO
GRANT SELECT ON [ExportOrder] ([Buy]) TO [tm_user] AS [dbo]
GO
GRANT UPDATE ON [ExportOrder] ([Buy]) TO [tm_user] AS [dbo]
GO
GRANT SELECT ON [ExportOrder] ([ML]) TO [tm_admin] AS [dbo]
GO
GRANT UPDATE ON [ExportOrder] ([ML]) TO [tm_admin] AS [dbo]
GO
GRANT SELECT ON [ExportOrder] ([ML]) TO [tm_user] AS [dbo]
GO
GRANT UPDATE ON [ExportOrder] ([ML]) TO [tm_user] AS [dbo]
GO
GRANT SELECT ON [ExportOrder] ([ClassCode]) TO [tm_admin] AS [dbo]
GO
GRANT UPDATE ON [ExportOrder] ([ClassCode]) TO [tm_admin] AS [dbo]
GO
GRANT SELECT ON [ExportOrder] ([ClassCode]) TO [tm_user] AS [dbo]
GO
GRANT UPDATE ON [ExportOrder] ([ClassCode]) TO [tm_user] AS [dbo]
GO
GRANT SELECT ON [ExportOrder] ([SecCode]) TO [tm_admin] AS [dbo]
GO
GRANT UPDATE ON [ExportOrder] ([SecCode]) TO [tm_admin] AS [dbo]
GO
GRANT SELECT ON [ExportOrder] ([SecCode]) TO [tm_user] AS [dbo]
GO
GRANT UPDATE ON [ExportOrder] ([SecCode]) TO [tm_user] AS [dbo]
GO
GRANT SELECT ON [ExportOrder] ([VisibleQty]) TO [tm_admin] AS [dbo]
GO
GRANT UPDATE ON [ExportOrder] ([VisibleQty]) TO [tm_admin] AS [dbo]
GO
GRANT SELECT ON [ExportOrder] ([VisibleQty]) TO [tm_user] AS [dbo]
GO
GRANT UPDATE ON [ExportOrder] ([VisibleQty]) TO [tm_user] AS [dbo]
GO
GRANT SELECT ON [GroupDesc] TO [tm_admin] AS [dbo]
GO
GRANT INSERT ON [GroupDesc] TO [tm_admin] AS [dbo]
GO
GRANT DELETE ON [GroupDesc] TO [tm_admin] AS [dbo]
GO
GRANT UPDATE ON [GroupDesc] TO [tm_admin] AS [dbo]
GO
GRANT REFERENCES ON [GroupDesc] TO [tm_admin] AS [dbo]
GO
GRANT SELECT ON [GroupDesc] TO [tm_user] AS [dbo]
GO
GRANT SELECT ON [GroupDesc] ([GroupID]) TO [tm_admin] AS [dbo]
GO
GRANT UPDATE ON [GroupDesc] ([GroupID]) TO [tm_admin] AS [dbo]
GO
GRANT REFERENCES ON [GroupDesc] ([GroupID]) TO [tm_admin] AS [dbo]
GO
GRANT SELECT ON [GroupDesc] ([GroupID]) TO [tm_user] AS [dbo]
GO
GRANT SELECT ON [GroupDesc] ([GroupCode]) TO [tm_admin] AS [dbo]
GO
GRANT UPDATE ON [GroupDesc] ([GroupCode]) TO [tm_admin] AS [dbo]
GO
GRANT REFERENCES ON [GroupDesc] ([GroupCode]) TO [tm_admin] AS [dbo]
GO
GRANT SELECT ON [GroupDesc] ([GroupCode]) TO [tm_user] AS [dbo]
GO
GRANT SELECT ON [GroupDesc] ([GroupName]) TO [tm_admin] AS [dbo]
GO
GRANT UPDATE ON [GroupDesc] ([GroupName]) TO [tm_admin] AS [dbo]
GO
GRANT REFERENCES ON [GroupDesc] ([GroupName]) TO [tm_admin] AS [dbo]
GO
GRANT SELECT ON [GroupDesc] ([GroupName]) TO [tm_user] AS [dbo]
GO
GRANT SELECT ON [GroupDesc] ([disabled]) TO [tm_admin] AS [dbo]
GO
GRANT UPDATE ON [GroupDesc] ([disabled]) TO [tm_admin] AS [dbo]
GO
GRANT REFERENCES ON [GroupDesc] ([disabled]) TO [tm_admin] AS [dbo]
GO
GRANT SELECT ON [GroupDesc] ([disabled]) TO [tm_user] AS [dbo]
GO
GRANT SELECT ON [GroupDesc] ([Mode]) TO [tm_admin] AS [dbo]
GO
GRANT UPDATE ON [GroupDesc] ([Mode]) TO [tm_admin] AS [dbo]
GO
GRANT REFERENCES ON [GroupDesc] ([Mode]) TO [tm_admin] AS [dbo]
GO
GRANT SELECT ON [GroupDesc] ([Mode]) TO [tm_user] AS [dbo]
GO
GRANT SELECT ON [GroupDesc] ([DefWeight]) TO [tm_admin] AS [dbo]
GO
GRANT UPDATE ON [GroupDesc] ([DefWeight]) TO [tm_admin] AS [dbo]
GO
GRANT REFERENCES ON [GroupDesc] ([DefWeight]) TO [tm_admin] AS [dbo]
GO
GRANT SELECT ON [GroupDesc] ([DefWeight]) TO [tm_user] AS [dbo]
GO
GRANT SELECT ON [GroupDesc] ([SplitOrders]) TO [tm_admin] AS [dbo]
GO
GRANT UPDATE ON [GroupDesc] ([SplitOrders]) TO [tm_admin] AS [dbo]
GO
GRANT REFERENCES ON [GroupDesc] ([SplitOrders]) TO [tm_admin] AS [dbo]
GO
GRANT SELECT ON [GroupDesc] ([SplitOrders]) TO [tm_user] AS [dbo]
GO
GRANT SELECT ON [Restrictions] TO [tm_admin] AS [dbo]
GO
GRANT INSERT ON [Restrictions] TO [tm_admin] AS [dbo]
GO
GRANT DELETE ON [Restrictions] TO [tm_admin] AS [dbo]
GO
GRANT UPDATE ON [Restrictions] TO [tm_admin] AS [dbo]
GO
GRANT REFERENCES ON [Restrictions] TO [tm_admin] AS [dbo]
GO
GRANT SELECT ON [Restrictions] TO [tm_user] AS [dbo]
GO
GRANT SELECT ON [Restrictions] ([ID]) TO [tm_admin] AS [dbo]
GO
GRANT UPDATE ON [Restrictions] ([ID]) TO [tm_admin] AS [dbo]
GO
GRANT REFERENCES ON [Restrictions] ([ID]) TO [tm_admin] AS [dbo]
GO
GRANT SELECT ON [Restrictions] ([ID]) TO [tm_user] AS [dbo]
GO
GRANT SELECT ON [Restrictions] ([RestType]) TO [tm_admin] AS [dbo]
GO
GRANT UPDATE ON [Restrictions] ([RestType]) TO [tm_admin] AS [dbo]
GO
GRANT REFERENCES ON [Restrictions] ([RestType]) TO [tm_admin] AS [dbo]
GO
GRANT SELECT ON [Restrictions] ([RestType]) TO [tm_user] AS [dbo]
GO
GRANT SELECT ON [Restrictions] ([Client]) TO [tm_admin] AS [dbo]
GO
GRANT UPDATE ON [Restrictions] ([Client]) TO [tm_admin] AS [dbo]
GO
GRANT REFERENCES ON [Restrictions] ([Client]) TO [tm_admin] AS [dbo]
GO
GRANT SELECT ON [Restrictions] ([Client]) TO [tm_user] AS [dbo]
GO
GRANT SELECT ON [Restrictions] ([Mode]) TO [tm_admin] AS [dbo]
GO
GRANT UPDATE ON [Restrictions] ([Mode]) TO [tm_admin] AS [dbo]
GO
GRANT REFERENCES ON [Restrictions] ([Mode]) TO [tm_admin] AS [dbo]
GO
GRANT SELECT ON [Restrictions] ([Mode]) TO [tm_user] AS [dbo]
GO
GRANT SELECT ON [Restrictions] ([Limit]) TO [tm_admin] AS [dbo]
GO
GRANT UPDATE ON [Restrictions] ([Limit]) TO [tm_admin] AS [dbo]
GO
GRANT REFERENCES ON [Restrictions] ([Limit]) TO [tm_admin] AS [dbo]
GO
GRANT SELECT ON [Restrictions] ([Limit]) TO [tm_user] AS [dbo]
GO
GRANT SELECT ON [Restrictions] ([SecGroupID]) TO [tm_admin] AS [dbo]
GO
GRANT UPDATE ON [Restrictions] ([SecGroupID]) TO [tm_admin] AS [dbo]
GO
GRANT REFERENCES ON [Restrictions] ([SecGroupID]) TO [tm_admin] AS [dbo]
GO
GRANT SELECT ON [Restrictions] ([SecGroupID]) TO [tm_user] AS [dbo]
GO
GRANT SELECT ON [Restrictions] ([CoSecGroupID]) TO [tm_admin] AS [dbo]
GO
GRANT UPDATE ON [Restrictions] ([CoSecGroupID]) TO [tm_admin] AS [dbo]
GO
GRANT REFERENCES ON [Restrictions] ([CoSecGroupID]) TO [tm_admin] AS [dbo]
GO
GRANT SELECT ON [Restrictions] ([CoSecGroupID]) TO [tm_user] AS [dbo]
GO
GRANT SELECT ON [Restrictions] ([disabled]) TO [tm_admin] AS [dbo]
GO
GRANT UPDATE ON [Restrictions] ([disabled]) TO [tm_admin] AS [dbo]
GO
GRANT REFERENCES ON [Restrictions] ([disabled]) TO [tm_admin] AS [dbo]
GO
GRANT SELECT ON [Restrictions] ([disabled]) TO [tm_user] AS [dbo]
GO
GRANT SELECT ON [Restrictions] ([Value]) TO [tm_admin] AS [dbo]
GO
GRANT UPDATE ON [Restrictions] ([Value]) TO [tm_admin] AS [dbo]
GO
GRANT REFERENCES ON [Restrictions] ([Value]) TO [tm_admin] AS [dbo]
GO
GRANT SELECT ON [Restrictions] ([Value]) TO [tm_user] AS [dbo]
GO
GRANT SELECT ON [Restrictions] ([NoCheck]) TO [tm_admin] AS [dbo]
GO
GRANT UPDATE ON [Restrictions] ([NoCheck]) TO [tm_admin] AS [dbo]
GO
GRANT REFERENCES ON [Restrictions] ([NoCheck]) TO [tm_admin] AS [dbo]
GO
GRANT SELECT ON [Restrictions] ([NoCheck]) TO [tm_user] AS [dbo]
GO
GRANT SELECT ON [Restrictions] ([TMUserID]) TO [tm_admin] AS [dbo]
GO
GRANT UPDATE ON [Restrictions] ([TMUserID]) TO [tm_admin] AS [dbo]
GO
GRANT REFERENCES ON [Restrictions] ([TMUserID]) TO [tm_admin] AS [dbo]
GO
GRANT SELECT ON [Restrictions] ([TMUserID]) TO [tm_user] AS [dbo]
GO
GRANT SELECT ON [Restrictions] ([TMSessionID]) TO [tm_admin] AS [dbo]
GO
GRANT UPDATE ON [Restrictions] ([TMSessionID]) TO [tm_admin] AS [dbo]
GO
GRANT REFERENCES ON [Restrictions] ([TMSessionID]) TO [tm_admin] AS [dbo]
GO
GRANT SELECT ON [Restrictions] ([TMSessionID]) TO [tm_user] AS [dbo]
GO
GRANT SELECT ON [Restrictions] ([TMCounter]) TO [tm_admin] AS [dbo]
GO
GRANT UPDATE ON [Restrictions] ([TMCounter]) TO [tm_admin] AS [dbo]
GO
GRANT REFERENCES ON [Restrictions] ([TMCounter]) TO [tm_admin] AS [dbo]
GO
GRANT SELECT ON [Restrictions] ([TMCounter]) TO [tm_user] AS [dbo]
GO
GRANT SELECT ON [SecGroups] TO [tm_admin] AS [dbo]
GO
GRANT INSERT ON [SecGroups] TO [tm_admin] AS [dbo]
GO
GRANT DELETE ON [SecGroups] TO [tm_admin] AS [dbo]
GO
GRANT UPDATE ON [SecGroups] TO [tm_admin] AS [dbo]
GO
GRANT REFERENCES ON [SecGroups] TO [tm_admin] AS [dbo]
GO
GRANT SELECT ON [SecGroups] TO [tm_user] AS [dbo]
GO
GRANT INSERT ON [SecGroups] TO [tm_user] AS [dbo]
GO
GRANT DELETE ON [SecGroups] TO [tm_user] AS [dbo]
GO
GRANT UPDATE ON [SecGroups] TO [tm_user] AS [dbo]
GO
GRANT SELECT ON [SecGroups] ([ID]) TO [tm_admin] AS [dbo]
GO
GRANT UPDATE ON [SecGroups] ([ID]) TO [tm_admin] AS [dbo]
GO
GRANT REFERENCES ON [SecGroups] ([ID]) TO [tm_admin] AS [dbo]
GO
GRANT SELECT ON [SecGroups] ([ID]) TO [tm_user] AS [dbo]
GO
GRANT UPDATE ON [SecGroups] ([ID]) TO [tm_user] AS [dbo]
GO
GRANT SELECT ON [SecGroups] ([SecGCode]) TO [tm_admin] AS [dbo]
GO
GRANT UPDATE ON [SecGroups] ([SecGCode]) TO [tm_admin] AS [dbo]
GO
GRANT REFERENCES ON [SecGroups] ([SecGCode]) TO [tm_admin] AS [dbo]
GO
GRANT SELECT ON [SecGroups] ([SecGCode]) TO [tm_user] AS [dbo]
GO
GRANT UPDATE ON [SecGroups] ([SecGCode]) TO [tm_user] AS [dbo]
GO
GRANT SELECT ON [SecGroups] ([SecGName]) TO [tm_admin] AS [dbo]
GO
GRANT UPDATE ON [SecGroups] ([SecGName]) TO [tm_admin] AS [dbo]
GO
GRANT REFERENCES ON [SecGroups] ([SecGName]) TO [tm_admin] AS [dbo]
GO
GRANT SELECT ON [SecGroups] ([SecGName]) TO [tm_user] AS [dbo]
GO
GRANT UPDATE ON [SecGroups] ([SecGName]) TO [tm_user] AS [dbo]
GO
GRANT SELECT ON [SecGroups] ([disabled]) TO [tm_admin] AS [dbo]
GO
GRANT UPDATE ON [SecGroups] ([disabled]) TO [tm_admin] AS [dbo]
GO
GRANT REFERENCES ON [SecGroups] ([disabled]) TO [tm_admin] AS [dbo]
GO
GRANT SELECT ON [SecGroups] ([disabled]) TO [tm_user] AS [dbo]
GO
GRANT UPDATE ON [SecGroups] ([disabled]) TO [tm_user] AS [dbo]
GO
GRANT SELECT ON [SecGroups] ([Filter]) TO [tm_admin] AS [dbo]
GO
GRANT UPDATE ON [SecGroups] ([Filter]) TO [tm_admin] AS [dbo]
GO
GRANT REFERENCES ON [SecGroups] ([Filter]) TO [tm_admin] AS [dbo]
GO
GRANT SELECT ON [SecGroups] ([Filter]) TO [tm_user] AS [dbo]
GO
GRANT UPDATE ON [SecGroups] ([Filter]) TO [tm_user] AS [dbo]
GO
GRANT SELECT ON [SecGroups] ([mode]) TO [tm_admin] AS [dbo]
GO
GRANT UPDATE ON [SecGroups] ([mode]) TO [tm_admin] AS [dbo]
GO
GRANT REFERENCES ON [SecGroups] ([mode]) TO [tm_admin] AS [dbo]
GO
GRANT SELECT ON [SecGroups] ([mode]) TO [tm_user] AS [dbo]
GO
GRANT UPDATE ON [SecGroups] ([mode]) TO [tm_user] AS [dbo]
GO
GRANT SELECT ON [SecGroups] ([RAgencies]) TO [tm_admin] AS [dbo]
GO
GRANT UPDATE ON [SecGroups] ([RAgencies]) TO [tm_admin] AS [dbo]
GO
GRANT REFERENCES ON [SecGroups] ([RAgencies]) TO [tm_admin] AS [dbo]
GO
GRANT SELECT ON [SecGroups] ([RAgencies]) TO [tm_user] AS [dbo]
GO
GRANT UPDATE ON [SecGroups] ([RAgencies]) TO [tm_user] AS [dbo]
GO
GRANT EXECUTE ON [TM_CreateRestriction] TO [tm_admin] AS [dbo]
GO
GRANT EXECUTE ON [TM_CreateRestriction] TO [tm_user] AS [dbo]
GO
GRANT EXECUTE ON [CreateNewRestriction] TO [tm_admin] AS [dbo]
GO
GRANT EXECUTE ON [CreateNewRestriction] TO [tm_user] AS [dbo]
GO
GRANT EXECUTE ON [TM_CreateSecGroup] TO [tm_admin] AS [dbo]
GO
GRANT EXECUTE ON [TM_CreateSecGroup] TO [tm_user] AS [dbo]
GO
GRANT EXECUTE ON [ModifySecGroup] TO [tm_admin] AS [dbo]
GO
GRANT EXECUTE ON [ModifySecGroup] TO [tm_user] AS [dbo]
GO
GRANT EXECUTE ON [DeleteSecGroup] TO [tm_admin] AS [dbo]
GO
GRANT EXECUTE ON [DeleteSecGroup] TO [tm_user] AS [dbo]
GO
GRANT EXECUTE ON [TM_CreateGroupOrder] TO [tm_admin] AS [dbo]
GO
GRANT EXECUTE ON [TM_CreateGroupOrder] TO [tm_user] AS [dbo]
GO
GRANT EXECUTE ON [TM_CreateOrder] TO [tm_admin] AS [dbo]
GO
GRANT EXECUTE ON [TM_CreateOrder] TO [tm_user] AS [dbo]
GO
GRANT EXECUTE ON [EditRestriction] TO [tm_admin] AS [dbo]
GO
GRANT EXECUTE ON [EditRestriction] TO [tm_user] AS [dbo]
GO
GRANT EXECUTE ON [TM_CreateClientGroup] TO [tm_admin] AS [dbo]
GO
GRANT EXECUTE ON [TM_CreateClientGroup] TO [tm_user] AS [dbo]
GO
GRANT EXECUTE ON [TM_CreateExportOrder] TO [tm_admin] AS [dbo]
GO
GRANT EXECUTE ON [TM_CreateExportOrder] TO [tm_user] AS [dbo]
GO
GRANT EXECUTE ON [TM_CreateGroupNegOrder] TO [tm_admin] AS [dbo]
GO
GRANT EXECUTE ON [TM_CreateGroupNegOrder] TO [tm_user] AS [dbo]
GO
GRANT EXECUTE ON [TM_CreateGroupStopOrder] TO [tm_admin] AS [dbo]
GO
GRANT EXECUTE ON [TM_CreateGroupStopOrder] TO [tm_user] AS [dbo]
GO
GRANT EXECUTE ON [TM_CreateNegOrder] TO [tm_admin] AS [dbo]
GO
GRANT EXECUTE ON [TM_CreateNegOrder] TO [tm_user] AS [dbo]
GO
GRANT EXECUTE ON [CreateNewSecGroup] TO [tm_admin] AS [dbo]
GO
GRANT EXECUTE ON [CreateNewSecGroup] TO [tm_user] AS [dbo]
GO
GRANT EXECUTE ON [TM_AddClientToGroup] TO [tm_admin] AS [dbo]
GO
GRANT EXECUTE ON [TM_AddClientToGroup] TO [tm_user] AS [dbo]
GO
GRANT EXECUTE ON [TM_DeleteClientFromGroup] TO [tm_admin] AS [dbo]
GO
GRANT EXECUTE ON [TM_DeleteClientFromGroup] TO [tm_user] AS [dbo]
GO
GRANT EXECUTE ON [TM_DeleteClientGroup] TO [tm_admin] AS [dbo]
GO
GRANT EXECUTE ON [TM_DeleteClientGroup] TO [tm_user] AS [dbo]
GO

/* Запишем версию созданной базы данных */

SET ANSI_PADDING OFF
GO
INSERT INTO SystemData (KeyName, KeyValue)
VALUES ('dbver', '29');
INSERT INTO SystemData (KeyName, KeyValue)
VALUES ('UseStoredProc', 'y');
INSERT INTO SystemData (KeyName, KeyValue)
VALUES ('dbgen_029', getdate());
GO

PRINT 'DB has been created as version 29'
GO
