Use ATNDBTest
Go


/* 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
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.GetterOrPayerFactor
	DROP CONSTRAINT FK_GetterOrPayerFactor_Users
GO
ALTER TABLE dbo.Users SET (LOCK_ESCALATION = TABLE)
GO
COMMIT
BEGIN TRANSACTION
GO
ALTER TABLE dbo.GetterOrPayerFactor
	DROP CONSTRAINT FK_GetterOrPayerFactor_GetterOrPayerFactorKind
GO
ALTER TABLE dbo.GetterOrPayerFactorKind SET (LOCK_ESCALATION = TABLE)
GO
COMMIT
BEGIN TRANSACTION
GO
ALTER TABLE dbo.GetterOrPayerFactor
	DROP CONSTRAINT FK_GetterOrPayerFactor_Degree
GO
ALTER TABLE dbo.Degree SET (LOCK_ESCALATION = TABLE)
GO
COMMIT
BEGIN TRANSACTION
GO
ALTER TABLE dbo.GetterOrPayerFactor
	DROP CONSTRAINT DF_GetterOrPayerFactor_Active
GO
CREATE TABLE dbo.Tmp_GetterOrPayerFactor
	(
	Serial bigint NOT NULL,
	Code bigint NOT NULL,
	FAName varchar(50) NULL,
	ENName varchar(50) NULL,
	KindRef smallint NOT NULL,
	Active bit NULL,
	Manager varchar(50) NULL,
	DegreeRef smallint NULL,
	Address varchar(150) NULL,
	PostCode varchar(20) NULL,
	Email varchar(50) NULL,
	Website varchar(50) NULL,
	RegNo varchar(50) NULL,
	SSNOrRegNo varchar(50) NULL,
	EconomicCode varchar(50) NULL,
	Tel1 varchar(20) NULL,
	Tel2 varchar(20) NULL,
	Fax varchar(20) NULL,
	Mobile varchar(20) NULL,
	BankName varchar(50) NULL,
	OffshootCode varchar(15) NULL,
	OffshootName varchar(50) NULL,
	BankAccountNo varchar(20) NULL,
	IBAN varchar(30) NULL,
	BankAddress varchar(300) NULL,
	AccEntityL1CodeBookRef bigint NULL,
	AccEntityL2CodeBookRef bigint NULL,
	AccountMaximum bigint NULL,
	SaleProfitPercent decimal(6, 3) NULL,
	SaleRebatePercent decimal(6, 3) NULL,
	RecorderRef int NULL,
	RecordDate char(10) NULL,
	EditorRef int NULL,
	EditDate char(10) NULL,
	Description varchar(300) NULL,
	OfficeDetailRef int NULL
	)  ON [PRIMARY]
GO
ALTER TABLE dbo.Tmp_GetterOrPayerFactor 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_GetterOrPayerFactor', N'COLUMN', N'Manager'
GO
ALTER TABLE dbo.Tmp_GetterOrPayerFactor ADD CONSTRAINT
	DF_GetterOrPayerFactor_Active DEFAULT ((0)) FOR Active
GO
IF EXISTS(SELECT * FROM dbo.GetterOrPayerFactor)
	 EXEC('INSERT INTO dbo.Tmp_GetterOrPayerFactor (Serial, Code, FAName, KindRef, Active, Manager, DegreeRef, Address, PostCode, SSNOrRegNo, EconomicCode, Tel1, Tel2, Fax, Mobile, AccEntityL1CodeBookRef, AccEntityL2CodeBookRef, AccountMaximum, SaleProfitPercent, SaleRebatePercent, RecorderRef, RecordDate, Description, OfficeDetailRef)
		SELECT Serial, Code, Name, KindRef, Active, Manager, DegreeRef, Address, PostCode, SSNOrRegNo, EconomicCode, Tel1, Tel2, Fax, Mobile, AccEntityL1CodeBookRef, AccEntityL2CodeBookRef, AccountMaximum, SaleProfitPercent, SaleRebatePercent, RecorderRef, RecordDate, Description, OfficeDetailRef FROM dbo.GetterOrPayerFactor WITH (HOLDLOCK TABLOCKX)')
GO
ALTER TABLE dbo.FactorHeader
	DROP CONSTRAINT FK_FactorHeader_GetterOrPayerFactor
GO
ALTER TABLE dbo.CashGetPay
	DROP CONSTRAINT FK_CashGetPay_GetterOrPayerFactor
GO
DROP TABLE dbo.GetterOrPayerFactor
GO
EXECUTE sp_rename N'dbo.Tmp_GetterOrPayerFactor', N'GetterOrPayerFactor', 'OBJECT' 
GO
ALTER TABLE dbo.GetterOrPayerFactor ADD CONSTRAINT
	PK_GetterOrPayerFactor 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.GetterOrPayerFactor ADD CONSTRAINT
	FK_GetterOrPayerFactor_Degree FOREIGN KEY
	(
	DegreeRef
	) REFERENCES dbo.Degree
	(
	Serial
	) ON UPDATE  NO ACTION 
	 ON DELETE  NO ACTION 
	
GO
ALTER TABLE dbo.GetterOrPayerFactor ADD CONSTRAINT
	FK_GetterOrPayerFactor_GetterOrPayerFactorKind FOREIGN KEY
	(
	KindRef
	) REFERENCES dbo.GetterOrPayerFactorKind
	(
	Serial
	) ON UPDATE  NO ACTION 
	 ON DELETE  NO ACTION 
	
GO
ALTER TABLE dbo.GetterOrPayerFactor ADD CONSTRAINT
	FK_GetterOrPayerFactor_Users FOREIGN KEY
	(
	RecorderRef
	) REFERENCES dbo.Users
	(
	Serial
	) ON UPDATE  NO ACTION 
	 ON DELETE  NO ACTION 
	
GO
COMMIT
BEGIN TRANSACTION
GO
ALTER TABLE dbo.CashGetPay ADD CONSTRAINT
	FK_CashGetPay_GetterOrPayerFactor FOREIGN KEY
	(
	GetterOrPayerRef
	) REFERENCES dbo.GetterOrPayerFactor
	(
	Serial
	) ON UPDATE  NO ACTION 
	 ON DELETE  NO ACTION 
	
GO
ALTER TABLE dbo.CashGetPay SET (LOCK_ESCALATION = TABLE)
GO
COMMIT
BEGIN TRANSACTION
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 SET (LOCK_ESCALATION = TABLE)
GO
COMMIT
