Use ATNDBTest
Go



/*
   الجمعة, جوان 12, 201501:16:05 ب.ظ
   User: 
   Server: TAHERIAN-PC
   Database: ATNDBTest
   Application: 
*/

/* 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
CREATE TABLE dbo.Tmp_Warehouse
	(
	Serial bigint NOT NULL,
	Code bigint NULL,
	Detail varchar(100) NULL,
	RecorderRef int NULL,
	RecordDate char(10) NULL,
	EditorRef int NULL,
	EditDate char(10) NULL,
	OfficeDetailRef int NULL
	)  ON [PRIMARY]
GO
ALTER TABLE dbo.Tmp_Warehouse SET (LOCK_ESCALATION = TABLE)
GO
IF EXISTS(SELECT * FROM dbo.Warehouse)
	 EXEC('INSERT INTO dbo.Tmp_Warehouse (Serial, Code, Detail, RecorderRef, RecordDate, OfficeDetailRef)
		SELECT Serial, Code, Detail, RecorderRef, RecordDate, OfficeDetailRef FROM dbo.Warehouse WITH (HOLDLOCK TABLOCKX)')
GO
ALTER TABLE dbo.FactorHeader
	DROP CONSTRAINT FK_FactorHeader_Warehouse
GO
ALTER TABLE dbo.StorageCountHeader
	DROP CONSTRAINT FK_StorageCountHeader_Warehouse
GO
ALTER TABLE dbo.PartWarehouseBridge
	DROP CONSTRAINT FK_PartWarehouseBridge_Warehouse
GO
DROP TABLE dbo.Warehouse
GO
EXECUTE sp_rename N'dbo.Tmp_Warehouse', N'Warehouse', 'OBJECT' 
GO
ALTER TABLE dbo.Warehouse ADD CONSTRAINT
	PK_Warehouse PRIMARY KEY CLUSTERED 
	(
	Serial
	) WITH( STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]

GO
COMMIT
BEGIN TRANSACTION
GO
ALTER TABLE dbo.PartWarehouseBridge ADD CONSTRAINT
	FK_PartWarehouseBridge_Warehouse FOREIGN KEY
	(
	WarehouseRef
	) REFERENCES dbo.Warehouse
	(
	Serial
	) ON UPDATE  NO ACTION 
	 ON DELETE  NO ACTION 
	
GO
ALTER TABLE dbo.PartWarehouseBridge SET (LOCK_ESCALATION = TABLE)
GO
COMMIT
BEGIN TRANSACTION
GO
ALTER TABLE dbo.StorageCountHeader ADD CONSTRAINT
	FK_StorageCountHeader_Warehouse FOREIGN KEY
	(
	WarehouseRef
	) REFERENCES dbo.Warehouse
	(
	Serial
	) ON UPDATE  NO ACTION 
	 ON DELETE  NO ACTION 
	
GO
ALTER TABLE dbo.StorageCountHeader SET (LOCK_ESCALATION = TABLE)
GO
COMMIT
BEGIN TRANSACTION
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
ALTER TABLE dbo.FactorHeader SET (LOCK_ESCALATION = TABLE)
GO
COMMIT
