Use ATNDBTest
Go



BEGIN TRANSACTION
SET QUOTED_IDENTIFIER ON
SET ARITHABORT ON
SET NUMERIC_ROUNDABORT OFF
SET CONCAT_NULL_YIELDS_NULL ON
SET ANSI_NULLS ON
SET ANSI_PADDING ON
SET ANSI_WARNINGS ON
COMMIT
BEGIN TRANSACTION
GO
ALTER TABLE dbo.FactorHeader
	DROP CONSTRAINT FK_FactorHeader_Warehouse
GO
ALTER TABLE dbo.Warehouse SET (LOCK_ESCALATION = TABLE)
GO
COMMIT
BEGIN TRANSACTION
GO
ALTER TABLE dbo.FactorHeader
	DROP CONSTRAINT FK_FactorHeader_GetterOrPayerFactor
GO
ALTER TABLE dbo.GetterOrPayerFactor SET (LOCK_ESCALATION = TABLE)
GO
COMMIT
BEGIN TRANSACTION
GO
ALTER TABLE dbo.FactorHeader
	DROP CONSTRAINT FK_FactorHeader_FactorKind
GO
ALTER TABLE dbo.FactorKind SET (LOCK_ESCALATION = TABLE)
GO
COMMIT
BEGIN TRANSACTION
GO
ALTER TABLE dbo.FactorHeader
	DROP CONSTRAINT FK_FactorHeader_AccDocumentHeader_OnVerification
GO
ALTER TABLE dbo.FactorHeader
	DROP CONSTRAINT FK_FactorHeader_AccDocumentHeader_OnUpdating
GO
ALTER TABLE dbo.AccDocumentHeader SET (LOCK_ESCALATION = TABLE)
GO
COMMIT
BEGIN TRANSACTION
GO
ALTER TABLE dbo.FactorHeader
	DROP CONSTRAINT FK_FactorHeader_Broker
GO
ALTER TABLE dbo.Broker SET (LOCK_ESCALATION = TABLE)
GO
COMMIT
BEGIN TRANSACTION
GO
CREATE TABLE dbo.Tmp_FactorHeader
	(
	Serial bigint NOT NULL,
	Code bigint NULL,
	FactorKindRef int NOT NULL,
	AccDocumentHeaderRefOnVerification bigint NULL,
	AccDocumentHeaderRefOnUpdating bigint NULL,
	GetterOrPayerFactorRef bigint NULL,
	ControlNo varchar(20) NULL,
	WarehouseRef bigint NULL,
	EffectiveDate char(10) NULL,
	RecorderRef int NULL,
	RecordDate char(10) NULL,
	EditorRef int NULL,
	EditDate char(10) NULL,
	VerifierRef int NULL,
	VerificationDate char(10) NULL,
	UpdatingUserRef int NULL,
	UpdatingDate char(10) NULL,
	Cost1th bigint NULL,
	Cost2th bigint NULL,
	Rebate bigint NULL,
	RebateRound bigint NULL,
	BrokerRef bigint NULL,
	SaleBrokerPercent decimal(6, 3) NULL,
	SaleBrokerPrice bigint NULL,
	BrokerPercentTypeRef smallint NULL,
	TotalPaid bigint NULL,
	TotalPaidInForeignCurrency money NULL,
	ForeignCurrencyFactor float(53) NULL,
	ForeignCurrencySymbolRef smallint NULL,
	PayDate char(10) NULL,
	WarehouseVerificationCode bigint NULL,
	WarehouseVerificationDate char(10) NULL,
	WarehouseVerificationUserRef int NULL,
	Mechanize bit NULL,
	Description varchar(300) NULL,
	OfficeDetailRef int NULL,
	OfficePeriodRef int NULL,
	RowVersion datetime NULL
	)  ON [PRIMARY]
GO
ALTER TABLE dbo.Tmp_FactorHeader SET (LOCK_ESCALATION = TABLE)
GO
IF EXISTS(SELECT * FROM dbo.FactorHeader)
	 EXEC('INSERT INTO dbo.Tmp_FactorHeader (Serial, Code, FactorKindRef, AccDocumentHeaderRefOnVerification, AccDocumentHeaderRefOnUpdating, GetterOrPayerFactorRef, ControlNo, WarehouseRef, EffectiveDate, RecorderRef, RecordDate, EditorRef, EditDate, VerifierRef, VerificationDate, UpdatingUserRef, UpdatingDate, Cost1th, Cost2th, Rebate, RebateRound, BrokerRef, SaleBrokerPercent, TotalPaid, TotalPaidInForeignCurrency, ForeignCurrencyFactor, ForeignCurrencySymbolRef, PayDate, WarehouseVerificationCode, WarehouseVerificationDate, WarehouseVerificationUserRef, Mechanize, Description, OfficeDetailRef, OfficePeriodRef, RowVersion)
		SELECT Serial, Code, FactorKindRef, AccDocumentHeaderRefOnVerification, AccDocumentHeaderRefOnUpdating, GetterOrPayerFactorRef, ControlNo, WarehouseRef, EffectiveDate, RecorderRef, RecordDate, EditorRef, EditDate, VerifierRef, VerificationDate, UpdatingUserRef, UpdatingDate, Cost1th, Cost2th, Rebate, RebateRound, BrokerRef, SaleBrokerPercent, TotalPaid, TotalPaidInForeignCurrency, ForeignCurrencyFactor, ForeignCurrencySymbolRef, PayDate, WarehouseVerificationCode, WarehouseVerificationDate, WarehouseVerificationUserRef, Mechanize, Description, OfficeDetailRef, OfficePeriodRef, RowVersion FROM dbo.FactorHeader WITH (HOLDLOCK TABLOCKX)')
GO
ALTER TABLE dbo.FactorExtendedOption
	DROP CONSTRAINT FK_FactorExtendedOption_FactorHeader
GO
ALTER TABLE dbo.FactorDetail
	DROP CONSTRAINT FK_FactorDetail_FactorHeader
GO
ALTER TABLE dbo.FactorCashSettlementCheckBridge
	DROP CONSTRAINT FK_FactorCashSettlementCheckBridge_FactorHeader
GO
ALTER TABLE dbo.FactorAccCode
	DROP CONSTRAINT FK_FactorAccCode_FactorHeader
GO
DROP TABLE dbo.FactorHeader
GO
EXECUTE sp_rename N'dbo.Tmp_FactorHeader', N'FactorHeader', 'OBJECT' 
GO
ALTER TABLE dbo.FactorHeader ADD CONSTRAINT
	PK_FactorHeader PRIMARY KEY CLUSTERED 
	(
	Serial
	) WITH( STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]

GO
CREATE NONCLUSTERED INDEX IDX_FactorHeader_GetterOrPayerFactorRef ON dbo.FactorHeader
	(
	GetterOrPayerFactorRef
	) WITH( STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
GO
CREATE NONCLUSTERED INDEX IDX_FactorHeader_EffectiveDate ON dbo.FactorHeader
	(
	EffectiveDate
	) WITH( STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
GO
CREATE NONCLUSTERED INDEX IDX_FactorHeader_RecorderRef ON dbo.FactorHeader
	(
	RecorderRef
	) WITH( STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
GO
CREATE NONCLUSTERED INDEX IDX_FactorHeader_EditorRef ON dbo.FactorHeader
	(
	EditorRef
	) WITH( STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
GO
CREATE NONCLUSTERED INDEX IDX_FactorHeader_VerifierRef ON dbo.FactorHeader
	(
	VerifierRef
	) WITH( STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
GO
CREATE NONCLUSTERED INDEX IDX_FactorHeader_UpdatingUserRef ON dbo.FactorHeader
	(
	UpdatingUserRef
	) WITH( STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
GO
CREATE NONCLUSTERED INDEX IDX_FactorHeader_WarehouseRef ON dbo.FactorHeader
	(
	WarehouseRef
	) WITH( STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
GO
CREATE NONCLUSTERED INDEX IDX_FactorHeader_FactorKindRef ON dbo.FactorHeader
	(
	FactorKindRef
	) WITH( STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
GO
CREATE NONCLUSTERED INDEX IDX_FactorHeader_BrokerRef ON dbo.FactorHeader
	(
	BrokerRef
	) WITH( STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
GO
CREATE NONCLUSTERED INDEX IDX_FactorHeader_AccDocumentHeaderRefOnVerification ON dbo.FactorHeader
	(
	AccDocumentHeaderRefOnVerification
	) WITH( STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
GO
CREATE NONCLUSTERED INDEX IDX_FactorHeader_AccDocumentHeaderRefOnUpdating ON dbo.FactorHeader
	(
	AccDocumentHeaderRefOnUpdating
	) WITH( STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
GO
CREATE NONCLUSTERED INDEX IDX_FactorHeader_ForeignCurrencySymbolRef ON dbo.FactorHeader
	(
	ForeignCurrencySymbolRef
	) WITH( STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
GO
CREATE NONCLUSTERED INDEX IDX_FactorHeader_OfficeDetailRef ON dbo.FactorHeader
	(
	OfficeDetailRef
	) WITH( STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
GO
CREATE NONCLUSTERED INDEX IDX_FactorHeader_OfficePeriodRef ON dbo.FactorHeader
	(
	OfficePeriodRef
	) WITH( STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
GO
ALTER TABLE dbo.FactorHeader ADD CONSTRAINT
	FK_FactorHeader_Broker FOREIGN KEY
	(
	BrokerRef
	) REFERENCES dbo.Broker
	(
	Serial
	) ON UPDATE  NO ACTION 
	 ON DELETE  NO ACTION 
	
GO
ALTER TABLE dbo.FactorHeader ADD CONSTRAINT
	FK_FactorHeader_AccDocumentHeader_OnVerification FOREIGN KEY
	(
	AccDocumentHeaderRefOnVerification
	) REFERENCES dbo.AccDocumentHeader
	(
	Serial
	) ON UPDATE  NO ACTION 
	 ON DELETE  NO ACTION 
	
GO
ALTER TABLE dbo.FactorHeader ADD CONSTRAINT
	FK_FactorHeader_AccDocumentHeader_OnUpdating FOREIGN KEY
	(
	AccDocumentHeaderRefOnUpdating
	) REFERENCES dbo.AccDocumentHeader
	(
	Serial
	) ON UPDATE  NO ACTION 
	 ON DELETE  NO ACTION 
	
GO
ALTER TABLE dbo.FactorHeader ADD CONSTRAINT
	FK_FactorHeader_FactorKind FOREIGN KEY
	(
	FactorKindRef
	) REFERENCES dbo.FactorKind
	(
	Serial
	) ON UPDATE  NO ACTION 
	 ON DELETE  NO ACTION 
	
GO
ALTER TABLE dbo.FactorHeader ADD CONSTRAINT
	FK_FactorHeader_GetterOrPayerFactor FOREIGN KEY
	(
	GetterOrPayerFactorRef
	) REFERENCES dbo.GetterOrPayerFactor
	(
	Serial
	) ON UPDATE  NO ACTION 
	 ON DELETE  NO ACTION 
	
GO
ALTER TABLE dbo.FactorHeader ADD CONSTRAINT
	FK_FactorHeader_Warehouse FOREIGN KEY
	(
	WarehouseRef
	) REFERENCES dbo.Warehouse
	(
	Serial
	) ON UPDATE  NO ACTION 
	 ON DELETE  NO ACTION 
	
GO
COMMIT
BEGIN TRANSACTION
GO
ALTER TABLE dbo.FactorAccCode ADD CONSTRAINT
	FK_FactorAccCode_FactorHeader FOREIGN KEY
	(
	FactorHeaderRef
	) REFERENCES dbo.FactorHeader
	(
	Serial
	) ON UPDATE  NO ACTION 
	 ON DELETE  NO ACTION 
	
GO
ALTER TABLE dbo.FactorAccCode SET (LOCK_ESCALATION = TABLE)
GO
COMMIT
BEGIN TRANSACTION
GO
ALTER TABLE dbo.FactorCashSettlementCheckBridge ADD CONSTRAINT
	FK_FactorCashSettlementCheckBridge_FactorHeader FOREIGN KEY
	(
	FactorHeaderRef
	) REFERENCES dbo.FactorHeader
	(
	Serial
	) ON UPDATE  NO ACTION 
	 ON DELETE  NO ACTION 
	
GO
ALTER TABLE dbo.FactorCashSettlementCheckBridge SET (LOCK_ESCALATION = TABLE)
GO
COMMIT
BEGIN TRANSACTION
GO
ALTER TABLE dbo.FactorDetail ADD CONSTRAINT
	FK_FactorDetail_FactorHeader FOREIGN KEY
	(
	FactorHeaderRef
	) REFERENCES dbo.FactorHeader
	(
	Serial
	) ON UPDATE  NO ACTION 
	 ON DELETE  NO ACTION 
	
GO
ALTER TABLE dbo.FactorDetail SET (LOCK_ESCALATION = TABLE)
GO
COMMIT
BEGIN TRANSACTION
GO
ALTER TABLE dbo.FactorExtendedOption ADD CONSTRAINT
	FK_FactorExtendedOption_FactorHeader FOREIGN KEY
	(
	FactorHeaderRef
	) REFERENCES dbo.FactorHeader
	(
	Serial
	) ON UPDATE  NO ACTION 
	 ON DELETE  NO ACTION 
	
GO
ALTER TABLE dbo.FactorExtendedOption SET (LOCK_ESCALATION = TABLE)
GO
COMMIT
