/*
   19 September 201815:37:42
   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
--ALTER TABLE dbo.custport_m_user
--	DROP CONSTRAINT FK__custport___user___73B0DA39
--GO
ALTER TABLE dbo.custport_m_user_type SET (LOCK_ESCALATION = TABLE)
GO
COMMIT
BEGIN TRANSACTION
GO
CREATE TABLE dbo.Tmp_custport_m_user
	(
	user_id int NOT NULL IDENTITY (1, 1),
	username varchar(30) NOT NULL,
	username_login varchar(100) NULL,
	fullname varchar(100) NOT NULL,
	email varchar(100) NULL,
	user_type_code varchar(10) NULL,
	password varchar(32) 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 NOT NULL
	)  ON [PRIMARY]
GO
ALTER TABLE dbo.Tmp_custport_m_user SET (LOCK_ESCALATION = TABLE)
GO
GRANT DELETE ON dbo.Tmp_custport_m_user TO public  AS dbo
GO
GRANT INSERT ON dbo.Tmp_custport_m_user TO public  AS dbo
GO
GRANT REFERENCES ON dbo.Tmp_custport_m_user TO public  AS dbo
GO
GRANT SELECT ON dbo.Tmp_custport_m_user TO public  AS dbo
GO
GRANT UPDATE ON dbo.Tmp_custport_m_user TO public  AS dbo
GO
SET IDENTITY_INSERT dbo.Tmp_custport_m_user ON
GO
IF EXISTS(SELECT * FROM dbo.custport_m_user)
	 EXEC('INSERT INTO dbo.Tmp_custport_m_user (user_id, username, username_login, fullname, email, user_type_code, password, created_by, created_date, modified_by, modified_date, is_active)
		SELECT user_id, username, username, fullname, email, user_type_code, password, created_by, created_date, modified_by, modified_date, COALESCE(is_active,1) FROM dbo.custport_m_user WITH (HOLDLOCK TABLOCKX)')
GO
SET IDENTITY_INSERT dbo.Tmp_custport_m_user OFF
GO


DROP TABLE dbo.custport_m_user
GO
EXECUTE sp_rename N'dbo.Tmp_custport_m_user', N'custport_m_user', 'OBJECT' 
GO
ALTER TABLE dbo.custport_m_user ADD CONSTRAINT
	DF_custport_m_user_is_active DEFAULT 1 FOR is_active
GO
ALTER TABLE dbo.custport_m_user ADD CONSTRAINT
	PK_custport_m_user PRIMARY KEY CLUSTERED 
	(
	user_id
	) WITH( STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]

GO
ALTER TABLE dbo.custport_m_user ADD CONSTRAINT
	UQ__custport__B9BE370E7A9BCB7D UNIQUE NONCLUSTERED 
	(
	user_id
	) WITH( STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]

GO
ALTER TABLE dbo.custport_m_user ADD CONSTRAINT
	UQ_custport_m_user_username UNIQUE NONCLUSTERED 
	(
	username
	) WITH( STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]

GO
ALTER TABLE dbo.custport_m_user ADD CONSTRAINT
	FK__custport___user___73B0DA39 FOREIGN KEY
	(
	user_type_code
	) REFERENCES dbo.custport_m_user_type
	(
	user_type_code
	) ON UPDATE  NO ACTION 
	 ON DELETE  NO ACTION 
	
GO
COMMIT
