/*
 Navicat Premium Data Transfer

 Source Server         : AyalaOdin
 Source Server Type    : SQL Server
 Source Server Version : 12002000
 Source Host           : 172.16.69.1:1433
 Source Catalog        : DF_World
 Source Schema         : dbo

 Target Server Type    : SQL Server
 Target Server Version : 12002000
 File Encoding         : 65001

 Date: 24/07/2018 12:55:11
*/


-- ----------------------------
-- Table structure for BlockList
-- ----------------------------
IF EXISTS (SELECT * FROM sys.all_objects WHERE object_id = OBJECT_ID(N'[dbo].[BlockList]') AND type IN ('U'))
	DROP TABLE [dbo].[BlockList]
GO

CREATE TABLE [dbo].[BlockList] (
  [OwnerID] int  NOT NULL,
  [BlockedID] int  NOT NULL
)
GO

ALTER TABLE [dbo].[BlockList] SET (LOCK_ESCALATION = TABLE)
GO


-- ----------------------------
-- Table structure for Buffs
-- ----------------------------
IF EXISTS (SELECT * FROM sys.all_objects WHERE object_id = OBJECT_ID(N'[dbo].[Buffs]') AND type IN ('U'))
	DROP TABLE [dbo].[Buffs]
GO

CREATE TABLE [dbo].[Buffs] (
  [ID] bigint  NOT NULL,
  [OwnerID] int  NOT NULL,
  [AbStateIndex] int  NOT NULL,
  [Strength] int  NOT NULL,
  [StartDate] datetime  NOT NULL,
  [ExpireDate] datetime  NOT NULL,
  [test] text COLLATE SQL_Latin1_General_CP1_CI_AS  NULL
)
GO

ALTER TABLE [dbo].[Buffs] SET (LOCK_ESCALATION = TABLE)
GO


-- ----------------------------
-- Table structure for Character_Options
-- ----------------------------
IF EXISTS (SELECT * FROM sys.all_objects WHERE object_id = OBJECT_ID(N'[dbo].[Character_Options]') AND type IN ('U'))
	DROP TABLE [dbo].[Character_Options]
GO

CREATE TABLE [dbo].[Character_Options] (
  [ID] int  NOT NULL,
  [ShortCutData] varbinary(1024) DEFAULT (0x00) NOT NULL,
  [ShortCutSize] varbinary(24) DEFAULT (0x00) NOT NULL,
  [Video] varbinary(60) DEFAULT (0x00) NOT NULL,
  [Sound] varbinary(1) DEFAULT (0x00) NOT NULL,
  [Game] varbinary(64) DEFAULT (0x00) NOT NULL,
  [WindowsPos] varbinary(392) DEFAULT (0x00) NOT NULL,
  [KeyMapping] varbinary(308) DEFAULT (0x00) NOT NULL
)
GO

ALTER TABLE [dbo].[Character_Options] SET (LOCK_ESCALATION = TABLE)
GO


-- ----------------------------
-- Table structure for Characters
-- ----------------------------
IF EXISTS (SELECT * FROM sys.all_objects WHERE object_id = OBJECT_ID(N'[dbo].[Characters]') AND type IN ('U'))
	DROP TABLE [dbo].[Characters]
GO

CREATE TABLE [dbo].[Characters] (
  [ID] int  NOT NULL,
  [AccountID] int  NOT NULL,
  [Name] nvarchar(20) COLLATE SQL_Latin1_General_CP1_CI_AS  NOT NULL,
  [Slot] tinyint  NOT NULL,
  [Map] smallint  NULL,
  [PositionX] int  NOT NULL,
  [PositionY] int  NOT NULL,
  [Rotation] tinyint DEFAULT ((0)) NOT NULL,
  [Class] tinyint  NOT NULL,
  [Level] tinyint DEFAULT ((1)) NOT NULL,
  [HP] int  NOT NULL,
  [SP] int  NOT NULL,
  [HPStones] smallint  NOT NULL,
  [SPStones] smallint  NOT NULL,
  [EXP] bigint DEFAULT ((0)) NOT NULL,
  [Money] bigint DEFAULT ((0)) NOT NULL,
  [Fame] int DEFAULT ((0)) NOT NULL,
  [KillPoints] int DEFAULT ((0)) NOT NULL,
  [IsMale] bit  NOT NULL,
  [Hair] tinyint  NOT NULL,
  [HairColor] tinyint  NOT NULL,
  [Face] tinyint  NOT NULL,
  [FreeStat_Points] tinyint DEFAULT ((1)) NOT NULL,
  [FreeStat_Str] tinyint DEFAULT ((0)) NOT NULL,
  [FreeStat_End] tinyint DEFAULT ((0)) NOT NULL,
  [FreeStat_Dex] tinyint DEFAULT ((0)) NOT NULL,
  [FreeStat_Int] tinyint DEFAULT ((0)) NOT NULL,
  [FreeStat_Spr] tinyint DEFAULT ((0)) NOT NULL,
  [SkillPoints] tinyint DEFAULT ((0)) NOT NULL,
  [LastLogin] datetime DEFAULT (getdate()) NOT NULL,
  [IsOnline] bit DEFAULT ((0)) NOT NULL,
  [IsFirstLogin] bit DEFAULT ((1)) NOT NULL,
  [LP] int DEFAULT ((0)) NOT NULL,
  [FriendPoints] int DEFAULT ((0)) NOT NULL
)
GO

ALTER TABLE [dbo].[Characters] SET (LOCK_ESCALATION = TABLE)
GO


-- ----------------------------
-- Table structure for Friends
-- ----------------------------
IF EXISTS (SELECT * FROM sys.all_objects WHERE object_id = OBJECT_ID(N'[dbo].[Friends]') AND type IN ('U'))
	DROP TABLE [dbo].[Friends]
GO

CREATE TABLE [dbo].[Friends] (
  [OwnerID] int  NOT NULL,
  [FriendID] int  NOT NULL,
  [RegisterDate] datetime  NOT NULL
)
GO

ALTER TABLE [dbo].[Friends] SET (LOCK_ESCALATION = TABLE)
GO


-- ----------------------------
-- Table structure for GoldSpammer
-- ----------------------------
IF EXISTS (SELECT * FROM sys.all_objects WHERE object_id = OBJECT_ID(N'[dbo].[GoldSpammer]') AND type IN ('U'))
	DROP TABLE [dbo].[GoldSpammer]
GO

CREATE TABLE [dbo].[GoldSpammer] (
  [ReporterID] int  NOT NULL,
  [ReporterIP] nvarchar(15) COLLATE SQL_Latin1_General_CP1_CI_AS  NOT NULL,
  [SpammerID] int  NOT NULL,
  [SpammerIP] nvarchar(15) COLLATE SQL_Latin1_General_CP1_CI_AS  NOT NULL,
  [ReportDate] datetime  NOT NULL
)
GO

ALTER TABLE [dbo].[GoldSpammer] SET (LOCK_ESCALATION = TABLE)
GO


-- ----------------------------
-- Table structure for GroupMembers
-- ----------------------------
IF EXISTS (SELECT * FROM sys.all_objects WHERE object_id = OBJECT_ID(N'[dbo].[GroupMembers]') AND type IN ('U'))
	DROP TABLE [dbo].[GroupMembers]
GO

CREATE TABLE [dbo].[GroupMembers] (
  [GroupID] smallint  NOT NULL,
  [MemberID] int  NOT NULL,
  [Rank] tinyint  NOT NULL
)
GO

ALTER TABLE [dbo].[GroupMembers] SET (LOCK_ESCALATION = TABLE)
GO


-- ----------------------------
-- Table structure for Groups
-- ----------------------------
IF EXISTS (SELECT * FROM sys.all_objects WHERE object_id = OBJECT_ID(N'[dbo].[Groups]') AND type IN ('U'))
	DROP TABLE [dbo].[Groups]
GO

CREATE TABLE [dbo].[Groups] (
  [ID] smallint  NOT NULL,
  [Flags] tinyint  NOT NULL
)
GO

ALTER TABLE [dbo].[Groups] SET (LOCK_ESCALATION = TABLE)
GO


-- ----------------------------
-- Table structure for GuildMembers
-- ----------------------------
IF EXISTS (SELECT * FROM sys.all_objects WHERE object_id = OBJECT_ID(N'[dbo].[GuildMembers]') AND type IN ('U'))
	DROP TABLE [dbo].[GuildMembers]
GO

CREATE TABLE [dbo].[GuildMembers] (
  [GuildID] int  NOT NULL,
  [MemberID] int  NOT NULL,
  [Rank] tinyint  NOT NULL,
  [Corp] smallint  NOT NULL
)
GO

ALTER TABLE [dbo].[GuildMembers] SET (LOCK_ESCALATION = TABLE)
GO


-- ----------------------------
-- Table structure for Guilds
-- ----------------------------
IF EXISTS (SELECT * FROM sys.all_objects WHERE object_id = OBJECT_ID(N'[dbo].[Guilds]') AND type IN ('U'))
	DROP TABLE [dbo].[Guilds]
GO

CREATE TABLE [dbo].[Guilds] (
  [ID] int  NOT NULL,
  [Name] nvarchar(16) COLLATE SQL_Latin1_General_CP1_CI_AS  NOT NULL,
  [Password] varbinary(max)  NOT NULL,
  [AllowGuildWar] bit  NOT NULL,
  [Message] nvarchar(512) COLLATE SQL_Latin1_General_CP1_CI_AS DEFAULT '' NOT NULL,
  [MessageCreateDate] datetime DEFAULT (getdate()) NOT NULL,
  [MessageCreaterID] int DEFAULT ((0)) NOT NULL,
  [CreateDate] datetime  NOT NULL,
  [Money] bigint DEFAULT ((0)) NOT NULL
)
GO

ALTER TABLE [dbo].[Guilds] SET (LOCK_ESCALATION = TABLE)
GO


-- ----------------------------
-- Table structure for ItemOptions
-- ----------------------------
IF EXISTS (SELECT * FROM sys.all_objects WHERE object_id = OBJECT_ID(N'[dbo].[ItemOptions]') AND type IN ('U'))
	DROP TABLE [dbo].[ItemOptions]
GO

CREATE TABLE [dbo].[ItemOptions] (
  [ItemKey] bigint  NOT NULL,
  [OptionType] smallint  NOT NULL,
  [OptionData] bigint  NOT NULL
)
GO

ALTER TABLE [dbo].[ItemOptions] SET (LOCK_ESCALATION = TABLE)
GO


-- ----------------------------
-- Table structure for Items
-- ----------------------------
IF EXISTS (SELECT * FROM sys.all_objects WHERE object_id = OBJECT_ID(N'[dbo].[Items]') AND type IN ('U'))
	DROP TABLE [dbo].[Items]
GO

CREATE TABLE [dbo].[Items] (
  [ItemKey] bigint  NOT NULL,
  [StorageType] tinyint  NOT NULL,
  [Owner] int  NOT NULL,
  [Storage] smallint  NOT NULL,
  [ItemID] int  NOT NULL,
  [Flags] int  NOT NULL,
  [Date] datetime DEFAULT (getdate()) NOT NULL
)
GO

ALTER TABLE [dbo].[Items] SET (LOCK_ESCALATION = TABLE)
GO


-- ----------------------------
-- Table structure for Skills
-- ----------------------------
IF EXISTS (SELECT * FROM sys.all_objects WHERE object_id = OBJECT_ID(N'[dbo].[Skills]') AND type IN ('U'))
	DROP TABLE [dbo].[Skills]
GO

CREATE TABLE [dbo].[Skills] (
  [ID] bigint  NOT NULL,
  [OwnerID] int  NOT NULL,
  [SkillID] smallint  NOT NULL,
  [IsPassive] bit  NOT NULL,
  [Upgrades] varbinary(4)  NOT NULL
)
GO

ALTER TABLE [dbo].[Skills] SET (LOCK_ESCALATION = TABLE)
GO


-- ----------------------------
-- Table structure for Titles
-- ----------------------------
IF EXISTS (SELECT * FROM sys.all_objects WHERE object_id = OBJECT_ID(N'[dbo].[Titles]') AND type IN ('U'))
	DROP TABLE [dbo].[Titles]
GO

CREATE TABLE [dbo].[Titles] (
  [ID] bigint  NOT NULL,
  [OwnerID] int  NOT NULL,
  [TitleType] int  NOT NULL,
  [TitleLevel] tinyint  NOT NULL,
  [RegisterDate] datetime  NOT NULL,
  [IsActive] bit DEFAULT ((0)) NOT NULL,
  [Data] bigint  NOT NULL
)
GO

ALTER TABLE [dbo].[Titles] SET (LOCK_ESCALATION = TABLE)
GO


-- ----------------------------
-- Procedure structure for BlockList_Remove
-- ----------------------------
IF EXISTS (SELECT * FROM sys.all_objects WHERE object_id = OBJECT_ID(N'[dbo].[BlockList_Remove]') AND type IN ('P', 'PC', 'RF', 'X'))
	DROP PROCEDURE[dbo].[BlockList_Remove]
GO

CREATE PROCEDURE [dbo].[BlockList_Remove]
	
	@pOwnerID INT,
	@pBlockedID INT
	
AS
BEGIN
	
	DELETE FROM BlockList WHERE OwnerID = @pOwnerID AND BlockedID = @pBlockedID;
	
END
GO


-- ----------------------------
-- Procedure structure for BlockList_Save
-- ----------------------------
IF EXISTS (SELECT * FROM sys.all_objects WHERE object_id = OBJECT_ID(N'[dbo].[BlockList_Save]') AND type IN ('P', 'PC', 'RF', 'X'))
	DROP PROCEDURE[dbo].[BlockList_Save]
GO

CREATE PROCEDURE [dbo].[BlockList_Save]
	
	@pOwnerID INT,
	@pBlockedID INT
	
AS
BEGIN
	
	
	IF EXISTS (SELECT OwnerID FROM BlockList WHERE OwnerID = @pOwnerID AND BlockedID = @pBlockedID)
	BEGIN
		RETURN;
	END
	
	
	INSERT INTO BlockList
													(OwnerID,   BlockedID)
							VALUES
													(@pOwnerID, @pBlockedID);
	
END
GO


-- ----------------------------
-- Procedure structure for Buff_Insert
-- ----------------------------
IF EXISTS (SELECT * FROM sys.all_objects WHERE object_id = OBJECT_ID(N'[dbo].[Buff_Insert]') AND type IN ('P', 'PC', 'RF', 'X'))
	DROP PROCEDURE[dbo].[Buff_Insert]
GO

CREATE PROCEDURE [dbo].[Buff_Insert]
	
	@pOwnerID INT,
	@pAbStateIndex INT,
	@pStrength INT,
	@pStartDate DATETIME,
	@pExpireDate DATETIME,
	
	@pID BIGINT OUTPUT
	
AS
BEGIN
	
	
	BEGIN TRAN
		
		DECLARE @pTries INT = 0;
		SET @pID = CAST(CRYPT_GEN_RANDOM(8) AS BIGINT);

		WHILE EXISTS (SELECT ID FROM Buffs WHERE ID = @pID)
		BEGIN
			SET @pID = CAST(CRYPT_GEN_RANDOM(8) AS BIGINT);
			
			SET @pTries = (@pTries + 1);
			IF (@pTries >= 25)
			BEGIN
				ROLLBACK TRAN;
				SELECT -1;
				RETURN;
			END
		END
		
		
		
		INSERT INTO Buffs
											(ID,   OwnerID,   AbStateIndex,   Strength,   StartDate,   ExpireDate)
								VALUES
											(@pID, @pOwnerID, @pAbStateIndex, @pStrength, @pStartDate, @pExpireDate);
		
		
		IF (@@ROWCOUNT = 0)
		BEGIN
			ROLLBACK TRAN;
			SELECT -2;
			RETURN;
		END
		
		
		SELECT 0;
	
	COMMIT TRAN
	
	
	
	
END
GO


-- ----------------------------
-- Procedure structure for Buff_Remove
-- ----------------------------
IF EXISTS (SELECT * FROM sys.all_objects WHERE object_id = OBJECT_ID(N'[dbo].[Buff_Remove]') AND type IN ('P', 'PC', 'RF', 'X'))
	DROP PROCEDURE[dbo].[Buff_Remove]
GO

CREATE PROCEDURE [dbo].[Buff_Remove]
	
	@pID BIGINT
	
AS
BEGIN
	
	DELETE FROM Buffs WHERE ID = @pID;
	
END
GO


-- ----------------------------
-- Procedure structure for Buff_Save
-- ----------------------------
IF EXISTS (SELECT * FROM sys.all_objects WHERE object_id = OBJECT_ID(N'[dbo].[Buff_Save]') AND type IN ('P', 'PC', 'RF', 'X'))
	DROP PROCEDURE[dbo].[Buff_Save]
GO

CREATE PROCEDURE [dbo].[Buff_Save]
	
	@pID BIGINT,
	
	@pStrength INT,
	@pStartDate DATETIME,
	@pExpireDate DATETIME
	
AS
BEGIN
	
	
	UPDATE Buffs SET
										StartDate				= @pStartDate,
										ExpireDate			= @pExpireDate
							 WHERE
										ID							= @pID;
	
	
	
END
GO


-- ----------------------------
-- Procedure structure for Character_ChangeName
-- ----------------------------
IF EXISTS (SELECT * FROM sys.all_objects WHERE object_id = OBJECT_ID(N'[dbo].[Character_ChangeName]') AND type IN ('P', 'PC', 'RF', 'X'))
	DROP PROCEDURE[dbo].[Character_ChangeName]
GO

CREATE PROCEDURE [dbo].[Character_ChangeName]
	@pCharID INT,
	@pName NVARCHAR(20)
AS
BEGIN

IF EXISTS (SELECT ID FROM Characters WHERE Name = @pName)
	BEGIN
		SELECT -2;
		RETURN;
	END


	BEGIN TRAN
		
		UPDATE Characters
											SET
													Name = @pName
											WHERE
													ID								= @pCharID;
		
		
		
		
		IF (@@ROWCOUNT = 0)
		BEGIN
			ROLLBACK TRAN;
			SELECT -1;
			RETURN;
		END
		
		
		SELECT -1;
		
		
	COMMIT TRAN

	BEGIN TRAN
COMMIT TRAN
  -- routine body goes here, e.g.
  -- SELECT 'Navicat for SQL Server'
END
GO


-- ----------------------------
-- Procedure structure for Character_Insert
-- ----------------------------
IF EXISTS (SELECT * FROM sys.all_objects WHERE object_id = OBJECT_ID(N'[dbo].[Character_Insert]') AND type IN ('P', 'PC', 'RF', 'X'))
	DROP PROCEDURE[dbo].[Character_Insert]
GO

CREATE PROCEDURE [dbo].[Character_Insert]
	
	@pAccountID INT,
	@pName NVARCHAR(20),
	@pSlot TINYINT,
	
	@pMap SMALLINT,
	@pPositionX INT,
	@pPositionY INT,
	@pRotation TINYINT,

	@pClass TINYINT,
	@pHP INT,
	@pSP INT,
	@pLP INT,
	@pHPStones SMALLINT,
	@pSPStones SMALLINT,
	
	@pMoney BIGINT,
	
	@pIsMale BIT,
	@pHair TINYINT,
	@pHairColor TINYINT,
	@pFace TINYINT,
	
	
	@pID INT OUTPUT
	
AS
BEGIN
	
	IF EXISTS (SELECT ID FROM Characters WHERE Name = @pName)
	BEGIN
		SELECT -1;
		RETURN;
	END
	
	IF EXISTS (SELECT ID FROM Characters WHERE AccountID = @pAccountID AND Slot = @pSlot)
	BEGIN
		SELECT -2;
		RETURN;
	END
	
	
	

	
	BEGIN TRAN
		
		DECLARE @pTries INT = 0;
		SET @pID = CAST(CRYPT_GEN_RANDOM(4) AS INT);

		WHILE EXISTS (SELECT ID FROM Characters WHERE ID = @pID)
		BEGIN
			SET @pID = CAST(CRYPT_GEN_RANDOM(4) AS INT);
			
			SET @pTries = (@pTries + 1);
			IF (@pTries >= 25)
			BEGIN
				ROLLBACK TRAN;
				SELECT -3;
				RETURN;
			END
		END
		
		
		
		IF EXISTS (SELECT ID FROM Character_Options WHERE ID = @pID)
	 BEGIN
		SELECT -5;
		RETURN;
	END
		
INSERT INTO Character_Options (ID) VALUES (@pID);
		
		IF (@@ROWCOUNT = 0)
		BEGIN
			ROLLBACK TRAN;
			SELECT -6;
			RETURN;
		END

		INSERT INTO Characters
														(ID,   AccountID,   Name,   Slot,   Map,   PositionX,   PositionY,   Class,   HP,   SP,  LP,  HPStones,   SPStones,   Money,   IsMale,   Hair,   HairColor,   Face)
								VALUES
														(@pID, @pAccountID, @pName, @pSlot, @pMap, @pPositionX, @pPositionY, @pClass, @pHP, @pSP, @pLP, @pHPStones, @pSPStones, @pMoney, @pIsMale, @pHair, @pHairColor, @pFace);
		
		
		IF (@@ROWCOUNT = 0)
		BEGIN
			ROLLBACK TRAN;
			SELECT -4;
			RETURN;
		END
		
		
		SELECT 0;
		
	COMMIT TRAN
	
END
GO


-- ----------------------------
-- Procedure structure for Character_Remove
-- ----------------------------
IF EXISTS (SELECT * FROM sys.all_objects WHERE object_id = OBJECT_ID(N'[dbo].[Character_Remove]') AND type IN ('P', 'PC', 'RF', 'X'))
	DROP PROCEDURE[dbo].[Character_Remove]
GO

CREATE PROCEDURE [dbo].[Character_Remove]
	
	@pID INT
	
AS
BEGIN
	
	


/**EquipItems*/
EXEC Items_Purge @pID , 8;
/*Inventory*/
EXEC Items_Purge @pID , 9;
/*Premium Items*/
EXEC Items_Purge @pID , 10;
/*MiniHaouse*/
EXEC Items_Purge @pID , 12;
/*Premium Emotions*/
EXEC Items_Purge @pID , 15;


DELETE FROM Character_Options WHERE ID = @pID;
	/* delete character itself */
	DELETE FROM Characters WHERE ID = @pID;
	SELECT -1;
END
GO


-- ----------------------------
-- Procedure structure for Character_Update_FirstLogin
-- ----------------------------
IF EXISTS (SELECT * FROM sys.all_objects WHERE object_id = OBJECT_ID(N'[dbo].[Character_Update_FirstLogin]') AND type IN ('P', 'PC', 'RF', 'X'))
	DROP PROCEDURE[dbo].[Character_Update_FirstLogin]
GO

CREATE PROCEDURE [dbo].[Character_Update_FirstLogin]
	
	@pID INT,
	@pIsFirstLogin BIT
	
AS
BEGIN
	
	UPDATE Characters SET IsFirstLogin = @pIsFirstLogin WHERE ID = @pID;
	
END
GO


-- ----------------------------
-- Procedure structure for Character_Update_World
-- ----------------------------
IF EXISTS (SELECT * FROM sys.all_objects WHERE object_id = OBJECT_ID(N'[dbo].[Character_Update_World]') AND type IN ('P', 'PC', 'RF', 'X'))
	DROP PROCEDURE[dbo].[Character_Update_World]
GO

CREATE PROCEDURE [dbo].[Character_Update_World]
	
	@pID INT,
	
	@pIsMale BIT,
	@pHair TINYINT,
	@pHairColor TINYINT,
	@pFace TINYINT
	
AS
BEGIN
	
	
	BEGIN TRAN
		
		UPDATE Characters
											SET
													IsMale						= @pIsMale,
													Hair							= @pHair,
													HairColor					= @pHairColor,
													Face							= @pFace
													

											WHERE
													ID								= @pID;
		
		
		
		
		IF (@@ROWCOUNT = 0)
		BEGIN
			ROLLBACK TRAN;
			SELECT -1;
			RETURN;
		END
		
		
		SELECT 0;
		
		
	COMMIT TRAN
	
	
	
END
GO


-- ----------------------------
-- Procedure structure for Character_Update_Zone
-- ----------------------------
IF EXISTS (SELECT * FROM sys.all_objects WHERE object_id = OBJECT_ID(N'[dbo].[Character_Update_Zone]') AND type IN ('P', 'PC', 'RF', 'X'))
	DROP PROCEDURE[dbo].[Character_Update_Zone]
GO

CREATE PROCEDURE [dbo].[Character_Update_Zone]
	
	@pID INT,
	
	@pName NVARCHAR(20),
	
	@pMap SMALLINT,
	@pPositionX INT,
	@pPositionY INT,
	@pRotation TINYINT,
	
	@pClass TINYINT,
	@pLevel TINYINT,
	@pHP INT,
	@pSP INT,
	@pHPStones SMALLINT,
	@pSPStones SMALLINT,
	
	@pEXP BIGINT,
	@pMoney BIGINT,
	@pFame INT,
	@pKillPoints INT,
	@pFriendPoints INT,

	@pFreeStat_Points TINYINT,
	@pFreeStat_Str TINYINT,
	@pFreeStat_End TINYINT,
	@pFreeStat_Dex TINYINT,
	@pFreeStat_Int TINYINT,
	@pFreeStat_Spr TINYINT,
	@pSkillPoints TINYINT
	
AS
BEGIN
	
	
	BEGIN TRAN
		
		
		UPDATE Characters
											SET
													Name						= @pName,
													
													Map							= @pMap,
													PositionX				= @pPositionX,
													PositionY				= @pPositionY,
													Rotation				= @pRotation,
													
													Class						= @pClass,
													Level						= @pLevel,
													HP							= @pHP,
													SP							= @pSP,
													HPStones				= @pHPStones,
													SPStones				= @pSPStones,
													
													EXP							= @pEXP,
													Money						= @pMoney,
													Fame						= @pFame,
													KillPoints			= @pKillPoints,
													FriendPoints    = @pFriendPoints,
													FreeStat_Points	= @pFreeStat_Points,
													FreeStat_Str		= @pFreeStat_Str,
													FreeStat_End		= @pFreeStat_End,
													FreeStat_Dex		= @pFreeStat_Dex,
													FreeStat_Int		= @pFreeStat_Int,
													FreeStat_Spr		= @pFreeStat_Spr,
													SkillPoints			= @pSkillPoints
											WHERE
													ID							= @pID;
		
		
		
		
	COMMIT TRAN
	
	
	
END
GO


-- ----------------------------
-- Procedure structure for Character_UpdateState
-- ----------------------------
IF EXISTS (SELECT * FROM sys.all_objects WHERE object_id = OBJECT_ID(N'[dbo].[Character_UpdateState]') AND type IN ('P', 'PC', 'RF', 'X'))
	DROP PROCEDURE[dbo].[Character_UpdateState]
GO

CREATE PROCEDURE [dbo].[Character_UpdateState]
	
	@pID INT,
	
	@pIsOnline BIT,
	@pLastLogin DATETIME
	
AS
BEGIN
	
	UPDATE Characters SET
													IsOnline					= @pIsOnline,
													LastLogin					= @pLastLogin
										WHERE
													ID								= @pID;
	
END
GO


-- ----------------------------
-- Procedure structure for Friend_Insert
-- ----------------------------
IF EXISTS (SELECT * FROM sys.all_objects WHERE object_id = OBJECT_ID(N'[dbo].[Friend_Insert]') AND type IN ('P', 'PC', 'RF', 'X'))
	DROP PROCEDURE[dbo].[Friend_Insert]
GO

CREATE PROCEDURE [dbo].[Friend_Insert]
	
	@pOwnerID INT,
	@pFriendID INT,
	@pRegisterDate DATETIME
	
AS
BEGIN
	
	
	
	BEGIN TRAN
		
		IF EXISTS (SELECT OwnerID FROM Friends WHERE OwnerID = @pOwnerID AND FriendID = @pFriendID)
		BEGIN
			ROLLBACK TRAN;
			SELECT -1;
			RETURN;
		END
		
		IF EXISTS (SELECT OwnerID FROM Friends WHERE OwnerID = @pFriendID AND FriendID = @pOwnerID)
		BEGIN
			ROLLBACK TRAN;
			SELECT -2;
			RETURN;
		END
		
		
		INSERT INTO Friends
												(OwnerID,   FriendID,   RegisterDate)
								VALUES
												(@pOwnerID, @pFriendID, @pRegisterDate);
		
		IF (@@ROWCOUNT = 0)
		BEGIN
			ROLLBACK TRAN;
			SELECT -3;
			RETURN;
		END
		
		INSERT INTO Friends
												(OwnerID,   FriendID,   RegisterDate)
								VALUES
												(@pFriendID, @pOwnerID, @pRegisterDate);
		
		IF (@@ROWCOUNT = 0)
		BEGIN
			ROLLBACK TRAN;
			SELECT -4;
			RETURN;
		END
		
		
		
		SELECT 0;
		
		
	COMMIT TRAN
	
END
GO


-- ----------------------------
-- Procedure structure for Friend_Remove
-- ----------------------------
IF EXISTS (SELECT * FROM sys.all_objects WHERE object_id = OBJECT_ID(N'[dbo].[Friend_Remove]') AND type IN ('P', 'PC', 'RF', 'X'))
	DROP PROCEDURE[dbo].[Friend_Remove]
GO

CREATE PROCEDURE [dbo].[Friend_Remove]
	
	@pOwnerID INT,
	@pFriendID INT
	
AS
BEGIN
	
	DELETE FROM Friends WHERE OwnerID = @pOwnerID AND FriendID = @pFriendID;
	DELETE FROM Friends WHERE OwnerID = @pFriendID AND FriendID = @pOwnerID;
	
END
GO


-- ----------------------------
-- Procedure structure for GoldSpammer_Insert
-- ----------------------------
IF EXISTS (SELECT * FROM sys.all_objects WHERE object_id = OBJECT_ID(N'[dbo].[GoldSpammer_Insert]') AND type IN ('P', 'PC', 'RF', 'X'))
	DROP PROCEDURE[dbo].[GoldSpammer_Insert]
GO

CREATE PROCEDURE [dbo].[GoldSpammer_Insert]
	
	@pReporterID INT,
	@pReporterIP NVARCHAR(15),
	
	@pSpammerID INT,
	@pSpammerIP NVARCHAR(15),
	
	@pReportDate DATETIME
	
AS
BEGIN
	
	
	INSERT INTO GoldSpammer
													(ReporterID,   ReporterIP,   SpammerID,   SpammerIP,   ReportDate)
							VALUES
													(@pReporterID, @pReporterIP, @pSpammerID, @pSpammerIP, @pReportDate);
	
	
END
GO


-- ----------------------------
-- Procedure structure for Group_Insert
-- ----------------------------
IF EXISTS (SELECT * FROM sys.all_objects WHERE object_id = OBJECT_ID(N'[dbo].[Group_Insert]') AND type IN ('P', 'PC', 'RF', 'X'))
	DROP PROCEDURE[dbo].[Group_Insert]
GO

CREATE PROCEDURE [dbo].[Group_Insert]
	
	@pFlags TINYINT,
	
	@pID SMALLINT OUTPUT
	
AS
BEGIN
	
	BEGIN TRAN
		
		DECLARE @pTries INT = 0;
		SET @pID = CAST(CRYPT_GEN_RANDOM(2) AS SMALLINT);

		WHILE EXISTS (SELECT ID FROM Groups WHERE ID = @pID)
		BEGIN
			SET @pID = CAST(CRYPT_GEN_RANDOM(2) AS SMALLINT);
			
			SET @pTries = (@pTries + 1);
			IF (@pTries >= 25)
			BEGIN
				ROLLBACK TRAN;
				SELECT -1;
				RETURN;
			END
		END
		
		
		INSERT INTO Groups (ID, Flags) VALUES (@pID, @pFlags);
		
		
		IF (@@ROWCOUNT = 0)
		BEGIN
			ROLLBACK TRAN;
			SELECT -2;
			RETURN;
		END
		
		
		SELECT 0;
		
		
	COMMIT TRAN
	
END
GO


-- ----------------------------
-- Procedure structure for Group_Remove
-- ----------------------------
IF EXISTS (SELECT * FROM sys.all_objects WHERE object_id = OBJECT_ID(N'[dbo].[Group_Remove]') AND type IN ('P', 'PC', 'RF', 'X'))
	DROP PROCEDURE[dbo].[Group_Remove]
GO

CREATE PROCEDURE [dbo].[Group_Remove]
	
	@pID SMALLINT
	
AS
BEGIN
	
	DELETE FROM Groups WHERE ID = @pID;
	
END
GO


-- ----------------------------
-- Procedure structure for Group_UpdateMaster
-- ----------------------------
IF EXISTS (SELECT * FROM sys.all_objects WHERE object_id = OBJECT_ID(N'[dbo].[Group_UpdateMaster]') AND type IN ('P', 'PC', 'RF', 'X'))
	DROP PROCEDURE[dbo].[Group_UpdateMaster]
GO

CREATE PROCEDURE [dbo].[Group_UpdateMaster]
	
	@pGroupID SMALLINT,
	
	@pOldMasterID INT,
	@pNewMasterID INT
	
AS
BEGIN
	
	UPDATE GroupMembers SET Rank = 2 WHERE GroupID = @pGroupID AND MemberID = @pOldMasterID;
	UPDATE GroupMembers SET Rank = 1 WHERE GroupID = @pGroupID AND MemberID = @pNewMasterID;
	
END
GO


-- ----------------------------
-- Procedure structure for GroupMember_Insert
-- ----------------------------
IF EXISTS (SELECT * FROM sys.all_objects WHERE object_id = OBJECT_ID(N'[dbo].[GroupMember_Insert]') AND type IN ('P', 'PC', 'RF', 'X'))
	DROP PROCEDURE[dbo].[GroupMember_Insert]
GO

CREATE PROCEDURE [dbo].[GroupMember_Insert]
	
	@pGroupID SMALLINT,
	@pMemberID INT,
  @pRank TINYINT
	
AS
BEGIN
	
	INSERT INTO GroupMembers
														(GroupID,   MemberID,   Rank)
						  VALUES
														(@pGroupID, @pMemberID, @pRank);
	
END
GO


-- ----------------------------
-- Procedure structure for GroupMember_Remove
-- ----------------------------
IF EXISTS (SELECT * FROM sys.all_objects WHERE object_id = OBJECT_ID(N'[dbo].[GroupMember_Remove]') AND type IN ('P', 'PC', 'RF', 'X'))
	DROP PROCEDURE[dbo].[GroupMember_Remove]
GO

CREATE PROCEDURE [dbo].[GroupMember_Remove]
	
	@pGroupID SMALLINT,
	@pMemberID INT
	
AS
BEGIN
	
	DELETE FROM GroupMembers WHERE GroupID = @pGroupID AND MemberID = @pMemberID;
	
END
GO


-- ----------------------------
-- Procedure structure for Guild_Insert
-- ----------------------------
IF EXISTS (SELECT * FROM sys.all_objects WHERE object_id = OBJECT_ID(N'[dbo].[Guild_Insert]') AND type IN ('P', 'PC', 'RF', 'X'))
	DROP PROCEDURE[dbo].[Guild_Insert]
GO

CREATE PROCEDURE [dbo].[Guild_Insert]
	
	@pName NVARCHAR(16),
	@pPassword VARBINARY(MAX),
	@pAllowGuildWar BIT,
	@pMasterID INT,
	@pCreateDate DATETIME,
	
	
	
	@pID INT OUTPUT
	
AS
BEGIN
	
	IF EXISTS (SELECT ID FROM Guilds WHERE Name = @pName)
	BEGIN
		SELECT -1;
		RETURN;
	END
	
	
	
	
	BEGIN TRAN
		
		DECLARE @pTries INT = 0;
		SET @pID = CAST(CRYPT_GEN_RANDOM(4) AS INT);

		WHILE EXISTS (SELECT ID FROM Guilds WHERE ID = @pID)
		BEGIN
			SET @pID = CAST(CRYPT_GEN_RANDOM(4) AS INT);
			
			SET @pTries = (@pTries + 1);
			IF (@pTries >= 25)
			BEGIN
				ROLLBACK TRAN;
				SELECT -2;
				RETURN;
			END
		END
		
		
		
		INSERT INTO Guilds
												(ID,   Name,   Password,   AllowGuildWar,   MessageCreateDate, MessageCreaterID, CreateDate)
								VALUES
												(@pID, @pName, @pPassword, @pAllowGuildWar, @pCreateDate,      @pMasterID,       @pCreateDate);
		
		
		
		IF (@@ROWCOUNT = 0)
		BEGIN
			ROLLBACK TRAN;
			SELECT -3;
			RETURN;
		END
		
		
		
		INSERT INTO GuildMembers
															(GuildID, MemberID,   Rank, Corp)
								VALUES
															(@pID,    @pMasterID, 0,    0);
		
		
		
		IF (@@ROWCOUNT = 0)
		BEGIN
			ROLLBACK TRAN;
			SELECT -4;
			RETURN;
		END
		
		
		SELECT 0;
		
		
	COMMIT TRAN
	
	
	
END
GO


-- ----------------------------
-- Procedure structure for Guild_Save
-- ----------------------------
IF EXISTS (SELECT * FROM sys.all_objects WHERE object_id = OBJECT_ID(N'[dbo].[Guild_Save]') AND type IN ('P', 'PC', 'RF', 'X'))
	DROP PROCEDURE[dbo].[Guild_Save]
GO

CREATE PROCEDURE [dbo].[Guild_Save]
	
	@pID INT,
	
	@pName NVARCHAR(16),
	@pPassword VARBINARY(MAX),
	
	@pAllowGuildWar BIT,
	
	@pMessage NVARCHAR(512),
	@pMessageCreateDate DATETIME,
	@pMessageCreaterID INT
	
AS
BEGIN
	
	UPDATE Guilds SET
											Name								= @pName,
											Password						= @pPassword,
											
											AllowGuildWar				= @pAllowGuildWar,
											
											Message							= @pMessage,
											MessageCreateDate		= @pMessageCreateDate,
											MessageCreaterID		= @pMessageCreaterID
								WHERE
											ID									= @pID;
	
END
GO


-- ----------------------------
-- Procedure structure for Guild_SaveMoney
-- ----------------------------
IF EXISTS (SELECT * FROM sys.all_objects WHERE object_id = OBJECT_ID(N'[dbo].[Guild_SaveMoney]') AND type IN ('P', 'PC', 'RF', 'X'))
	DROP PROCEDURE[dbo].[Guild_SaveMoney]
GO

CREATE PROCEDURE [dbo].[Guild_SaveMoney]
	
	@pGuildID INT,
	
	
	@pMoney BIGINT
	
AS
BEGIN
	
	
	UPDATE Guilds SET Money = @pMoney WHERE ID = @pGuildID;
	
	
END
GO


-- ----------------------------
-- Procedure structure for GuildMember_Insert
-- ----------------------------
IF EXISTS (SELECT * FROM sys.all_objects WHERE object_id = OBJECT_ID(N'[dbo].[GuildMember_Insert]') AND type IN ('P', 'PC', 'RF', 'X'))
	DROP PROCEDURE[dbo].[GuildMember_Insert]
GO

CREATE PROCEDURE [dbo].[GuildMember_Insert]
	
	@pGuildID INT,
	@pMemberID INT,
	
	@pRank TINYINT,
	@pCorp SMALLINT = 0
	
AS
BEGIN
	
	
	INSERT INTO GuildMembers
														(GuildID,   MemberID,   Rank,   Corp)
							VALUES
														(@pGuildID, @pMemberID, @pRank, @pCorp);
	
	
END
GO


-- ----------------------------
-- Procedure structure for Skill_Insert
-- ----------------------------
IF EXISTS (SELECT * FROM sys.all_objects WHERE object_id = OBJECT_ID(N'[dbo].[Skill_Insert]') AND type IN ('P', 'PC', 'RF', 'X'))
	DROP PROCEDURE[dbo].[Skill_Insert]
GO

CREATE PROCEDURE [dbo].[Skill_Insert]
	
	@pOwnerID INT,
	@pSkillID SMALLINT,
	@pIsPassive BIT,
	@pUpgrades VARBINARY(4),
	
	@pID BIGINT OUTPUT
	
AS
BEGIN
	
	BEGIN TRAN
		
		DECLARE @pTries INT = 0;
		SET @pID = CAST(CRYPT_GEN_RANDOM(8) AS BIGINT);

		WHILE EXISTS (SELECT ID FROM Skills WHERE ID = @pID)
		BEGIN
			SET @pID = CAST(CRYPT_GEN_RANDOM(8) AS BIGINT);
			
			SET @pTries = (@pTries + 1);
			IF (@pTries >= 25)
			BEGIN
				ROLLBACK TRAN;
				SELECT -1;
				RETURN;
			END
		END
		
		
		INSERT INTO Skills
												(ID,   OwnerID,   SkillID,   IsPassive,   Upgrades)
								VALUES
												(@pID, @pOwnerID, @pSkillID, @pIsPassive, @pUpgrades);
		
		
		IF (@@ROWCOUNT = 0)
		BEGIN
			ROLLBACK TRAN;
			SELECT -2;
			RETURN;
		END
		
		
		SELECT 0;
		
		
	COMMIT TRAN
	
	
END
GO


-- ----------------------------
-- Procedure structure for Skill_Update
-- ----------------------------
IF EXISTS (SELECT * FROM sys.all_objects WHERE object_id = OBJECT_ID(N'[dbo].[Skill_Update]') AND type IN ('P', 'PC', 'RF', 'X'))
	DROP PROCEDURE[dbo].[Skill_Update]
GO

CREATE PROCEDURE [dbo].[Skill_Update]
	
	@pID BIGINT,
	
	@pUpgrades VARBINARY(4)
	
AS
BEGIN
	
	UPDATE Skills SET
											Upgrades				= @pUpgrades
								WHERE
											ID							= @pID;
	
END
GO


-- ----------------------------
-- Procedure structure for Title_Insert
-- ----------------------------
IF EXISTS (SELECT * FROM sys.all_objects WHERE object_id = OBJECT_ID(N'[dbo].[Title_Insert]') AND type IN ('P', 'PC', 'RF', 'X'))
	DROP PROCEDURE[dbo].[Title_Insert]
GO

CREATE PROCEDURE [dbo].[Title_Insert]
	
	@pOwnerID INT,
	@pTitleType INT,
	@pTitleLevel TINYINT,
	@pRegisterDate DATETIME,
	@pData BIGINT,
	
	@pID BIGINT OUTPUT
	
AS
BEGIN
	
	
	BEGIN TRAN
		
		DECLARE @pTries INT = 0;
		SET @pID = CAST(CRYPT_GEN_RANDOM(8) AS BIGINT);

		WHILE EXISTS (SELECT ID FROM Titles WHERE ID = @pID)
		BEGIN
			SET @pID = CAST(CRYPT_GEN_RANDOM(8) AS BIGINT);
			
			SET @pTries = (@pTries + 1);
			IF (@pTries >= 25)
			BEGIN
				ROLLBACK TRAN;
				SELECT -1;
				RETURN;
			END
		END
		
		
		INSERT INTO Titles
												(ID,   OwnerID,   TitleType,   TitleLevel,   RegisterDate,   Data)
								VALUES
												(@pID, @pOwnerID, @pTitleType, @pTitleLevel, @pRegisterDate, @pData);
		
		
		IF (@@ROWCOUNT = 0)
		BEGIN
			ROLLBACK TRAN;
			SELECT -2;
			RETURN;
		END
		
		
		SELECT 0;
		
		
	COMMIT TRAN
	
	
END
GO


-- ----------------------------
-- Procedure structure for Title_Save
-- ----------------------------
IF EXISTS (SELECT * FROM sys.all_objects WHERE object_id = OBJECT_ID(N'[dbo].[Title_Save]') AND type IN ('P', 'PC', 'RF', 'X'))
	DROP PROCEDURE[dbo].[Title_Save]
GO

CREATE PROCEDURE [dbo].[Title_Save]
	
	@pID BIGINT,
	
	@pIsActive BIT,
	@pData BIGINT
	
AS
BEGIN
	
	UPDATE Titles SET
										IsActive				= @pIsActive,
										Data						= @pData
								WHERE
										ID							= @pID;
	
END
GO


-- ----------------------------
-- Indexes structure for table BlockList
-- ----------------------------
CREATE NONCLUSTERED INDEX [INX_BlockList]
ON [dbo].[BlockList] (
  [OwnerID] ASC
)
GO


-- ----------------------------
-- Primary Key structure for table BlockList
-- ----------------------------
ALTER TABLE [dbo].[BlockList] ADD CONSTRAINT [PK_BlockList] PRIMARY KEY CLUSTERED ([OwnerID])
WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON)  
ON [PRIMARY]
GO


-- ----------------------------
-- Indexes structure for table Buffs
-- ----------------------------
CREATE UNIQUE NONCLUSTERED INDEX [INX_Buffs_ID]
ON [dbo].[Buffs] (
  [ID] ASC
)
GO

CREATE NONCLUSTERED INDEX [INX_Buffs_OwnerID]
ON [dbo].[Buffs] (
  [OwnerID] ASC
)
GO


-- ----------------------------
-- Uniques structure for table Buffs
-- ----------------------------
ALTER TABLE [dbo].[Buffs] ADD CONSTRAINT [UQ__Buffs__3214EC26135451A9] UNIQUE NONCLUSTERED ([ID] ASC)
WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON)  
ON [PRIMARY]
GO

ALTER TABLE [dbo].[Buffs] ADD CONSTRAINT [UQ__Buffs__3214EC2649C3F6B7] UNIQUE NONCLUSTERED ([ID] ASC)
WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON)  
ON [PRIMARY]
GO

ALTER TABLE [dbo].[Buffs] ADD CONSTRAINT [UQ__Buffs__3214EC268AD69F2B] UNIQUE NONCLUSTERED ([ID] ASC)
WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON)  
ON [PRIMARY]
GO


-- ----------------------------
-- Primary Key structure for table Buffs
-- ----------------------------
ALTER TABLE [dbo].[Buffs] ADD CONSTRAINT [PK__Buffs__3214EC2746E78A0C] PRIMARY KEY CLUSTERED ([ID])
WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON)  
ON [PRIMARY]
GO


-- ----------------------------
-- Primary Key structure for table Character_Options
-- ----------------------------
ALTER TABLE [dbo].[Character_Options] ADD CONSTRAINT [PK__Characte__3214EC2701142BA1] PRIMARY KEY CLUSTERED ([ID])
WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON)  
ON [PRIMARY]
GO


-- ----------------------------
-- Indexes structure for table Characters
-- ----------------------------
CREATE UNIQUE NONCLUSTERED INDEX [INX_Characters]
ON [dbo].[Characters] (
  [ID] ASC,
  [Name] ASC
)
GO

CREATE NONCLUSTERED INDEX [INX_Characters_AccountID]
ON [dbo].[Characters] (
  [AccountID] ASC
)
GO


-- ----------------------------
-- Uniques structure for table Characters
-- ----------------------------
ALTER TABLE [dbo].[Characters] ADD CONSTRAINT [UQ__Characte__5523B46941B02456] UNIQUE NONCLUSTERED ([ID] ASC, [Name] ASC)
WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON)  
ON [PRIMARY]
GO

ALTER TABLE [dbo].[Characters] ADD CONSTRAINT [UQ__Characte__5523B4694F7CD00D] UNIQUE NONCLUSTERED ([ID] ASC, [Name] ASC)
WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON)  
ON [PRIMARY]
GO

ALTER TABLE [dbo].[Characters] ADD CONSTRAINT [UQ__Characte__5523B469805A0E4E] UNIQUE NONCLUSTERED ([ID] ASC, [Name] ASC)
WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON)  
ON [PRIMARY]
GO


-- ----------------------------
-- Primary Key structure for table Characters
-- ----------------------------
ALTER TABLE [dbo].[Characters] ADD CONSTRAINT [PK_Characters] PRIMARY KEY CLUSTERED ([ID])
WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON)  
ON [PRIMARY]
GO


-- ----------------------------
-- Primary Key structure for table Friends
-- ----------------------------
ALTER TABLE [dbo].[Friends] ADD CONSTRAINT [PK_Friends2] PRIMARY KEY CLUSTERED ([OwnerID])
WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON)  
ON [PRIMARY]
GO


-- ----------------------------
-- Indexes structure for table GoldSpammer
-- ----------------------------
CREATE NONCLUSTERED INDEX [INX_GoldSpammer]
ON [dbo].[GoldSpammer] (
  [ReporterID] ASC,
  [ReporterIP] ASC,
  [SpammerID] ASC,
  [SpammerIP] ASC
)
GO


-- ----------------------------
-- Primary Key structure for table GoldSpammer
-- ----------------------------
ALTER TABLE [dbo].[GoldSpammer] ADD CONSTRAINT [PK_GoldSpammer] PRIMARY KEY CLUSTERED ([ReporterID])
WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON)  
ON [PRIMARY]
GO


-- ----------------------------
-- Indexes structure for table GroupMembers
-- ----------------------------
CREATE NONCLUSTERED INDEX [INX_GroupMembers]
ON [dbo].[GroupMembers] (
  [GroupID] ASC,
  [MemberID] ASC
)
GO


-- ----------------------------
-- Primary Key structure for table GroupMembers
-- ----------------------------
ALTER TABLE [dbo].[GroupMembers] ADD CONSTRAINT [PK_GroupMembers] PRIMARY KEY CLUSTERED ([MemberID])
WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON)  
ON [PRIMARY]
GO


-- ----------------------------
-- Indexes structure for table Groups
-- ----------------------------
CREATE UNIQUE NONCLUSTERED INDEX [INX_Groups_ID]
ON [dbo].[Groups] (
  [ID] ASC
)
GO


-- ----------------------------
-- Uniques structure for table Groups
-- ----------------------------
ALTER TABLE [dbo].[Groups] ADD CONSTRAINT [UQ__Groups__3214EC2602B7A14B] UNIQUE NONCLUSTERED ([ID] ASC)
WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON)  
ON [PRIMARY]
GO

ALTER TABLE [dbo].[Groups] ADD CONSTRAINT [UQ__Groups__3214EC265535A963] UNIQUE NONCLUSTERED ([ID] ASC)
WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON)  
ON [PRIMARY]
GO

ALTER TABLE [dbo].[Groups] ADD CONSTRAINT [UQ__Groups__3214EC26B9636BB1] UNIQUE NONCLUSTERED ([ID] ASC)
WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON)  
ON [PRIMARY]
GO


-- ----------------------------
-- Primary Key structure for table Groups
-- ----------------------------
ALTER TABLE [dbo].[Groups] ADD CONSTRAINT [PK__Groups__3214EC2752593CB8] PRIMARY KEY CLUSTERED ([ID])
WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON)  
ON [PRIMARY]
GO


-- ----------------------------
-- Primary Key structure for table GuildMembers
-- ----------------------------
ALTER TABLE [dbo].[GuildMembers] ADD CONSTRAINT [PK_GuildMembers_1] PRIMARY KEY CLUSTERED ([MemberID])
WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON)  
ON [PRIMARY]
GO


-- ----------------------------
-- Indexes structure for table Guilds
-- ----------------------------
CREATE UNIQUE NONCLUSTERED INDEX [INX_Guilds]
ON [dbo].[Guilds] (
  [ID] ASC,
  [Name] ASC
)
GO


-- ----------------------------
-- Uniques structure for table Guilds
-- ----------------------------
ALTER TABLE [dbo].[Guilds] ADD CONSTRAINT [UQ__Guilds__5523B4695AEE82B9] UNIQUE NONCLUSTERED ([ID] ASC, [Name] ASC)
WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON)  
ON [PRIMARY]
GO

ALTER TABLE [dbo].[Guilds] ADD CONSTRAINT [UQ__Guilds__5523B4698B59AB27] UNIQUE NONCLUSTERED ([ID] ASC, [Name] ASC)
WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON)  
ON [PRIMARY]
GO

ALTER TABLE [dbo].[Guilds] ADD CONSTRAINT [UQ__Guilds__5523B469B1AED8AD] UNIQUE NONCLUSTERED ([ID] ASC, [Name] ASC)
WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON)  
ON [PRIMARY]
GO


-- ----------------------------
-- Primary Key structure for table Guilds
-- ----------------------------
ALTER TABLE [dbo].[Guilds] ADD CONSTRAINT [PK_Guilds] PRIMARY KEY CLUSTERED ([ID])
WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON)  
ON [PRIMARY]
GO


-- ----------------------------
-- Indexes structure for table ItemOptions
-- ----------------------------
CREATE NONCLUSTERED INDEX [INX_ItemOptions]
ON [dbo].[ItemOptions] (
  [ItemKey] ASC
)
GO


-- ----------------------------
-- Primary Key structure for table ItemOptions
-- ----------------------------
ALTER TABLE [dbo].[ItemOptions] ADD CONSTRAINT [PK_ItemOptions] PRIMARY KEY CLUSTERED ([ItemKey])
WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON)  
ON [PRIMARY]
GO


-- ----------------------------
-- Indexes structure for table Items
-- ----------------------------
CREATE UNIQUE NONCLUSTERED INDEX [INX_Items_ID]
ON [dbo].[Items] (
  [ItemKey] ASC
)
GO


-- ----------------------------
-- Uniques structure for table Items
-- ----------------------------
ALTER TABLE [dbo].[Items] ADD CONSTRAINT [UQ__Items__3214EC2660A75C0F] UNIQUE NONCLUSTERED ([ItemKey] ASC)
WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON)  
ON [PRIMARY]
GO


-- ----------------------------
-- Primary Key structure for table Items
-- ----------------------------
ALTER TABLE [dbo].[Items] ADD CONSTRAINT [PK__Items__3214EC275DCAEF64] PRIMARY KEY CLUSTERED ([ItemKey])
WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON)  
ON [PRIMARY]
GO


-- ----------------------------
-- Indexes structure for table Skills
-- ----------------------------
CREATE UNIQUE NONCLUSTERED INDEX [INX_Skills_ID]
ON [dbo].[Skills] (
  [ID] ASC
)
GO

CREATE NONCLUSTERED INDEX [INX_Skills_OwnerID]
ON [dbo].[Skills] (
  [OwnerID] ASC
)
GO


-- ----------------------------
-- Uniques structure for table Skills
-- ----------------------------
ALTER TABLE [dbo].[Skills] ADD CONSTRAINT [UQ__Skills__3214EC2666603565] UNIQUE NONCLUSTERED ([ID] ASC)
WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON)  
ON [PRIMARY]
GO

ALTER TABLE [dbo].[Skills] ADD CONSTRAINT [UQ__Skills__3214EC26A4CCC487] UNIQUE NONCLUSTERED ([ID] ASC)
WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON)  
ON [PRIMARY]
GO

ALTER TABLE [dbo].[Skills] ADD CONSTRAINT [UQ__Skills__3214EC26CDCB911D] UNIQUE NONCLUSTERED ([ID] ASC)
WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON)  
ON [PRIMARY]
GO


-- ----------------------------
-- Primary Key structure for table Skills
-- ----------------------------
ALTER TABLE [dbo].[Skills] ADD CONSTRAINT [PK_Skills] PRIMARY KEY CLUSTERED ([ID])
WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON)  
ON [PRIMARY]
GO


-- ----------------------------
-- Indexes structure for table Titles
-- ----------------------------
CREATE UNIQUE NONCLUSTERED INDEX [INX_Titles_ID]
ON [dbo].[Titles] (
  [ID] ASC
)
GO

CREATE NONCLUSTERED INDEX [INX_Titles_OwnerID]
ON [dbo].[Titles] (
  [OwnerID] ASC
)
GO


-- ----------------------------
-- Uniques structure for table Titles
-- ----------------------------
ALTER TABLE [dbo].[Titles] ADD CONSTRAINT [UQ__Titles__3214EC265D45C030] UNIQUE NONCLUSTERED ([ID] ASC)
WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON)  
ON [PRIMARY]
GO

ALTER TABLE [dbo].[Titles] ADD CONSTRAINT [UQ__Titles__3214EC266C190EBB] UNIQUE NONCLUSTERED ([ID] ASC)
WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON)  
ON [PRIMARY]
GO

ALTER TABLE [dbo].[Titles] ADD CONSTRAINT [UQ__Titles__3214EC26AA90B20A] UNIQUE NONCLUSTERED ([ID] ASC)
WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON)  
ON [PRIMARY]
GO


-- ----------------------------
-- Primary Key structure for table Titles
-- ----------------------------
ALTER TABLE [dbo].[Titles] ADD CONSTRAINT [PK__Titles__3214EC27693CA210] PRIMARY KEY CLUSTERED ([ID])
WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON)  
ON [PRIMARY]
GO


-- ----------------------------
-- Foreign Keys structure for table GroupMembers
-- ----------------------------
ALTER TABLE [dbo].[GroupMembers] ADD CONSTRAINT [FK__GroupMemb__Group__6E01572D] FOREIGN KEY ([GroupID]) REFERENCES [dbo].[Groups] ([ID]) ON DELETE CASCADE ON UPDATE NO ACTION
GO


-- ----------------------------
-- Foreign Keys structure for table ItemOptions
-- ----------------------------
ALTER TABLE [dbo].[ItemOptions] ADD CONSTRAINT [FK__ItemOptio__ItemI__6EF57B66] FOREIGN KEY ([ItemKey]) REFERENCES [dbo].[Items] ([ItemKey]) ON DELETE CASCADE ON UPDATE NO ACTION
GO

