/*
   12 September 201816:00:08
   User: 
   Server: dev-db01
   Database: AJK
   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_custport_m_document
	(
	document_id int NOT NULL IDENTITY (1, 1),
	document_code varchar(50) NOT NULL,
	description varchar(150) NOT NULL,
	id_item_dokumen_core varchar(4) NULL,
	created_by varchar(15) NOT NULL,
	created_date datetime NOT NULL,
	modified_by varchar(15) NOT NULL,
	modified_date datetime NOT NULL,
	is_active bit NULL
	)  ON [PRIMARY]
GO
ALTER TABLE dbo.Tmp_custport_m_document SET (LOCK_ESCALATION = TABLE)
GO
GRANT DELETE ON dbo.Tmp_custport_m_document TO public  AS dbo
GO
GRANT INSERT ON dbo.Tmp_custport_m_document TO public  AS dbo
GO
GRANT REFERENCES ON dbo.Tmp_custport_m_document TO public  AS dbo
GO
GRANT SELECT ON dbo.Tmp_custport_m_document TO public  AS dbo
GO
GRANT UPDATE ON dbo.Tmp_custport_m_document TO public  AS dbo
GO
SET IDENTITY_INSERT dbo.Tmp_custport_m_document ON
GO
IF EXISTS(SELECT * FROM dbo.custport_m_document)
	 EXEC('INSERT INTO dbo.Tmp_custport_m_document (document_id, document_code, description, created_by, created_date, modified_by, modified_date, is_active)
		SELECT document_id, document_code, description, created_by, created_date, modified_by, modified_date, is_active FROM dbo.custport_m_document WITH (HOLDLOCK TABLOCKX)')
GO
SET IDENTITY_INSERT dbo.Tmp_custport_m_document OFF
GO
ALTER TABLE dbo.custport_claim_document
	DROP CONSTRAINT FK__custport___docum__3A4352B3
GO
ALTER TABLE dbo.custport_m_claim_document
	DROP CONSTRAINT FK__custport___docum__263C5A06
GO
ALTER TABLE dbo.custport_claim_document_file
	DROP CONSTRAINT FK__custport___docum__3F0807D0
GO
DROP TABLE dbo.custport_m_document
GO
EXECUTE sp_rename N'dbo.Tmp_custport_m_document', N'custport_m_document', 'OBJECT' 
GO
ALTER TABLE dbo.custport_m_document ADD CONSTRAINT
	PK__custport__B1C534BF0F8E3E78 PRIMARY KEY CLUSTERED 
	(
	document_code
	) WITH( STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]

GO
ALTER TABLE dbo.custport_m_document ADD CONSTRAINT
	UQ__custport__9666E8AD91275F46 UNIQUE NONCLUSTERED 
	(
	document_id
	) 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.custport_claim_document_file ADD CONSTRAINT
	FK__custport___docum__3F0807D0 FOREIGN KEY
	(
	document_code
	) REFERENCES dbo.custport_m_document
	(
	document_code
	) ON UPDATE  NO ACTION 
	 ON DELETE  NO ACTION 
	
GO
ALTER TABLE dbo.custport_claim_document_file SET (LOCK_ESCALATION = TABLE)
GO
COMMIT
BEGIN TRANSACTION
GO
ALTER TABLE dbo.custport_m_claim_document ADD CONSTRAINT
	FK__custport___docum__263C5A06 FOREIGN KEY
	(
	document_code
	) REFERENCES dbo.custport_m_document
	(
	document_code
	) ON UPDATE  NO ACTION 
	 ON DELETE  NO ACTION 
	
GO
ALTER TABLE dbo.custport_m_claim_document SET (LOCK_ESCALATION = TABLE)
GO
COMMIT
BEGIN TRANSACTION
GO
ALTER TABLE dbo.custport_claim_document ADD CONSTRAINT
	FK__custport___docum__3A4352B3 FOREIGN KEY
	(
	document_code
	) REFERENCES dbo.custport_m_document
	(
	document_code
	) ON UPDATE  NO ACTION 
	 ON DELETE  NO ACTION 
	
GO
ALTER TABLE dbo.custport_claim_document SET (LOCK_ESCALATION = TABLE)
GO
COMMIT
