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.AccDocumentHeader
	DROP CONSTRAINT FK_AccTmpDocHeader_UsersEditor
GO
ALTER TABLE dbo.AccDocumentHeader
	DROP CONSTRAINT FK_AccTmpDocHeader_UsersRecorder
GO
ALTER TABLE dbo.AccDocumentHeader
	DROP CONSTRAINT FK_AccTmpDocHeader_UsersVerifier
GO
ALTER TABLE dbo.Users SET (LOCK_ESCALATION = TABLE)
GO
COMMIT
BEGIN TRANSACTION
GO
CREATE TABLE dbo.Tmp_AccDocumentHeader
	(
	Serial bigint NOT NULL,
	TempCode bigint NULL,
	FinalCode bigint NULL,
	Detail varchar(200) NULL,
	ENDes varchar(200) NULL,
	Mechanize bit NULL,
	SubSystemRef varchar(16) NULL,
	EffectiveDate char(10) NULL,
	Effective_ENDate char(10) NULL,
	TotalSum bigint NULL,
	Balance bigint NULL,
	RecorderRef int NULL,
	RecordDate char(10) NULL,
	EditorRef int NULL,
	EditDate char(10) NULL,
	VerifierRef int NULL,
	VerificationDate char(10) NULL,
	Appendix int NULL,
	Description varchar(300) NULL,
	OfficeDetailRef int NULL,
	OfficePeriodRef int NULL
	)  ON [PRIMARY]
GO
ALTER TABLE dbo.Tmp_AccDocumentHeader SET (LOCK_ESCALATION = TABLE)
GO
DECLARE @v sql_variant 
SET @v = N'سریال'
EXECUTE sp_addextendedproperty N'MS_Description', @v, N'SCHEMA', N'dbo', N'TABLE', N'Tmp_AccDocumentHeader', N'COLUMN', N'Serial'
GO
DECLARE @v sql_variant 
SET @v = N'کد سند موقت'
EXECUTE sp_addextendedproperty N'MS_Description', @v, N'SCHEMA', N'dbo', N'TABLE', N'Tmp_AccDocumentHeader', N'COLUMN', N'TempCode'
GO
DECLARE @v sql_variant 
SET @v = N'کد سند قطعی'
EXECUTE sp_addextendedproperty N'MS_Description', @v, N'SCHEMA', N'dbo', N'TABLE', N'Tmp_AccDocumentHeader', N'COLUMN', N'FinalCode'
GO
DECLARE @v sql_variant 
SET @v = N'شرح سند'
EXECUTE sp_addextendedproperty N'MS_Description', @v, N'SCHEMA', N'dbo', N'TABLE', N'Tmp_AccDocumentHeader', N'COLUMN', N'Detail'
GO
DECLARE @v sql_variant 
SET @v = N'اگر سند مکانیزه باشد 1 است'
EXECUTE sp_addextendedproperty N'MS_Description', @v, N'SCHEMA', N'dbo', N'TABLE', N'Tmp_AccDocumentHeader', N'COLUMN', N'Mechanize'
GO
DECLARE @v sql_variant 
SET @v = N'در اسناد مکانیزه سریال زیر سیستم تولید کننده سند میباشد'
EXECUTE sp_addextendedproperty N'MS_Description', @v, N'SCHEMA', N'dbo', N'TABLE', N'Tmp_AccDocumentHeader', N'COLUMN', N'SubSystemRef'
GO
DECLARE @v sql_variant 
SET @v = N'ثبت کننده'
EXECUTE sp_addextendedproperty N'MS_Description', @v, N'SCHEMA', N'dbo', N'TABLE', N'Tmp_AccDocumentHeader', N'COLUMN', N'RecorderRef'
GO
DECLARE @v sql_variant 
SET @v = N'تاریخ ثبت'
EXECUTE sp_addextendedproperty N'MS_Description', @v, N'SCHEMA', N'dbo', N'TABLE', N'Tmp_AccDocumentHeader', N'COLUMN', N'RecordDate'
GO
DECLARE @v sql_variant 
SET @v = N'آخرین ویرایش کننده'
EXECUTE sp_addextendedproperty N'MS_Description', @v, N'SCHEMA', N'dbo', N'TABLE', N'Tmp_AccDocumentHeader', N'COLUMN', N'EditorRef'
GO
DECLARE @v sql_variant 
SET @v = N'تاریخ آخرین ویرایش'
EXECUTE sp_addextendedproperty N'MS_Description', @v, N'SCHEMA', N'dbo', N'TABLE', N'Tmp_AccDocumentHeader', N'COLUMN', N'EditDate'
GO
DECLARE @v sql_variant 
SET @v = N'قطعی کننده'
EXECUTE sp_addextendedproperty N'MS_Description', @v, N'SCHEMA', N'dbo', N'TABLE', N'Tmp_AccDocumentHeader', N'COLUMN', N'VerifierRef'
GO
DECLARE @v sql_variant 
SET @v = N'تاریخ قطعی'
EXECUTE sp_addextendedproperty N'MS_Description', @v, N'SCHEMA', N'dbo', N'TABLE', N'Tmp_AccDocumentHeader', N'COLUMN', N'VerificationDate'
GO
DECLARE @v sql_variant 
SET @v = N'تعداد پیوست سند'
EXECUTE sp_addextendedproperty N'MS_Description', @v, N'SCHEMA', N'dbo', N'TABLE', N'Tmp_AccDocumentHeader', N'COLUMN', N'Appendix'
GO
DECLARE @v sql_variant 
SET @v = N'توضیحات'
EXECUTE sp_addextendedproperty N'MS_Description', @v, N'SCHEMA', N'dbo', N'TABLE', N'Tmp_AccDocumentHeader', N'COLUMN', N'Description'
GO
IF EXISTS(SELECT * FROM dbo.AccDocumentHeader)
	 EXEC('INSERT INTO dbo.Tmp_AccDocumentHeader (Serial, TempCode, FinalCode, Detail, Mechanize, SubSystemRef, EffectiveDate, TotalSum, Balance, RecorderRef, RecordDate, EditorRef, EditDate, VerifierRef, VerificationDate, Appendix, Description, OfficeDetailRef, OfficePeriodRef)
		SELECT Serial, TempCode, FinalCode, Detail, Mechanize, SubSystemRef, EffectiveDate, TotalSum, Balance, RecorderRef, RecordDate, EditorRef, EditDate, VerifierRef, VerificationDate, Appendix, Description, OfficeDetailRef, OfficePeriodRef FROM dbo.AccDocumentHeader WITH (HOLDLOCK TABLOCKX)')
GO
ALTER TABLE dbo.CashGetPay
	DROP CONSTRAINT FK_CashGetPay_AccDocumentHeader
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.AccDocumentDetail
	DROP CONSTRAINT FK_AccDocumentDetail_AccDocumentHeader
GO
ALTER TABLE dbo.CheckGetPayHeader
	DROP CONSTRAINT FK_CheckGetPayHeader_AccDocumentHeader
GO
DROP TABLE dbo.AccDocumentHeader
GO
EXECUTE sp_rename N'dbo.Tmp_AccDocumentHeader', N'AccDocumentHeader', 'OBJECT' 
GO
ALTER TABLE dbo.AccDocumentHeader ADD CONSTRAINT
	PK_AccDocumentHeader PRIMARY KEY CLUSTERED 
	(
	Serial
	) WITH( STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]

GO
ALTER TABLE dbo.AccDocumentHeader ADD CONSTRAINT
	FK_AccTmpDocHeader_UsersEditor FOREIGN KEY
	(
	EditorRef
	) REFERENCES dbo.Users
	(
	Serial
	) ON UPDATE  NO ACTION 
	 ON DELETE  NO ACTION 
	
GO
ALTER TABLE dbo.AccDocumentHeader ADD CONSTRAINT
	FK_AccTmpDocHeader_UsersRecorder FOREIGN KEY
	(
	RecorderRef
	) REFERENCES dbo.Users
	(
	Serial
	) ON UPDATE  NO ACTION 
	 ON DELETE  NO ACTION 
	
GO
ALTER TABLE dbo.AccDocumentHeader ADD CONSTRAINT
	FK_AccTmpDocHeader_UsersVerifier FOREIGN KEY
	(
	VerifierRef
	) REFERENCES dbo.Users
	(
	Serial
	) ON UPDATE  NO ACTION 
	 ON DELETE  NO ACTION 
	
GO
COMMIT
BEGIN TRANSACTION
GO
ALTER TABLE dbo.CheckGetPayHeader ADD CONSTRAINT
	FK_CheckGetPayHeader_AccDocumentHeader FOREIGN KEY
	(
	AccDocumentHeaderRef
	) REFERENCES dbo.AccDocumentHeader
	(
	Serial
	) ON UPDATE  NO ACTION 
	 ON DELETE  NO ACTION 
	
GO
ALTER TABLE dbo.CheckGetPayHeader SET (LOCK_ESCALATION = TABLE)
GO
COMMIT
BEGIN TRANSACTION
GO
ALTER TABLE dbo.AccDocumentDetail ADD CONSTRAINT
	FK_AccDocumentDetail_AccDocumentHeader FOREIGN KEY
	(
	AccDocumentHeaderRef
	) REFERENCES dbo.AccDocumentHeader
	(
	Serial
	) ON UPDATE  NO ACTION 
	 ON DELETE  NO ACTION 
	
GO
ALTER TABLE dbo.AccDocumentDetail SET (LOCK_ESCALATION = TABLE)
GO
COMMIT
BEGIN TRANSACTION
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 SET (LOCK_ESCALATION = TABLE)
GO
COMMIT
BEGIN TRANSACTION
GO
ALTER TABLE dbo.CashGetPay ADD CONSTRAINT
	FK_CashGetPay_AccDocumentHeader FOREIGN KEY
	(
	AccDocumentHeaderRef
	) REFERENCES dbo.AccDocumentHeader
	(
	Serial
	) ON UPDATE  NO ACTION 
	 ON DELETE  NO ACTION 
	
GO
ALTER TABLE dbo.CashGetPay SET (LOCK_ESCALATION = TABLE)
GO
COMMIT
