Use ATNDBTest
Go


/*
   الجمعة, جوان 19, 201501:38:01 ب.ظ
   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_Units
	(
	Serial bigint NOT NULL,
	Code bigint NULL,
	Detail varchar(100) NULL,
	SubUnitRef bigint NULL,
	Ratio float(53) 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_Units SET (LOCK_ESCALATION = TABLE)
GO
IF EXISTS(SELECT * FROM dbo.Units)
	 EXEC('INSERT INTO dbo.Tmp_Units (Serial, Code, Detail, RecorderRef, RecordDate, OfficeDetailRef)
		SELECT Serial, Code, Detail, RecorderRef, RecordDate, OfficeDetailRef FROM dbo.Units WITH (HOLDLOCK TABLOCKX)')
GO
ALTER TABLE dbo.GritProduct
	DROP CONSTRAINT FK_GritProduct_Unit
GO
ALTER TABLE dbo.Part
	DROP CONSTRAINT FK_Parts_Unit
GO
DROP TABLE dbo.Units
GO
EXECUTE sp_rename N'dbo.Tmp_Units', N'Units', 'OBJECT' 
GO
ALTER TABLE dbo.Units ADD CONSTRAINT
	PK_Unit 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.Part ADD CONSTRAINT
	FK_Parts_Unit FOREIGN KEY
	(
	UnitRef
	) REFERENCES dbo.Units
	(
	Serial
	) ON UPDATE  NO ACTION 
	 ON DELETE  NO ACTION 
	
GO
ALTER TABLE dbo.Part SET (LOCK_ESCALATION = TABLE)
GO
COMMIT
BEGIN TRANSACTION
GO
ALTER TABLE dbo.GritProduct ADD CONSTRAINT
	FK_GritProduct_Unit FOREIGN KEY
	(
	UnitRef
	) REFERENCES dbo.Units
	(
	Serial
	) ON UPDATE  NO ACTION 
	 ON DELETE  NO ACTION 
	
GO
ALTER TABLE dbo.GritProduct SET (LOCK_ESCALATION = TABLE)
GO
COMMIT
