Use ATNDBTest
Go

/*
   Sunday, December 14, 20142:53:28 PM
   User: 
   Server: .
   Database: ATNDB
   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
ALTER TABLE dbo.UserActionLog
	DROP CONSTRAINT FK_UserActionLog_SystemsOperation
GO
ALTER TABLE dbo.SystemsOperation SET (LOCK_ESCALATION = TABLE)
GO
COMMIT
BEGIN TRANSACTION
GO
CREATE TABLE dbo.Tmp_UserActionLog
	(
	Serial bigint NOT NULL,
	UserRef int NULL,
	UserKey varchar(50) NULL,
	ComputerName varchar(100) NULL,
	Date char(10) NULL,
	Time char(8) NULL,
	SystemsOperationRef varchar(20) NULL,
	SystemsDataRef varchar(50) NULL,
	OfficeDetailRef int NULL,
	OfficePeriodRef int NULL
	)  ON [PRIMARY]
GO
ALTER TABLE dbo.Tmp_UserActionLog SET (LOCK_ESCALATION = TABLE)
GO
IF EXISTS(SELECT * FROM dbo.UserActionLog)
	 EXEC('INSERT INTO dbo.Tmp_UserActionLog (Serial, UserRef, Date, Time, SystemsOperationRef, SystemsDataRef, OfficeDetailRef, OfficePeriodRef)
		SELECT Serial, UserRef, Date, Time, SystemsOperationRef, SystemsDataRef, OfficeDetailRef, OfficePeriodRef FROM dbo.UserActionLog WITH (HOLDLOCK TABLOCKX)')
GO
DROP TABLE dbo.UserActionLog
GO
EXECUTE sp_rename N'dbo.Tmp_UserActionLog', N'UserActionLog', 'OBJECT' 
GO
ALTER TABLE dbo.UserActionLog ADD CONSTRAINT
	PK_UserActionLog 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.UserActionLog ADD CONSTRAINT
	FK_UserActionLog_SystemsOperation FOREIGN KEY
	(
	SystemsOperationRef
	) REFERENCES dbo.SystemsOperation
	(
	Serial
	) ON UPDATE  NO ACTION 
	 ON DELETE  NO ACTION 
	
GO
COMMIT
