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.Skills
	DROP CONSTRAINT FK_Skills_Character
GO
ALTER TABLE dbo.Character SET (LOCK_ESCALATION = TABLE)
GO
COMMIT
BEGIN TRANSACTION
GO
CREATE TABLE dbo.Tmp_Skills
	(
	ID int NOT NULL IDENTITY (1, 1),
	Owner int NOT NULL,
	SkillID smallint NOT NULL,
	Upgrades smallint NOT NULL,
	IsPassive bit NOT NULL
	)  ON [PRIMARY]
GO
ALTER TABLE dbo.Tmp_Skills SET (LOCK_ESCALATION = TABLE)
GO
SET IDENTITY_INSERT dbo.Tmp_Skills ON
GO
IF EXISTS(SELECT * FROM dbo.Skills)
	 EXEC('INSERT INTO dbo.Tmp_Skills (ID, Owner, SkillID, Upgrades, IsPassive)
		SELECT ID, Owner, SkillID, Upgrades, IsPassive FROM dbo.Skills WITH (HOLDLOCK TABLOCKX)')
GO
SET IDENTITY_INSERT dbo.Tmp_Skills OFF
GO
DROP TABLE dbo.Skills
GO
EXECUTE sp_rename N'dbo.Tmp_Skills', N'Skills', 'OBJECT' 
GO
ALTER TABLE dbo.Skills ADD CONSTRAINT
	PK_Skills PRIMARY KEY CLUSTERED 
	(
	ID
	) WITH( STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]

GO
CREATE UNIQUE NONCLUSTERED INDEX UniqueSkillPerOwner ON dbo.Skills
	(
	SkillID,
	Owner
	) WITH( STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
GO
ALTER TABLE dbo.Skills ADD CONSTRAINT
	FK_Skills_Character FOREIGN KEY
	(
	Owner
	) REFERENCES dbo.Character
	(
	ID
	) ON UPDATE  NO ACTION 
	 ON DELETE  CASCADE 
	
GO
COMMIT