Use ATNDBTest
Go

/*=============================================================================================================*/
-- اضافه کردن سه ستون به جدول ارتباط معین با انواع تفصیلی
BEGIN TRANSACTION
GO
ALTER TABLE dbo.AccAdjutantL1Bridge ADD
	EntityL1 bit NULL,
	SecondEntity bit NULL,
	ThirdEntity bit NULL
GO
ALTER TABLE dbo.AccAdjutantL1Bridge SET (LOCK_ESCALATION = TABLE)
GO
COMMIT
/*=============================================================================================================*/
-- به روز رسانی جدول ارتباط معین با انواع تفصیلی
Update 
	dbo.AccAdjutantL1Bridge
Set
	EntityL1 = 1
/*=============================================================================================================*/
-- ایجاد جدول تفصیلی 2
Create Table dbo.AccSecondEntityCodeBook(
	Serial Bigint Not Null,
	Code Bigint Null,
	FADetail Varchar(100) Null,
	ENDetail Varchar(100) Null,
	AccEntityKindRef smallint Null,
	Active bit Null,
	RecorderRef Int Null,
	RecordDate char(10) Null,
	EditorRef Int Null,
	EditDate char(10) Null,
	OfficeDetailRef Int Null)
GO
Alter Table dbo.AccSecondEntityCodeBook Add Constraint PK_AccSecondEntityCodeBook Primary Key Clustered (Serial)
GO
/*=============================================================================================================*/
-- ایجاد جدول تفصیلی 3
Create Table dbo.AccThirdEntityCodeBook(
	Serial Bigint Not Null,
	Code Bigint Null,
	FADetail Varchar(100) Null,
	ENDetail Varchar(100) Null,
	AccEntityKindRef smallint Null,
	Active bit Null,
	RecorderRef Int Null,
	RecordDate char(10) Null,
	EditorRef Int Null,
	EditDate char(10) Null,
	OfficeDetailRef Int Null)
GO
Alter Table dbo.AccThirdEntityCodeBook Add Constraint PK_AccThirdEntityCodeBook Primary Key Clustered (Serial)
GO
/*=============================================================================================================*/
-- حذف دو ستون گروه و کل از جدول جزئیات اسناد حسابداری
BEGIN TRANSACTION
GO
ALTER TABLE dbo.AccDocumentDetail DROP CONSTRAINT FK_AccDocumentDetail_AccGroupCodeBook
GO
ALTER TABLE dbo.AccGroupCodeBook SET (LOCK_ESCALATION = TABLE)
GO
COMMIT
BEGIN TRANSACTION
GO
ALTER TABLE dbo.AccDocumentDetail DROP CONSTRAINT FK_AccDocumentDetail_AccGeneralCodeBook
GO
ALTER TABLE dbo.AccGeneralCodeBook SET (LOCK_ESCALATION = TABLE)
GO
COMMIT
BEGIN TRANSACTION
GO
DROP INDEX IDX_AccDocumentDetail_AccGeneralCodeBookRef ON dbo.AccDocumentDetail
GO
DROP INDEX IDX_AccDocumentDetail_AccGroupCodeBookRef ON dbo.AccDocumentDetail
GO
ALTER TABLE dbo.AccDocumentDetail DROP COLUMN AccGroupCodeBookRef, AccGeneralCodeBookRef
GO
ALTER TABLE dbo.AccDocumentDetail SET (LOCK_ESCALATION = TABLE)
GO
COMMIT
/*=============================================================================================================*/
-- اضافه کردن دو ستون تفصیلی2 و تفصیلی3 به جدول جزئیات اسناد حسابداری
/* To prevent any potential data loss issues, you should review this script in detail before running it outside the context of the database designer.*/
BEGIN TRANSACTION
GO
ALTER TABLE dbo.AccDocumentDetail ADD
	AccSecondEntityCodeBookRef bigint NULL,
	AccThirdEntityCodeBookRef bigint NULL
GO
ALTER TABLE dbo.AccDocumentDetail SET (LOCK_ESCALATION = TABLE)
GO
COMMIT
/*=============================================================================================================*/
