/* 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.AppSetting
	DROP CONSTRAINT DF_AppSetting_UserID
GO
CREATE TABLE dbo.Tmp_AppSetting
	(
	Name char(50) NOT NULL,
	Description nvarchar(100) NULL,
	TheValue nvarchar(512) NOT NULL,
	UserID bigint NOT NULL,
	ImageValue varbinary(MAX) NULL,
	DateValue datetime NULL,
	NumberValue decimal(28, 10) NULL
	)  ON [PRIMARY]
	 TEXTIMAGE_ON [PRIMARY]
GO
ALTER TABLE dbo.Tmp_AppSetting ADD CONSTRAINT
	DF_AppSetting_UserID DEFAULT ((0)) FOR UserID
GO
IF EXISTS(SELECT * FROM dbo.AppSetting)
	 EXEC('INSERT INTO dbo.Tmp_AppSetting (Name, Description, TheValue, UserID, ImageValue, DateValue, NumberValue)
		SELECT Name, Description, TheValue, UserID, ImageValue, DateValue, NumberValue FROM dbo.AppSetting WITH (HOLDLOCK TABLOCKX)')
GO
DROP TABLE dbo.AppSetting
GO
EXECUTE sp_rename N'dbo.Tmp_AppSetting', N'AppSetting', 'OBJECT' 
GO
ALTER TABLE dbo.AppSetting ADD CONSTRAINT
	PK_AppSetting PRIMARY KEY CLUSTERED 
	(
	Name
	) WITH( STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]

GO
COMMIT
