/*
   16 Agustus 201814:40:07
   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_claim_type
	(
	claim_type_id int NOT NULL IDENTITY (1, 1),
	claim_type_code varchar(50) NOT NULL,
	description varchar(100) NOT NULL,
	claim_core_code varchar(1) NULL,
	is_need_account bit NOT 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_claim_type SET (LOCK_ESCALATION = TABLE)
GO
GRANT DELETE ON dbo.Tmp_custport_m_claim_type TO public  AS dbo
GO
GRANT INSERT ON dbo.Tmp_custport_m_claim_type TO public  AS dbo
GO
GRANT REFERENCES ON dbo.Tmp_custport_m_claim_type TO public  AS dbo
GO
GRANT SELECT ON dbo.Tmp_custport_m_claim_type TO public  AS dbo
GO
GRANT UPDATE ON dbo.Tmp_custport_m_claim_type TO public  AS dbo
GO
ALTER TABLE dbo.Tmp_custport_m_claim_type ADD CONSTRAINT
	DF_custport_m_claim_type_is_need_account DEFAULT 0 FOR is_need_account
GO
SET IDENTITY_INSERT dbo.Tmp_custport_m_claim_type ON
GO
IF EXISTS(SELECT * FROM dbo.custport_m_claim_type)
	 EXEC('INSERT INTO dbo.Tmp_custport_m_claim_type (claim_type_id, claim_type_code, description, claim_core_code, created_by, created_date, modified_by, modified_date, is_active)
		SELECT claim_type_id, claim_type_code, description, claim_core_code, created_by, created_date, modified_by, modified_date, is_active FROM dbo.custport_m_claim_type WITH (HOLDLOCK TABLOCKX)')
GO
SET IDENTITY_INSERT dbo.Tmp_custport_m_claim_type OFF
GO
ALTER TABLE dbo.custport_m_claim_document
	DROP CONSTRAINT FK__custport___claim__254835CD
GO
ALTER TABLE dbo.custport_claim
	DROP CONSTRAINT FK__custport___claim__32A230EB
GO
DROP TABLE dbo.custport_m_claim_type
GO
EXECUTE sp_rename N'dbo.Tmp_custport_m_claim_type', N'custport_m_claim_type', 'OBJECT' 
GO
ALTER TABLE dbo.custport_m_claim_type ADD CONSTRAINT
	PK__custport__E28CA1DCA9576026 PRIMARY KEY CLUSTERED 
	(
	claim_type_code
	) 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 ADD CONSTRAINT
	FK__custport___claim__32A230EB FOREIGN KEY
	(
	claim_type_code
	) REFERENCES dbo.custport_m_claim_type
	(
	claim_type_code
	) ON UPDATE  NO ACTION 
	 ON DELETE  NO ACTION 
	
GO
ALTER TABLE dbo.custport_claim SET (LOCK_ESCALATION = TABLE)
GO
COMMIT
BEGIN TRANSACTION
GO
ALTER TABLE dbo.custport_m_claim_document ADD CONSTRAINT
	FK__custport___claim__254835CD FOREIGN KEY
	(
	claim_type_code
	) REFERENCES dbo.custport_m_claim_type
	(
	claim_type_code
	) ON UPDATE  NO ACTION 
	 ON DELETE  NO ACTION 
	
GO
ALTER TABLE dbo.custport_m_claim_document SET (LOCK_ESCALATION = TABLE)
GO
COMMIT
