IF NOT EXISTS (SELECT * FROM sys.database_principals WHERE name = N'irisdb')
CREATE USER [irisdb] FOR LOGIN [irisdb] WITH DEFAULT_SCHEMA=[dbo]
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[TB_ITEM_DISJOINT]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[TB_ITEM_DISJOINT](
	[IDX] [int] IDENTITY(1,1) NOT NULL,
	[INDEX] [int] NOT NULL,
	[PRICE] [int] NOT NULL,
	[ITEM_DEFINE_INDEX1] [int] NOT NULL CONSTRAINT [DF_TB_ITEM_DISJOINT_ITEM_DEFINE_INDEX1]  DEFAULT ((0)),
	[INVENTORY_COUNT1] [smallint] NOT NULL CONSTRAINT [DF_TB_ITEM_DISJOINT_INVENTORY_COUNT1]  DEFAULT ((0)),
	[ITEM_DEFINE_INDEX2] [int] NOT NULL CONSTRAINT [DF_TB_ITEM_DISJOINT_ITEM_DEFINE_INDEX2]  DEFAULT ((0)),
	[INVENTORY_COUNT2] [smallint] NOT NULL CONSTRAINT [DF_TB_ITEM_DISJOINT_INVENTORY_COUNT2]  DEFAULT ((0)),
	[ITEM_DEFINE_INDEX3] [int] NOT NULL CONSTRAINT [DF_TB_ITEM_DISJOINT_ITEM_DEFINE_INDEX3]  DEFAULT ((0)),
	[INVENTORY_COUNT3] [smallint] NOT NULL CONSTRAINT [DF_TB_ITEM_DISJOINT_INVENTORY_COUNT3]  DEFAULT ((0)),
	[ITEM_DEFINE_INDEX4] [int] NOT NULL CONSTRAINT [DF_TB_ITEM_DISJOINT_ITEM_DEFINE_INDEX4]  DEFAULT ((0)),
	[INVENTORY_COUNT4] [smallint] NOT NULL CONSTRAINT [DF_TB_ITEM_DISJOINT_INVENTORY_COUNT4]  DEFAULT ((0)),
	[ITEM_DEFINE_INDEX5] [int] NOT NULL CONSTRAINT [DF_TB_ITEM_DISJOINT_ITEM_DEFINE_INDEX5]  DEFAULT ((0)),
	[INVENTORY_COUNT5] [smallint] NOT NULL CONSTRAINT [DF_TB_ITEM_DISJOINT_INVENTORY_COUNT5]  DEFAULT ((0)),
	[ITEM_DEFINE_INDEX6] [int] NOT NULL CONSTRAINT [DF_TB_ITEM_DISJOINT_ITEM_DEFINE_INDEX6]  DEFAULT ((0)),
	[INVENTORY_COUNT6] [smallint] NOT NULL CONSTRAINT [DF_TB_ITEM_DISJOINT_INVENTORY_COUNT6]  DEFAULT ((0)),
 CONSTRAINT [PK_TB_ITEM_DISJOINT] PRIMARY KEY CLUSTERED 
(
	[IDX] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO

IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_ID(N'[dbo].[TB_ITEM_DISJOINT]') AND name = N'IX_TB_ITEM_DISJOINT')
CREATE NONCLUSTERED INDEX [IX_TB_ITEM_DISJOINT] ON [dbo].[TB_ITEM_DISJOINT] 
(
	[INDEX] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'고유번호' ,@level0type=N'SCHEMA', @level0name=N'dbo', @level1type=N'TABLE', @level1name=N'TB_ITEM_DISJOINT', @level2type=N'COLUMN', @level2name=N'IDX'

GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'기획:분류번호' ,@level0type=N'SCHEMA', @level0name=N'dbo', @level1type=N'TABLE', @level1name=N'TB_ITEM_DISJOINT', @level2type=N'COLUMN', @level2name=N'INDEX'

GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'비용' ,@level0type=N'SCHEMA', @level0name=N'dbo', @level1type=N'TABLE', @level1name=N'TB_ITEM_DISJOINT', @level2type=N'COLUMN', @level2name=N'PRICE'

GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'아이템1(TB_ITEM_DEFINE::INDEX)' ,@level0type=N'SCHEMA', @level0name=N'dbo', @level1type=N'TABLE', @level1name=N'TB_ITEM_DISJOINT', @level2type=N'COLUMN', @level2name=N'ITEM_DEFINE_INDEX1'

GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'인벤토리 지급 수량1' ,@level0type=N'SCHEMA', @level0name=N'dbo', @level1type=N'TABLE', @level1name=N'TB_ITEM_DISJOINT', @level2type=N'COLUMN', @level2name=N'INVENTORY_COUNT1'

GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'아이템2(TB_ITEM_DEFINE::INDEX)' ,@level0type=N'SCHEMA', @level0name=N'dbo', @level1type=N'TABLE', @level1name=N'TB_ITEM_DISJOINT', @level2type=N'COLUMN', @level2name=N'ITEM_DEFINE_INDEX2'

GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'인벤토리 지급 수량2' ,@level0type=N'SCHEMA', @level0name=N'dbo', @level1type=N'TABLE', @level1name=N'TB_ITEM_DISJOINT', @level2type=N'COLUMN', @level2name=N'INVENTORY_COUNT2'

GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'아이템3(TB_ITEM_DEFINE::INDEX)' ,@level0type=N'SCHEMA', @level0name=N'dbo', @level1type=N'TABLE', @level1name=N'TB_ITEM_DISJOINT', @level2type=N'COLUMN', @level2name=N'ITEM_DEFINE_INDEX3'

GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'인벤토리 지급 수량3' ,@level0type=N'SCHEMA', @level0name=N'dbo', @level1type=N'TABLE', @level1name=N'TB_ITEM_DISJOINT', @level2type=N'COLUMN', @level2name=N'INVENTORY_COUNT3'

GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'아이템4(TB_ITEM_DEFINE::INDEX)' ,@level0type=N'SCHEMA', @level0name=N'dbo', @level1type=N'TABLE', @level1name=N'TB_ITEM_DISJOINT', @level2type=N'COLUMN', @level2name=N'ITEM_DEFINE_INDEX4'

GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'인벤토리 지급 수량4' ,@level0type=N'SCHEMA', @level0name=N'dbo', @level1type=N'TABLE', @level1name=N'TB_ITEM_DISJOINT', @level2type=N'COLUMN', @level2name=N'INVENTORY_COUNT4'

GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'아이템5(TB_ITEM_DEFINE::INDEX)' ,@level0type=N'SCHEMA', @level0name=N'dbo', @level1type=N'TABLE', @level1name=N'TB_ITEM_DISJOINT', @level2type=N'COLUMN', @level2name=N'ITEM_DEFINE_INDEX5'

GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'인벤토리 지급 수량5' ,@level0type=N'SCHEMA', @level0name=N'dbo', @level1type=N'TABLE', @level1name=N'TB_ITEM_DISJOINT', @level2type=N'COLUMN', @level2name=N'INVENTORY_COUNT5'

GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'아이템6(TB_ITEM_DEFINE::INDEX)' ,@level0type=N'SCHEMA', @level0name=N'dbo', @level1type=N'TABLE', @level1name=N'TB_ITEM_DISJOINT', @level2type=N'COLUMN', @level2name=N'ITEM_DEFINE_INDEX6'

GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'인벤토리 지급 수량6' ,@level0type=N'SCHEMA', @level0name=N'dbo', @level1type=N'TABLE', @level1name=N'TB_ITEM_DISJOINT', @level2type=N'COLUMN', @level2name=N'INVENTORY_COUNT6'

GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[GP_INIT]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'

/**********************************************************************
 *<
	FILE: GP_INIT.SQL

	DESCRIPTION:

	CREATED BY:

	HISTORY:

 *>	Copyright (c) 2008, All Rights Reserved.
 **********************************************************************/

CREATE PROCEDURE [dbo].[GP_INIT]
	(@CHANNEL_NUM				[int]			--채널번호
	,@REMOVE_COOLTIME_COUNT		[int]OUTPUT		--영향받은 행 수
	,@REMOVE_STALL_SELL_COUNT	[int]OUTPUT)	--영향받은 행 수

AS

SET NOCOUNT ON

--CLEAR TB_INVENTORY_COOLTIME
--DELETE [dbo].[TB_INVENTORY_COOLTIME]
-- WHERE [VALID_THRU]<GETDATE()
--
--SELECT @REMOVE_COOLTIME_COUNT=@@ROWCOUNT

--CLEAR TB_STALL_SELL
--UPDATE [dbo].[TB_STALL_SELL]
--   SET [APPLY]=1
-- WHERE [CHANNEL_NUM]=@CHANNEL_NUM
--   AND [APPLY]=0
--
--SELECT @REMOVE_STALL_SELL_COUNT=@@ROWCOUNT

' 
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[TB_DEFAULT_SKILL]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[TB_DEFAULT_SKILL](
	[IDX] [int] IDENTITY(1,1) NOT NULL,
	[JOB_STEP] [int] NOT NULL,
	[SKILL_IDX] [int] NOT NULL,
	[RACE_TYPE] [tinyint] NULL,
 CONSTRAINT [PK_TB_DEFAULT_SKILL] PRIMARY KEY CLUSTERED 
(
	[IDX] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[GP_ITEM_ENHANCED_INSERT]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'
/**********************************************************************
 *<
	FILE: GP_ITEM_ENHANCED_INSERT.SQL

	DESCRIPTION:

	CREATED BY: 곽철중

	HISTORY: 08/04/28 생성

 *>	Copyright (c) 2008, All Rights Reserved.
 **********************************************************************/

CREATE PROCEDURE [dbo].[GP_ITEM_ENHANCED_INSERT]
	(@INDEX					[int]			--기획:분류번호
    ,@ENHANCED1				[tinyint]		--속성1
    ,@ENHANCED2				[tinyint]		--속성2
    ,@PLUS					[varchar](MAX)	--증가값
    ,@RETVALUE				[int]OUTPUT)	--반환값

AS

SET NOCOUNT ON

DECLARE @ERRORCODE		[int]
DECLARE @ROWCOUNT		[int]

INSERT [dbo].[TB_ITEM_ENHANCED]
       ([INDEX]
       ,[ENHANCED1]
       ,[ENHANCED2]
       ,[PLUS])
VALUES
       (@INDEX
       ,@ENHANCED1
       ,@ENHANCED2
       ,@PLUS)

SELECT @ERRORCODE=@@ERROR, @ROWCOUNT=@@ROWCOUNT

IF @ERRORCODE <> 0 OR @ROWCOUNT <> 1
	BEGIN
		SET @RETVALUE = -1	--등록실패
	END
ELSE
	BEGIN
		SET @RETVALUE = 0	--등록성공
	END
' 
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[TB_ITEM_ENHANCED]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[TB_ITEM_ENHANCED](
	[IDX] [int] IDENTITY(1,1) NOT NULL,
	[INDEX] [int] NOT NULL,
	[ENHANCED1] [tinyint] NOT NULL,
	[ENHANCED2] [tinyint] NOT NULL,
	[PLUS] [varchar](260) NOT NULL,
 CONSTRAINT [PK_TB_ITEM_ENHANCED] PRIMARY KEY CLUSTERED 
(
	[IDX] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO

IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_ID(N'[dbo].[TB_ITEM_ENHANCED]') AND name = N'IX_TB_ITEM_ENHANCED')
CREATE NONCLUSTERED INDEX [IX_TB_ITEM_ENHANCED] ON [dbo].[TB_ITEM_ENHANCED] 
(
	[INDEX] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'고유번호' ,@level0type=N'SCHEMA', @level0name=N'dbo', @level1type=N'TABLE', @level1name=N'TB_ITEM_ENHANCED', @level2type=N'COLUMN', @level2name=N'IDX'

GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'인덱스/분류번호' ,@level0type=N'SCHEMA', @level0name=N'dbo', @level1type=N'TABLE', @level1name=N'TB_ITEM_ENHANCED', @level2type=N'COLUMN', @level2name=N'INDEX'

GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'속성1(0없음,1물리공격력,2마법공격력,3물리방어력,4마법방어력)' ,@level0type=N'SCHEMA', @level0name=N'dbo', @level1type=N'TABLE', @level1name=N'TB_ITEM_ENHANCED', @level2type=N'COLUMN', @level2name=N'ENHANCED1'

GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'속성2(0없음,1물리공격력,2마법공격력,3물리방어력,4마법방어력)' ,@level0type=N'SCHEMA', @level0name=N'dbo', @level1type=N'TABLE', @level1name=N'TB_ITEM_ENHANCED', @level2type=N'COLUMN', @level2name=N'ENHANCED2'

GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'증가값(1~15 단계)' ,@level0type=N'SCHEMA', @level0name=N'dbo', @level1type=N'TABLE', @level1name=N'TB_ITEM_ENHANCED', @level2type=N'COLUMN', @level2name=N'PLUS'

GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[TB_GUILD]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[TB_GUILD](
	[IDX] [int] IDENTITY(1,1) NOT NULL,
	[REGISTER_DATE] [datetime] NOT NULL CONSTRAINT [DF_TB_GUILD_REGISTER_DATE]  DEFAULT (getdate()),
	[NAME] [nvarchar](50) NOT NULL,
	[MASTER_NAME] [nvarchar](50) NOT NULL,
	[MASTER_IDX] [int] NOT NULL,
	[NOTICE] [nvarchar](100) NULL,
	[MARK_IDX] [int] NOT NULL CONSTRAINT [DF_TB_GUILD_MARK_IDX]  DEFAULT ((0)),
	[MARK] [binary](2348) NULL,
	[APPLY] [tinyint] NOT NULL CONSTRAINT [DF_TB_GUILD_APPLY]  DEFAULT ((0)),
 CONSTRAINT [PK_TB_GUILD] PRIMARY KEY CLUSTERED 
(
	[IDX] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'고유번호' ,@level0type=N'SCHEMA', @level0name=N'dbo', @level1type=N'TABLE', @level1name=N'TB_GUILD', @level2type=N'COLUMN', @level2name=N'IDX'

GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'길드명' ,@level0type=N'SCHEMA', @level0name=N'dbo', @level1type=N'TABLE', @level1name=N'TB_GUILD', @level2type=N'COLUMN', @level2name=N'NAME'

GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'길드장명' ,@level0type=N'SCHEMA', @level0name=N'dbo', @level1type=N'TABLE', @level1name=N'TB_GUILD', @level2type=N'COLUMN', @level2name=N'MASTER_NAME'

GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'길드장 인덱스' ,@level0type=N'SCHEMA', @level0name=N'dbo', @level1type=N'TABLE', @level1name=N'TB_GUILD', @level2type=N'COLUMN', @level2name=N'MASTER_IDX'

GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'길드공지' ,@level0type=N'SCHEMA', @level0name=N'dbo', @level1type=N'TABLE', @level1name=N'TB_GUILD', @level2type=N'COLUMN', @level2name=N'NOTICE'

GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'마크 인덱스' ,@level0type=N'SCHEMA', @level0name=N'dbo', @level1type=N'TABLE', @level1name=N'TB_GUILD', @level2type=N'COLUMN', @level2name=N'MARK_IDX'

GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'마크 사이즈(24*24*4)' ,@level0type=N'SCHEMA', @level0name=N'dbo', @level1type=N'TABLE', @level1name=N'TB_GUILD', @level2type=N'COLUMN', @level2name=N'MARK'

GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'삭제여부 (0: 존재, 1: 삭제)' ,@level0type=N'SCHEMA', @level0name=N'dbo', @level1type=N'TABLE', @level1name=N'TB_GUILD', @level2type=N'COLUMN', @level2name=N'APPLY'

GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[GP_CHARACTER_LIST]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'


/**********************************************************************
 *<
	FILE: GP_CHARACTER_LIST.SQL

	DESCRIPTION: 캐릭터목록 검색

	CREATED BY: 곽철중

	HISTORY:

 *>	Copyright (c) 2007, All Rights Reserved.
 **********************************************************************/

CREATE PROCEDURE [dbo].[GP_CHARACTER_LIST]
	(@USER_IDX	[int])	-- TB_MEMBER::IDX

AS

SET NOCOUNT ON

SELECT [IDX]
      ,[NAME]
      ,[LEVEL]
      ,[RACE]
      ,[GENDER]
      ,[JOB]

      ,[HAIR]
      ,[FACE]

      ,[HAT]
      ,[BODY1]
      ,[BODY2]
      ,[HAND]
      ,[FOOT]

      ,[EARRING]
      ,[NECKLACE]
      ,[BROOCH]
      ,[BRACELET]
      ,[RING]

      ,[LEFT_HAND]
      ,[LEFT_HAND_ENHANCED]
      ,[RIGHT_HAND]
      ,[RIGHT_HAND_ENHANCED]

      ,[MAP_NUM]
      ,[STAND_IDX]
  FROM [dbo].[TB_CHARACTER]
 WHERE [USER_IDX]=@USER_IDX AND [APPLY]=0
 ORDER BY [STAND_IDX]


' 
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[GP_CHARACTER_TAROT_POINT]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'
/**********************************************************************
 *<
	FILE: GP_CHARACTER_TAROT_POINT.SQL

	DESCRIPTION:

	CREATED BY:

	HISTORY:

 *>	Copyright (c) 2007, All Rights Reserved.
 **********************************************************************/

CREATE PROCEDURE [dbo].[GP_CHARACTER_TAROT_POINT]
	(@IDX	[int]
	,@POINT	[int])

AS

SET NOCOUNT ON

UPDATE [dbo].[TB_CHARACTER]
   SET [TAROT_POINT]=[TAROT_POINT]+@POINT
 WHERE [IDX]=@IDX

IF @@ERROR <> 0 OR @@ROWCOUNT <> 1
	BEGIN
		RETURN -1 --업데이트 실패
	END
' 
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[GP_CHARACTER_PVP_POINT]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'
/**********************************************************************
 *<
	FILE: GP_CHARACTER_PVP_POINT.SQL

	DESCRIPTION:

	CREATED BY:

	HISTORY:

 *>	Copyright (c) 2009, All Rights Reserved.
 **********************************************************************/

CREATE PROCEDURE [dbo].[GP_CHARACTER_PVP_POINT]
	(@IDX	[int]
	,@POINT	[int])

AS

SET NOCOUNT ON

UPDATE [dbo].[TB_CHARACTER]
   SET [PVP_POINT]=[PVP_POINT]+@POINT
 WHERE [IDX]=@IDX

IF @@ERROR <> 0 OR @@ROWCOUNT <> 1
	BEGIN
		RETURN -1 --업데이트 실패
	END
' 
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[GP_CHARACTER_LEVEL]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'








/**********************************************************************
 *<
	FILE: GP_CHARACTER_LEVEL.SQL

	DESCRIPTION: 캐릭터 Level 갱신

	CREATED BY:

	HISTORY:

 *>	Copyright (c) 2007, All Rights Reserved.
 **********************************************************************/

CREATE PROCEDURE [dbo].[GP_CHARACTER_LEVEL]
	(@IDX			[int]
	,@LEVEL			[tinyint]
	,@LEVELUPPOINT	[tinyint]
	,@RETVALUE		[int]OUTPUT)

AS

DECLARE @ERRORCODE		[int]
DECLARE @ROWCOUNT		[int]
DECLARE @SELECTLEVEL	[tinyint]

SET NOCOUNT ON

SELECT	@SELECTLEVEL = [LEVEL]
FROM	[dbo].[TB_CHARACTER]
WHERE	[IDX] = @IDX

IF @SELECTLEVEL + @LEVELUPPOINT <> @LEVEL
	BEGIN
		SET @RETVALUE = 1
		RETURN
	END

BEGIN TRAN

UPDATE	[dbo].[TB_CHARACTER]
SET		[LEVEL] = @LEVEL
WHERE	[IDX] = @IDX

SELECT @ERRORCODE = @@ERROR, @ROWCOUNT = @@ROWCOUNT

IF @ERRORCODE <> 0 OR @ROWCOUNT <> 1
	BEGIN
		SET @RETVALUE = 2
		ROLLBACK TRAN
	END
ELSE
	BEGIN
		SET @RETVALUE = 0
		COMMIT TRAN
	END
















' 
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[TB_GUILD_USER]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[TB_GUILD_USER](
	[IDX] [int] IDENTITY(1,1) NOT NULL,
	[REGISTER_DATE] [datetime] NOT NULL CONSTRAINT [DF_TB_GUILD_USER_REGISTER_DATE]  DEFAULT (getdate()),
	[INDEX] [int] NOT NULL,
	[CHARACTER_IDX] [int] NOT NULL,
	[APPLY] [tinyint] NOT NULL CONSTRAINT [DF_TB_GUILD_USER_APPLY]  DEFAULT ((0)),
 CONSTRAINT [PK_TB_GUILD_USER] PRIMARY KEY CLUSTERED 
(
	[IDX] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO

IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_ID(N'[dbo].[TB_GUILD_USER]') AND name = N'CHARACTERIDX')
CREATE NONCLUSTERED INDEX [CHARACTERIDX] ON [dbo].[TB_GUILD_USER] 
(
	[CHARACTER_IDX] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
GO

IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_ID(N'[dbo].[TB_GUILD_USER]') AND name = N'IX_TB_GUILD_USER')
CREATE NONCLUSTERED INDEX [IX_TB_GUILD_USER] ON [dbo].[TB_GUILD_USER] 
(
	[IDX] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'고유번호' ,@level0type=N'SCHEMA', @level0name=N'dbo', @level1type=N'TABLE', @level1name=N'TB_GUILD_USER', @level2type=N'COLUMN', @level2name=N'IDX'

GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'등록시간' ,@level0type=N'SCHEMA', @level0name=N'dbo', @level1type=N'TABLE', @level1name=N'TB_GUILD_USER', @level2type=N'COLUMN', @level2name=N'REGISTER_DATE'

GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'길드인덱스' ,@level0type=N'SCHEMA', @level0name=N'dbo', @level1type=N'TABLE', @level1name=N'TB_GUILD_USER', @level2type=N'COLUMN', @level2name=N'INDEX'

GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'가입한 유저인덱스' ,@level0type=N'SCHEMA', @level0name=N'dbo', @level1type=N'TABLE', @level1name=N'TB_GUILD_USER', @level2type=N'COLUMN', @level2name=N'CHARACTER_IDX'

GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'존재여부(0:존재, 1:탈퇴)' ,@level0type=N'SCHEMA', @level0name=N'dbo', @level1type=N'TABLE', @level1name=N'TB_GUILD_USER', @level2type=N'COLUMN', @level2name=N'APPLY'

GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[GP_CHARACTER_SKILLLEVEL]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'


/**********************************************************************
 *<
	FILE: GP_CHARACTER_SKILLLEVEL.SQL

	DESCRIPTION: 캐릭터 Skill Level 갱신

	CREATED BY:

	HISTORY:

 *>	Copyright (c) 2007, All Rights Reserved.
 **********************************************************************/

CREATE PROCEDURE [dbo].[GP_CHARACTER_SKILLLEVEL]
	(@IDX					[int]
	,@SKILL_LEVEL			[tinyint]
	,@SKILL_LEVEL_UP_POINT	[tinyint]
	,@SKILL_POINT			[int]
	,@SKILL_TOTALPOINT		[int]
	,@SKILL_POINT_UP_POINT	[int]
	,@RETVALUE				[int]OUTPUT)

AS

SET @RETVALUE = 0

DECLARE @SELECT_SKILL_LEVEL	[tinyint]
DECLARE @SELECT_SKILL_POINT	[int]
DECLARE @SELECT_SKILL_TOTALPOINT	[int]

SET NOCOUNT ON

SELECT	@SELECT_SKILL_LEVEL=[SKILL_LEVEL]
	   ,@SELECT_SKILL_POINT=[SKILL_POINT_REMAIN]
	   ,@SELECT_SKILL_TOTALPOINT=[SKILL_POINT_TOTAL]
FROM	[dbo].[TB_CHARACTER]
WHERE	[IDX] = @IDX

-- 스킬 레벨 비교
IF (@SELECT_SKILL_LEVEL+@SKILL_LEVEL_UP_POINT) <> @SKILL_LEVEL
	BEGIN
		SET @RETVALUE = 1
	END

-- 스킬 포인트 비교
IF (@SELECT_SKILL_POINT+@SKILL_POINT_UP_POINT) <> @SKILL_POINT
	BEGIN
		SET @RETVALUE = 2
	END

-- 스킬 포인트 비교
IF (@SELECT_SKILL_TOTALPOINT+@SKILL_POINT_UP_POINT) <> @SKILL_TOTALPOINT
	BEGIN
		SET @RETVALUE = 21
	END

BEGIN TRAN

-- 스킬 레벨 관련정보 갱신
UPDATE	[dbo].[TB_CHARACTER]
SET		[SKILL_LEVEL]=@SKILL_LEVEL
	   ,[SKILL_POINT_REMAIN]=@SKILL_POINT
	   ,[SKILL_POINT_TOTAL]=@SKILL_TOTALPOINT
WHERE	[IDX]=@IDX

IF @@ERROR <> 0 OR @@ROWCOUNT <> 1
	BEGIN
		SET @RETVALUE = 3
		ROLLBACK TRAN
		RETURN
	END
ELSE
	BEGIN
		COMMIT TRAN
	END

' 
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[TB_SHORTCUT]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[TB_SHORTCUT](
	[CHARACTER_IDX] [int] NOT NULL,
	[BINARY] [varbinary](500) NULL,
 CONSTRAINT [PK_TB_SHORTCUT_1] PRIMARY KEY CLUSTERED 
(
	[CHARACTER_IDX] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'캐릭터 고유번호' ,@level0type=N'SCHEMA', @level0name=N'dbo', @level1type=N'TABLE', @level1name=N'TB_SHORTCUT', @level2type=N'COLUMN', @level2name=N'CHARACTER_IDX'

GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'이진데이터(300BYTE)' ,@level0type=N'SCHEMA', @level0name=N'dbo', @level1type=N'TABLE', @level1name=N'TB_SHORTCUT', @level2type=N'COLUMN', @level2name=N'BINARY'

GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[TB_CHARACTER_SKILL]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[TB_CHARACTER_SKILL](
	[CHARACTER_IDX] [int] NOT NULL,
	[SKILL_IDX] [int] NOT NULL,
	[SKILL_STEP] [tinyint] NOT NULL,
	[END_COOLTIME] [datetime] NULL,
 CONSTRAINT [PK_TB_CHARACTER_SKILL_1] PRIMARY KEY CLUSTERED 
(
	[CHARACTER_IDX] ASC,
	[SKILL_IDX] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO

IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_ID(N'[dbo].[TB_CHARACTER_SKILL]') AND name = N'IX_TB_CHARACTER_SKILL')
CREATE NONCLUSTERED INDEX [IX_TB_CHARACTER_SKILL] ON [dbo].[TB_CHARACTER_SKILL] 
(
	[END_COOLTIME] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[GP_CHARACTER_EQUIP]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'

/**********************************************************************
 *<
	FILE: GP_CHARACTER_EQUIP.SQL

	DESCRIPTION: 캐릭터 착용정보 갱신

	CREATED BY:

	HISTORY:

 *>	Copyright (c) 2007, All Rights Reserved.
 **********************************************************************/

CREATE PROCEDURE [dbo].[GP_CHARACTER_EQUIP]
	(@IDX					[int]
	,@HAT					[int]
	,@BODY1					[int]
	,@BODY2					[int]
	,@HAND					[int]
	,@FOOT					[int]
	,@EARRING				[int]
	,@NECKLACE				[int]
	,@BROOCH				[int]
	,@BRACELET				[int]
	,@RING					[int]
	,@LEFT_HAND				[int]
	,@LEFT_HAND_ENHANCED	[tinyint]
	,@RIGHT_HAND			[int]
	,@RIGHT_HAND_ENHANCED	[tinyint])

AS

SET NOCOUNT ON

UPDATE [dbo].[TB_CHARACTER]
   SET [HAT]                 = @HAT
      ,[BODY1]               = @BODY1
      ,[BODY2]               = @BODY2
      ,[HAND]                = @HAND
      ,[FOOT]                = @FOOT
      ,[EARRING]             = @EARRING
      ,[NECKLACE]            = @NECKLACE
      ,[BROOCH]              = @BROOCH
      ,[BRACELET]            = @BRACELET
      ,[RING]                = @RING
      ,[LEFT_HAND]           = @LEFT_HAND
	  ,[LEFT_HAND_ENHANCED]  = @LEFT_HAND_ENHANCED
      ,[RIGHT_HAND]          = @RIGHT_HAND
      ,[RIGHT_HAND_ENHANCED] = @RIGHT_HAND_ENHANCED
 WHERE [IDX] = @IDX
' 
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[TB_CHARACTER_BLOCK]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[TB_CHARACTER_BLOCK](
	[IDX] [int] IDENTITY(1,1) NOT NULL,
	[REGISTER_DATE] [datetime] NOT NULL CONSTRAINT [DF_TB_CHARACTER_BLOCK_REGISTER_DATE]  DEFAULT (getdate()),
	[VALID_THRU] [datetime] NOT NULL,
	[BLOCK_CHARACTER_IDX] [int] NOT NULL,
	[ADMIN_CHARACTER_IDX] [int] NOT NULL,
	[APPLY] [tinyint] NOT NULL CONSTRAINT [DF_TB_CHARACTER_BLOCK_APPLY]  DEFAULT ((0)),
 CONSTRAINT [PK_TB_CHARACTER_BLOCK] PRIMARY KEY CLUSTERED 
(
	[IDX] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO

IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_ID(N'[dbo].[TB_CHARACTER_BLOCK]') AND name = N'IX_TB_CHARACTER_BLOCK')
CREATE NONCLUSTERED INDEX [IX_TB_CHARACTER_BLOCK] ON [dbo].[TB_CHARACTER_BLOCK] 
(
	[BLOCK_CHARACTER_IDX] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'고유번호' ,@level0type=N'SCHEMA', @level0name=N'dbo', @level1type=N'TABLE', @level1name=N'TB_CHARACTER_BLOCK', @level2type=N'COLUMN', @level2name=N'IDX'

GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'등록일' ,@level0type=N'SCHEMA', @level0name=N'dbo', @level1type=N'TABLE', @level1name=N'TB_CHARACTER_BLOCK', @level2type=N'COLUMN', @level2name=N'REGISTER_DATE'

GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'유효만기' ,@level0type=N'SCHEMA', @level0name=N'dbo', @level1type=N'TABLE', @level1name=N'TB_CHARACTER_BLOCK', @level2type=N'COLUMN', @level2name=N'VALID_THRU'

GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'블록 캐릭터 고유번호' ,@level0type=N'SCHEMA', @level0name=N'dbo', @level1type=N'TABLE', @level1name=N'TB_CHARACTER_BLOCK', @level2type=N'COLUMN', @level2name=N'BLOCK_CHARACTER_IDX'

GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'관리 캐릭터 고유번호' ,@level0type=N'SCHEMA', @level0name=N'dbo', @level1type=N'TABLE', @level1name=N'TB_CHARACTER_BLOCK', @level2type=N'COLUMN', @level2name=N'ADMIN_CHARACTER_IDX'

GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'적용여부(0적용중/1사용안함)' ,@level0type=N'SCHEMA', @level0name=N'dbo', @level1type=N'TABLE', @level1name=N'TB_CHARACTER_BLOCK', @level2type=N'COLUMN', @level2name=N'APPLY'

GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[TB_CHARACTER_MAKESKILL]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[TB_CHARACTER_MAKESKILL](
	[DB_IDX] [int] IDENTITY(1,1) NOT NULL,
	[CHARACTER_IDX] [int] NOT NULL,
	[MAKESKILL] [tinyint] NOT NULL,
	[RECIPE_IDX] [int] NOT NULL,
	[COOL_TIME] [datetime] NOT NULL CONSTRAINT [DF_TB_CHARACTER_MAKESKILL_COOL_TIME]  DEFAULT (getdate()),
 CONSTRAINT [PK_TB_CHARACTER_MAKESKILL] PRIMARY KEY CLUSTERED 
(
	[DB_IDX] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO

IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_ID(N'[dbo].[TB_CHARACTER_MAKESKILL]') AND name = N'IX_MAKESKILL_1')
CREATE NONCLUSTERED INDEX [IX_MAKESKILL_1] ON [dbo].[TB_CHARACTER_MAKESKILL] 
(
	[CHARACTER_IDX] ASC,
	[MAKESKILL] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
GO
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[GP_VERIFY_ITEM_ABILITY]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'
/**********************************************************************
 *<
	FILE: GP_VERIFY_ITEM_ABILITY.SQL

	DESCRIPTION:

	CREATED BY:

	HISTORY:

 *>	Copyright (c) 2006, All Rights Reserved.
 **********************************************************************/

CREATE PROCEDURE [dbo].[GP_VERIFY_ITEM_ABILITY]
	(@COUNT    [int]OUTPUT
	,@RETVALUE [int]OUTPUT)

AS

SET NOCOUNT ON

DECLARE @MAX [int]

SELECT @COUNT=COUNT(IDX)
      ,@MAX  =MAX(IDX)
  FROM [dbo].[TB_ITEM_ABILITY]
  
SET @RETVALUE = @COUNT - @MAX
' 
END
GO
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[GP_VERIFY_ITEM_LIMIT]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'
/**********************************************************************
 *<
	FILE: GP_VERIFY_ITEM_LIMIT.SQL

	DESCRIPTION:

	CREATED BY:

	HISTORY:

 *>	Copyright (c) 2006, All Rights Reserved.
 **********************************************************************/

CREATE PROCEDURE [dbo].[GP_VERIFY_ITEM_LIMIT]
	(@COUNT    [int]OUTPUT
	,@RETVALUE [int]OUTPUT)

AS

SET NOCOUNT ON

DECLARE @MAX [int]

SELECT @COUNT=COUNT(IDX)
      ,@MAX  =MAX(IDX)
  FROM [dbo].[TB_ITEM_LIMIT]
  
SET @RETVALUE = @COUNT - @MAX
' 
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[TB_SKILLLIST_PC]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[TB_SKILLLIST_PC](
	[SKILL_IDX] [int] NOT NULL,
	[NAME_IDX] [int] NOT NULL,
	[ICON_IDX] [int] NOT NULL,
	[RACE] [tinyint] NOT NULL,
	[LEARNSKILLIDX1] [int] NOT NULL,
	[LEARNSKILLSTEP1] [tinyint] NOT NULL,
	[LEARNSKILLIDX2] [int] NOT NULL,
	[LEARNSKILLSTEP2] [tinyint] NOT NULL,
	[USEEQUIPMENT] [tinyint] NOT NULL,
	[USESTATE] [tinyint] NOT NULL,
	[USEITEM] [int] NOT NULL,
	[TYPE] [int] NOT NULL,
	[ATTRIBUTETYPE] [int] NOT NULL,
	[SHOTTYPE] [int] NOT NULL,
	[BOUNDTYPE] [int] NOT NULL,
	[APPLYTYPE] [int] NOT NULL,
	[RANGETYPE] [int] NOT NULL,
	[ISGLOBALCOOLTIME] [tinyint] NOT NULL,
	[GROUPCOOLTIMEIDX] [int] NOT NULL,
	[STEPMAX] [int] NOT NULL,
 CONSTRAINT [PK_TB_SKILLLIST_PC] PRIMARY KEY CLUSTERED 
(
	[SKILL_IDX] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[GP_VERIFY_ITEM_DEFINE]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'
/**********************************************************************
 *<
	FILE: GP_VERIFY_ITEM_DEFINE.SQL

	DESCRIPTION:

	CREATED BY:

	HISTORY:

 *>	Copyright (c) 2008, All Rights Reserved.
 **********************************************************************/

CREATE PROCEDURE [dbo].[GP_VERIFY_ITEM_DEFINE]
	(@COUNT    [int]OUTPUT
	,@RETVALUE [int]OUTPUT)

AS

SET NOCOUNT ON

DECLARE @MAX [int]

SELECT @COUNT=COUNT(IDX)
      ,@MAX  =MAX(IDX)
  FROM [dbo].[TB_ITEM_DEFINE]
  
SET @RETVALUE = @COUNT - @MAX
' 
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[GP_CHARACTER_MONEY]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'

/**********************************************************************
 *<
	FILE: GP_CHARACTER_MONEY.SQL

	DESCRIPTION: 캐릭터 소지금액 갱신

	CREATED BY:

	HISTORY:

 *>	Copyright (c) 2007, All Rights Reserved.
 **********************************************************************/

CREATE PROCEDURE [dbo].[GP_CHARACTER_MONEY]
	(@IDX			[int]
	,@MONEY			[int]
	,@RETVALUE		[int]OUTPUT)

AS

DECLARE @ERRORCODE	[int]
DECLARE @ROWCOUNT	[int]

SET NOCOUNT ON

UPDATE [dbo].[TB_CHARACTER]
   SET [MONEY]=[MONEY]+@MONEY
 WHERE [IDX]=@IDX

SELECT @ERRORCODE = @@ERROR, @ROWCOUNT = @@ROWCOUNT

IF @ERRORCODE <> 0 OR @ROWCOUNT <> 1
	BEGIN
		SET @RETVALUE = -1	--업데이트 실패
	END
ELSE
	BEGIN
		SET @RETVALUE = 0	--업데이트 성공
	END
' 
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[TB_INVENTORY_COOLTIME]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[TB_INVENTORY_COOLTIME](
	[IDX] [int] IDENTITY(1,1) NOT NULL,
	[VALID_THRU] [datetime] NOT NULL,
	[CHARACTER_IDX] [int] NOT NULL,
	[ITEM_DEFINE_INDEX] [int] NOT NULL,
	[COOL_TIME1] [int] NOT NULL,
	[COOL_TIME2] [int] NOT NULL,
 CONSTRAINT [PK_TB_INVENTORY_COOLTIME] PRIMARY KEY CLUSTERED 
(
	[IDX] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO

IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_ID(N'[dbo].[TB_INVENTORY_COOLTIME]') AND name = N'IX_TB_INVENTORY_COOLTIME')
CREATE NONCLUSTERED INDEX [IX_TB_INVENTORY_COOLTIME] ON [dbo].[TB_INVENTORY_COOLTIME] 
(
	[CHARACTER_IDX] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
GO

IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_ID(N'[dbo].[TB_INVENTORY_COOLTIME]') AND name = N'IX_TB_INVENTORY_COOLTIME_1')
CREATE NONCLUSTERED INDEX [IX_TB_INVENTORY_COOLTIME_1] ON [dbo].[TB_INVENTORY_COOLTIME] 
(
	[VALID_THRU] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'고유번호' ,@level0type=N'SCHEMA', @level0name=N'dbo', @level1type=N'TABLE', @level1name=N'TB_INVENTORY_COOLTIME', @level2type=N'COLUMN', @level2name=N'IDX'

GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'유효만기' ,@level0type=N'SCHEMA', @level0name=N'dbo', @level1type=N'TABLE', @level1name=N'TB_INVENTORY_COOLTIME', @level2type=N'COLUMN', @level2name=N'VALID_THRU'

GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'캐릭터 고유번호' ,@level0type=N'SCHEMA', @level0name=N'dbo', @level1type=N'TABLE', @level1name=N'TB_INVENTORY_COOLTIME', @level2type=N'COLUMN', @level2name=N'CHARACTER_IDX'

GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'아이템 정의 인덱스' ,@level0type=N'SCHEMA', @level0name=N'dbo', @level1type=N'TABLE', @level1name=N'TB_INVENTORY_COOLTIME', @level2type=N'COLUMN', @level2name=N'ITEM_DEFINE_INDEX'

GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'쿨 타임1(지연시간)' ,@level0type=N'SCHEMA', @level0name=N'dbo', @level1type=N'TABLE', @level1name=N'TB_INVENTORY_COOLTIME', @level2type=N'COLUMN', @level2name=N'COOL_TIME1'

GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'쿨 타임2(그룹번호)' ,@level0type=N'SCHEMA', @level0name=N'dbo', @level1type=N'TABLE', @level1name=N'TB_INVENTORY_COOLTIME', @level2type=N'COLUMN', @level2name=N'COOL_TIME2'

GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[TB_ITEM_ENHANCED_RATE]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[TB_ITEM_ENHANCED_RATE](
	[IDX] [int] IDENTITY(1,1) NOT NULL,
	[INDEX] [int] NOT NULL,
	[SUCCESS] [varchar](max) NOT NULL,
	[DOWN] [varchar](max) NOT NULL,
	[DESTRUCT] [varchar](max) NOT NULL,
 CONSTRAINT [PK_TB_ITEM_ENHANCED_RATE] PRIMARY KEY CLUSTERED 
(
	[IDX] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO

IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_ID(N'[dbo].[TB_ITEM_ENHANCED_RATE]') AND name = N'IX_TB_ITEM_ENHANCED_RATE')
CREATE NONCLUSTERED INDEX [IX_TB_ITEM_ENHANCED_RATE] ON [dbo].[TB_ITEM_ENHANCED_RATE] 
(
	[INDEX] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'고유번호' ,@level0type=N'SCHEMA', @level0name=N'dbo', @level1type=N'TABLE', @level1name=N'TB_ITEM_ENHANCED_RATE', @level2type=N'COLUMN', @level2name=N'IDX'

GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'인덱스/분류번호' ,@level0type=N'SCHEMA', @level0name=N'dbo', @level1type=N'TABLE', @level1name=N'TB_ITEM_ENHANCED_RATE', @level2type=N'COLUMN', @level2name=N'INDEX'

GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'성공률(1~15단계)' ,@level0type=N'SCHEMA', @level0name=N'dbo', @level1type=N'TABLE', @level1name=N'TB_ITEM_ENHANCED_RATE', @level2type=N'COLUMN', @level2name=N'SUCCESS'

GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'감소율(1~15단계)' ,@level0type=N'SCHEMA', @level0name=N'dbo', @level1type=N'TABLE', @level1name=N'TB_ITEM_ENHANCED_RATE', @level2type=N'COLUMN', @level2name=N'DOWN'

GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'파괴율(1~15단계)' ,@level0type=N'SCHEMA', @level0name=N'dbo', @level1type=N'TABLE', @level1name=N'TB_ITEM_ENHANCED_RATE', @level2type=N'COLUMN', @level2name=N'DESTRUCT'

GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[TB_CHARACTER_NAME]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[TB_CHARACTER_NAME](
	[IDX] [int] IDENTITY(1,1) NOT NULL,
	[NAME] [nvarchar](16) NOT NULL,
	[APPLY] [tinyint] NOT NULL CONSTRAINT [DF_TB_CHARACTER_NAME_APPLY]  DEFAULT ((0)),
 CONSTRAINT [PK_TB_CHARACTER_NAME] PRIMARY KEY CLUSTERED 
(
	[IDX] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO

IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_ID(N'[dbo].[TB_CHARACTER_NAME]') AND name = N'IX_TB_CHARACTER_NAME')
CREATE NONCLUSTERED INDEX [IX_TB_CHARACTER_NAME] ON [dbo].[TB_CHARACTER_NAME] 
(
	[NAME] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'고유번호' ,@level0type=N'SCHEMA', @level0name=N'dbo', @level1type=N'TABLE', @level1name=N'TB_CHARACTER_NAME', @level2type=N'COLUMN', @level2name=N'IDX'

GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'이름' ,@level0type=N'SCHEMA', @level0name=N'dbo', @level1type=N'TABLE', @level1name=N'TB_CHARACTER_NAME', @level2type=N'COLUMN', @level2name=N'NAME'

GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'적용여부(0포함단어,1일치단어)' ,@level0type=N'SCHEMA', @level0name=N'dbo', @level1type=N'TABLE', @level1name=N'TB_CHARACTER_NAME', @level2type=N'COLUMN', @level2name=N'APPLY'

GO
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[GP_VERIFY_ITEM_ENHANCED]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'
/**********************************************************************
 *<
	FILE: GP_VERIFY_ITEM_ENHANCED.SQL

	DESCRIPTION:

	CREATED BY:

	HISTORY:

 *>	Copyright (c) 2008, All Rights Reserved.
 **********************************************************************/

CREATE PROCEDURE [dbo].[GP_VERIFY_ITEM_ENHANCED]
	(@COUNT    [int]OUTPUT
	,@RETVALUE [int]OUTPUT)

AS

SET NOCOUNT ON

DECLARE @MAX [int]

SELECT @COUNT=COUNT(IDX)
      ,@MAX  =MAX(IDX)
  FROM [dbo].[TB_ITEM_ENHANCED]
  
SET @RETVALUE = @COUNT - @MAX
' 
END
GO
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[GP_VERIFY_ITEM_COOLTIME2]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'
/**********************************************************************
 *<
	FILE: GP_VERIFY_ITEM_COOLTIME2.SQL

	DESCRIPTION:

	CREATED BY:

	HISTORY:

 *>	Copyright (c) 2008, All Rights Reserved.
 **********************************************************************/

CREATE PROCEDURE [dbo].[GP_VERIFY_ITEM_COOLTIME2]
	(@COUNT    [int]OUTPUT
	,@RETVALUE [int]OUTPUT)

AS

SET NOCOUNT ON

SELECT @COUNT=MAX([COOL_TIME2])
  FROM [dbo].[TB_ITEM_ABILITY]
 WHERE [COOL_TIME2] > 0

SET @RETVALUE = 0
' 
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[GP_ITEM_COOLTIME2_SELECT]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'


/**********************************************************************
 *<
	FILE: GP_ITEM_COOLTIME2_SELECT.SQL

	DESCRIPTION:

	CREATED BY:

	HISTORY:

 *>	Copyright (c) 2008, All Rights Reserved.
 **********************************************************************/

CREATE PROCEDURE [dbo].[GP_ITEM_COOLTIME2_SELECT]
	(@IDX	[int])		--고유번호

AS

SET NOCOUNT ON

SELECT (SELECT [IDX  ] FROM [IRIS_GAMEDB].[dbo].[TB_ITEM_DEFINE] WHERE [ABILITY_INDEX]=A.[INDEX]) AS ''DEFINE_IDX''
	  ,(SELECT [INDEX] FROM [IRIS_GAMEDB].[dbo].[TB_ITEM_DEFINE] WHERE [ABILITY_INDEX]=A.[INDEX]) AS ''DEFINE_INDEX''
--	  ,(SELECT [NAME ] FROM [IRIS_GAMEDB].[dbo].[TB_ITEM_DEFINE] WHERE [ABILITY_INDEX]=A.[INDEX]) AS ''DEFINE_NAME''
	  ,[COOL_TIME1]
  FROM [dbo].[TB_ITEM_ABILITY] A
 WHERE [COOL_TIME2] = @IDX


' 
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[GP_CHARACTER_FORCE]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'

/**********************************************************************
 *<
	FILE: GP_CHARACTER_FORCE.SQL

	DESCRIPTION: 캐릭터 세력 갱신

	CREATED BY:

	HISTORY:

 *>	Copyright (c) 2007, All Rights Reserved.
 **********************************************************************/

create PROCEDURE [dbo].[GP_CHARACTER_FORCE]
	(@IDX				[int]
	,@FORCE_TYPE		[tinyint]
	,@RETVALUE			[int]OUTPUT)

AS

DECLARE @ERRORCODE			[int]
DECLARE @ROWCOUNT			[int]

SET NOCOUNT ON

BEGIN TRAN

-- 스킬 레벨 관련정보 갱신
UPDATE	[dbo].[TB_CHARACTER]
SET		[FORCE_TYPE] = @FORCE_TYPE
WHERE	[IDX] = @IDX

SELECT @ERRORCODE = @@ERROR, @ROWCOUNT = @@ROWCOUNT

IF @ERRORCODE <> 0 OR @ROWCOUNT <> 1
	BEGIN
		SET @RETVALUE = 1
		ROLLBACK TRAN
		RETURN
	END
ELSE
	BEGIN
		SET @RETVALUE = 0
		COMMIT TRAN
	END





























' 
END
GO
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[GP_ITEM_ENHANCED_SELECT]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'
/**********************************************************************
 *<
	FILE: GP_ITEM_ENHANCED_SELECT.SQL

	DESCRIPTION:  TB_ITEM_ENHANCED분할 로딩.

	CREATED BY: 곽철중

	HISTORY: 08/03/27 생성

 *>	Copyright (c) 2008, All Rights Reserved.
 **********************************************************************/

CREATE PROCEDURE [dbo].[GP_ITEM_ENHANCED_SELECT]
	(@IDX	[int])		--고유번호

AS

SET NOCOUNT ON

SELECT [IDX]
      ,[INDEX]
      ,[ENHANCED1]
      ,[ENHANCED2]
      ,[PLUS]
  FROM [dbo].[TB_ITEM_ENHANCED]
 WHERE [IDX]=@IDX
' 
END
GO
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[GP_VERIFY_ITEM_CHANGE]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'
/**********************************************************************
 *<
	FILE: GP_VERIFY_ITEM_CHANGE.SQL

	DESCRIPTION:

	CREATED BY:

	HISTORY:

 *>	Copyright (c) 2008, All Rights Reserved.
 **********************************************************************/

CREATE PROCEDURE [dbo].[GP_VERIFY_ITEM_CHANGE]
	(@COUNT    [int]OUTPUT
	,@RETVALUE [int]OUTPUT)

AS

SET NOCOUNT ON

DECLARE @MAX [int]

SELECT @COUNT=COUNT(IDX)
      ,@MAX  =MAX(IDX)
  FROM [dbo].[TB_ITEM_CHANGE]
  
SET @RETVALUE = @COUNT - @MAX
' 
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[TB_FRIEND]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[TB_FRIEND](
	[IDX] [int] IDENTITY(1,1) NOT NULL,
	[REGISTER_DATE] [datetime] NOT NULL CONSTRAINT [DF_TB_FRIEND_REGISTER_DATE]  DEFAULT (getdate()),
	[CHARACTER_IDX1] [int] NOT NULL,
	[CHARACTER_IDX2] [int] NOT NULL,
	[STATUS] [tinyint] NOT NULL CONSTRAINT [DF_TB_FRIEND_STATUS]  DEFAULT ((0)),
	[BLOCK] [tinyint] NOT NULL CONSTRAINT [DF_TB_FRIEND_BLOCK]  DEFAULT ((0)),
	[APPLY] [tinyint] NOT NULL CONSTRAINT [DF_TB_FRIEND_APPLY]  DEFAULT ((0)),
 CONSTRAINT [PK_TB_FRIEND] PRIMARY KEY CLUSTERED 
(
	[IDX] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO

IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_ID(N'[dbo].[TB_FRIEND]') AND name = N'IX_TB_FRIEND')
CREATE NONCLUSTERED INDEX [IX_TB_FRIEND] ON [dbo].[TB_FRIEND] 
(
	[CHARACTER_IDX1] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'고유번호' ,@level0type=N'SCHEMA', @level0name=N'dbo', @level1type=N'TABLE', @level1name=N'TB_FRIEND', @level2type=N'COLUMN', @level2name=N'IDX'

GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'등록일' ,@level0type=N'SCHEMA', @level0name=N'dbo', @level1type=N'TABLE', @level1name=N'TB_FRIEND', @level2type=N'COLUMN', @level2name=N'REGISTER_DATE'

GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'캐릭터 고유번호1' ,@level0type=N'SCHEMA', @level0name=N'dbo', @level1type=N'TABLE', @level1name=N'TB_FRIEND', @level2type=N'COLUMN', @level2name=N'CHARACTER_IDX1'

GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'캐릭터 고유번호2' ,@level0type=N'SCHEMA', @level0name=N'dbo', @level1type=N'TABLE', @level1name=N'TB_FRIEND', @level2type=N'COLUMN', @level2name=N'CHARACTER_IDX2'

GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'상태(0등록완료/1등록신청)' ,@level0type=N'SCHEMA', @level0name=N'dbo', @level1type=N'TABLE', @level1name=N'TB_FRIEND', @level2type=N'COLUMN', @level2name=N'STATUS'

GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'차단여부(0차단안함/1차단함)' ,@level0type=N'SCHEMA', @level0name=N'dbo', @level1type=N'TABLE', @level1name=N'TB_FRIEND', @level2type=N'COLUMN', @level2name=N'BLOCK'

GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'적용여부(0사용중/1사용안함)' ,@level0type=N'SCHEMA', @level0name=N'dbo', @level1type=N'TABLE', @level1name=N'TB_FRIEND', @level2type=N'COLUMN', @level2name=N'APPLY'

GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[GP_CHAT_WHISPER]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N' 
/**********************************************************************
 *<
	FILE: GP_CHAT_WHISPER.SQL

	DESCRIPTION:

	CREATED BY:

	HISTORY:

 *>	Copyright (c) 2006, All Rights Reserved.
 **********************************************************************/

CREATE PROCEDURE [dbo].[GP_CHAT_WHISPER]
	(@CHARACTER_IDX		[int]OUTPUT
	,@CHARACTER_NAME	[nvarchar](16))

AS

SELECT @CHARACTER_IDX=[IDX]
  FROM [dbo].[TB_CHARACTER]
 WHERE [NAME]=@CHARACTER_NAME AND [APPLY]=0
' 
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[TB_CHARACTER_INFLUENCE]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[TB_CHARACTER_INFLUENCE](
	[IDX] [int] IDENTITY(1,1) NOT NULL,
	[CHARACTER_IDX] [int] NOT NULL,
	[INFLUENCE_IDX] [int] NOT NULL,
	[ATTACKER_IDX] [int] NOT NULL,
	[ATTACKER_TYPE] [int] NOT NULL,
	[ISREALTIME] [bit] NOT NULL,
	[RESTTIME] [int] NULL,
	[STARTTIME] [datetime] NULL,
	[ENDTIME] [datetime] NULL,
	[TIME1] [float] NOT NULL,
	[TIME2] [float] NOT NULL,
	[VALUE1] [int] NOT NULL CONSTRAINT [DF_TB_CHARACTER_INFLUENCE_VALUE1]  DEFAULT ((0)),
	[VALUE2] [int] NOT NULL CONSTRAINT [DF_TB_CHARACTER_INFLUENCE_VALUE2]  DEFAULT ((0)),
	[ATTRIBUTE_TYPE] [int] NOT NULL,
 CONSTRAINT [PK_TB_CHARACTER_INFLUENCE] PRIMARY KEY CLUSTERED 
(
	[IDX] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO

IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_ID(N'[dbo].[TB_CHARACTER_INFLUENCE]') AND name = N'IX_TB_CHARACTER_INFLUENCE')
CREATE NONCLUSTERED INDEX [IX_TB_CHARACTER_INFLUENCE] ON [dbo].[TB_CHARACTER_INFLUENCE] 
(
	[CHARACTER_IDX] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
GO
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[GP_CHARACTER_DEPOSIT]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'
/**********************************************************************
 *<
	FILE: GP_CHARACTER_DEPOSIT.SQL

	DESCRIPTION: 캐릭터 예치금액 갱신

	CREATED BY:

	HISTORY:

 *>	Copyright (c) 2007, All Rights Reserved.
 **********************************************************************/

CREATE PROCEDURE [dbo].[GP_CHARACTER_DEPOSIT]
	(@IDX			[int]
	,@DEPOSIT		[int]
	,@RETVALUE		[int]OUTPUT)

AS

DECLARE @ERRORCODE	[int]
DECLARE @ROWCOUNT	[int]

SET NOCOUNT ON

UPDATE [dbo].[TB_CHARACTER]
   SET [DEPOSIT]=[DEPOSIT]+@DEPOSIT
 WHERE [IDX]=@IDX

SELECT @ERRORCODE = @@ERROR, @ROWCOUNT = @@ROWCOUNT

IF @ERRORCODE <> 0 OR @ROWCOUNT <> 1
	BEGIN
		SET @RETVALUE = -1	--업데이트 실패
	END
ELSE
	BEGIN
		SET @RETVALUE = 0	--업데이트 성공
	END
' 
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[GP_CHARACTER_INFLUENCE_DELETE]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'


/**********************************************************************
 *<
	FILE: GP_CHARACTER_INFLUENCE_DELETE.SQL

	DESCRIPTION:

	CREATED BY: 2007/08/30

	HISTORY: PKH

 *>	Copyright (c) 2007, All Rights Reserved.
 **********************************************************************/

CREATE PROCEDURE [dbo].[GP_CHARACTER_INFLUENCE_DELETE]
(
	@CHARACTER_IDX			[int],	-- 캐릭터 인덱스
	@RETVALUE				[int]OUTPUT
)

AS

SET NOCOUNT ON

DECLARE @ERRORCODE			[int]
DECLARE @ROWCOUNT			[int]

BEGIN TRAN

DELETE FROM	[dbo].[TB_CHARACTER_INFLUENCE]
WHERE		[CHARACTER_IDX] = @CHARACTER_IDX

SELECT @ERRORCODE=@@ERROR

IF @ERRORCODE <> 0
	BEGIN
		SET @RETVALUE = 1
		ROLLBACK TRAN
	END
ELSE
	BEGIN
		SET @RETVALUE = 0
		COMMIT TRAN
	END
















' 
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[TB_FORTUNE]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[TB_FORTUNE](
	[IDX] [int] IDENTITY(1,1) NOT NULL,
	[REGISTER_DATE] [datetime] NOT NULL CONSTRAINT [DF_TB_FORTUNE_REGISTER_DATE]  DEFAULT (getdate()),
	[CHARACTER_IDX] [int] NOT NULL,
	[FORTUNE1] [datetime] NOT NULL CONSTRAINT [DF_TB_FORTUNE_FORTUNE1]  DEFAULT ((0)),
	[FORTUNE2] [datetime] NOT NULL CONSTRAINT [DF_TB_FORTUNE_FORTUNE2]  DEFAULT ((0)),
	[FORTUNE3] [datetime] NOT NULL CONSTRAINT [DF_TB_FORTUNE_FORTUNE3]  DEFAULT ((0)),
	[FORTUNE4] [datetime] NOT NULL CONSTRAINT [DF_TB_FORTUNE_FORTUNE4]  DEFAULT ((0)),
	[FORTUNE5] [datetime] NOT NULL CONSTRAINT [DF_TB_FORTUNE_FORTUNE5]  DEFAULT ((0)),
	[TODAY_WORD] [nvarchar](50) NULL,
	[TODAY_COLOR] [int] NULL,
 CONSTRAINT [PK_TB_FORTUNE] PRIMARY KEY CLUSTERED 
(
	[IDX] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'고유번호' ,@level0type=N'SCHEMA', @level0name=N'dbo', @level1type=N'TABLE', @level1name=N'TB_FORTUNE', @level2type=N'COLUMN', @level2name=N'IDX'

GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'등록일' ,@level0type=N'SCHEMA', @level0name=N'dbo', @level1type=N'TABLE', @level1name=N'TB_FORTUNE', @level2type=N'COLUMN', @level2name=N'REGISTER_DATE'

GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'캐릭터인덱스' ,@level0type=N'SCHEMA', @level0name=N'dbo', @level1type=N'TABLE', @level1name=N'TB_FORTUNE', @level2type=N'COLUMN', @level2name=N'CHARACTER_IDX'

GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'운세속성1' ,@level0type=N'SCHEMA', @level0name=N'dbo', @level1type=N'TABLE', @level1name=N'TB_FORTUNE', @level2type=N'COLUMN', @level2name=N'FORTUNE1'

GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'운세속성2' ,@level0type=N'SCHEMA', @level0name=N'dbo', @level1type=N'TABLE', @level1name=N'TB_FORTUNE', @level2type=N'COLUMN', @level2name=N'FORTUNE2'

GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'운세속성3' ,@level0type=N'SCHEMA', @level0name=N'dbo', @level1type=N'TABLE', @level1name=N'TB_FORTUNE', @level2type=N'COLUMN', @level2name=N'FORTUNE3'

GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'운세속성4' ,@level0type=N'SCHEMA', @level0name=N'dbo', @level1type=N'TABLE', @level1name=N'TB_FORTUNE', @level2type=N'COLUMN', @level2name=N'FORTUNE4'

GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'운세속성5' ,@level0type=N'SCHEMA', @level0name=N'dbo', @level1type=N'TABLE', @level1name=N'TB_FORTUNE', @level2type=N'COLUMN', @level2name=N'FORTUNE5'

GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'오늘의한마디' ,@level0type=N'SCHEMA', @level0name=N'dbo', @level1type=N'TABLE', @level1name=N'TB_FORTUNE', @level2type=N'COLUMN', @level2name=N'TODAY_WORD'

GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'오늘의한마디 색' ,@level0type=N'SCHEMA', @level0name=N'dbo', @level1type=N'TABLE', @level1name=N'TB_FORTUNE', @level2type=N'COLUMN', @level2name=N'TODAY_COLOR'

GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[GP_CHARACTER_MAKESKILL_DELETE]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'

/**********************************************************************
 *<
	FILE: GP_CHARACTER_MAKESKILL_DELETE.SQL

	DESCRIPTION:

	CREATED BY: PKH

	HISTORY:

 *>	Copyright (c) 2009, All Rights Reserved.
 **********************************************************************/

CREATE PROCEDURE [dbo].[GP_CHARACTER_MAKESKILL_DELETE]
(
	@CHARACTER_IDX	[int],			-- 캐릭터 고유번호
	@MAKESKILL		[tinyint],		-- 전문기술
	@RETVALUE		[int]OUTPUT
)

AS

SET @RETVALUE = 0

DECLARE @ERRORCODE			[int]
DECLARE @ROWCOUNT			[int]
DECLARE @MAKESKILL1			[tinyint]
DECLARE @MAKESKILL2			[tinyint]

SET NOCOUNT ON

BEGIN TRAN

SELECT		@MAKESKILL1 = [MAKE_SKILL1],
			@MAKESKILL2 = [MAKE_SKILL2]
FROM		[DBO].[TB_CHARACTER]
WHERE		[IDX] = @CHARACTER_IDX

IF @MAKESKILL1 = @MAKESKILL
	BEGIN
		UPDATE		[DBO].[TB_CHARACTER]
		SET			[MAKE_SKILL1] = 0
		WHERE		[IDX] = @CHARACTER_IDX

		SELECT		@ERRORCODE=@@ERROR, @ROWCOUNT=@@ROWCOUNT

		IF @ERRORCODE <> 0 OR @ROWCOUNT <> 1
			BEGIN
				SET @RETVALUE = 1
				ROLLBACK TRAN
				RETURN
			END
	END
ELSE IF @MAKESKILL2 = @MAKESKILL
	BEGIN
		UPDATE		[DBO].[TB_CHARACTER]
		SET			[MAKE_SKILL2] = 0
		WHERE		[IDX] = @CHARACTER_IDX

		SELECT		@ERRORCODE=@@ERROR, @ROWCOUNT=@@ROWCOUNT

		IF @ERRORCODE <> 0 OR @ROWCOUNT <> 1
			BEGIN
				SET @RETVALUE = 2
				ROLLBACK TRAN
				RETURN
			END
	END
ELSE
	BEGIN
		SET @RETVALUE = 3
		ROLLBACK TRAN
		RETURN

	END


DELETE FROM	[DBO].[TB_CHARACTER_MAKESKILL]
WHERE		CHARACTER_IDX = @CHARACTER_IDX
AND			MAKESKILL = @MAKESKILL

SELECT		@ERRORCODE=@@ERROR, @ROWCOUNT=@@ROWCOUNT

IF @ERRORCODE <> 0
	BEGIN
		SET @RETVALUE = 4
		ROLLBACK TRAN
		RETURN
	END
ELSE
	BEGIN
		COMMIT TRAN
	END





' 
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[GP_GUILDUSER_GIVEPOSITION]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'



   
 /**********************************************************************
 *<
	FILE: GP_GUILDUSER_GIVEPOSITION.SQL

	DESCRIPTION:

	CREATED BY:

	HISTORY:

 *>	Copyright (c) 2007, All Rights Reserved.
 **********************************************************************/
 
 CREATE PROCEDURE [dbo].[GP_GUILDUSER_GIVEPOSITION]
				(@IDX				[int]		-- 길드 인덱스
				,@CHARACTER_IDX		[int]		-- 대상 인덱스
				,@GUILD_POSITION	[tinyint]	-- 변경할 직위타입
				,@RETVALUE			[int]OUTPUT)		
        
AS

-- 적용행 출력 금지
SET NOCOUNT ON
DECLARE @ERRORCODE		[int]
DECLARE @ROWCOUNT		[int]
--DECLARE @GUILD_IDX		[int]
DECLARE @MASTER_IDX		[int]
DECLARE @CHARACTER_NAME	nvarchar(16)

BEGIN TRAN 

--SELECT @GUILD_IDX=[GUILD_INDEX]
--  FROM [dbo].[TB_CHARACTER]
-- WHERE [IDX]=@CHARACTER_IDX

-- 길드인덱스가 동일한지 검사
--IF @GUILD_IDX<>@IDX
--	GOTO ROLLBACK_TRAN

-- 
SELECT @MASTER_IDX=[MASTER_IDX]
  FROM [dbo].[TB_GUILD]
 WHERE [IDX]=@IDX

IF @@ERROR <> 0 OR @@ROWCOUNT <> 1
	GOTO ROLLBACK_TRAN

-- 길드장으로 변경시 기존 길드장의 직위도 변경한다
IF @GUILD_POSITION=1
	BEGIN
		SELECT @CHARACTER_NAME=[NAME]
		  FROM [dbo].[TB_CHARACTER]
		 WHERE [IDX]=@CHARACTER_IDX AND [APPLY]=0

		IF @@ERROR <> 0 OR @@ROWCOUNT <> 1
			GOTO ROLLBACK_TRAN

		-- 1. 캐릭터 정보 변경
		UPDATE [dbo].[TB_CHARACTER]
		   SET [GUILD_POSITION]=''6''			--일반 으로 변경
		 WHERE [IDX]=@MASTER_IDX
	
		IF @@ERROR <> 0 OR @@ROWCOUNT <> 1
			GOTO ROLLBACK_TRAN

		-- 2. 길드테이블 정보 변경
		UPDATE [dbo].[TB_GUILD]
		   SET [MASTER_IDX]=@CHARACTER_IDX
			 , [MASTER_NAME]=@CHARACTER_NAME
		 WHERE [IDX]=@IDX

		IF @@ERROR <> 0 OR @@ROWCOUNT <> 1
			GOTO ROLLBACK_TRAN
	END

UPDATE [dbo].[TB_CHARACTER]
   SET [GUILD_POSITION]=@GUILD_POSITION		--변경
 WHERE [IDX]=@CHARACTER_IDX

IF @@ERROR <> 0 OR @@ROWCOUNT <> 1
	GOTO ROLLBACK_TRAN

--
COMMIT TRAN
SET @RETVALUE = 0						-- 성공
RETURN
--
ROLLBACK_TRAN:
	ROLLBACK TRAN
	SET @RETVALUE = 1						-- 등록실패 :알수 없는 오류
RETURN



' 
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[TB_ITEM_TAROT]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[TB_ITEM_TAROT](
	[IDX] [int] IDENTITY(1,1) NOT NULL,
	[INDEX] [int] NOT NULL,
	[NUMBER] [int] NOT NULL,
	[LEVEL] [tinyint] NOT NULL,
	[STR_VALUE] [int] NOT NULL,
	[INV_VALUE] [int] NOT NULL,
	[PROP] [int] NOT NULL,
	[EPISODE] [int] NOT NULL,
	[STR_DESCRIPTION] [varchar](200) NULL,
	[INV_DESCRIPTION] [varchar](200) NULL,
 CONSTRAINT [PK_TB_ITEM_TAROT] PRIMARY KEY CLUSTERED 
(
	[IDX] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO

IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_ID(N'[dbo].[TB_ITEM_TAROT]') AND name = N'IX_TB_ITEM_TAROT')
CREATE NONCLUSTERED INDEX [IX_TB_ITEM_TAROT] ON [dbo].[TB_ITEM_TAROT] 
(
	[INDEX] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'고유번호' ,@level0type=N'SCHEMA', @level0name=N'dbo', @level1type=N'TABLE', @level1name=N'TB_ITEM_TAROT', @level2type=N'COLUMN', @level2name=N'IDX'

GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'인덱스/분류번호' ,@level0type=N'SCHEMA', @level0name=N'dbo', @level1type=N'TABLE', @level1name=N'TB_ITEM_TAROT', @level2type=N'COLUMN', @level2name=N'INDEX'

GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'카드번호' ,@level0type=N'SCHEMA', @level0name=N'dbo', @level1type=N'TABLE', @level1name=N'TB_ITEM_TAROT', @level2type=N'COLUMN', @level2name=N'NUMBER'

GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'희귀도(0커몬<1언커몬<2레어<3에픽)' ,@level0type=N'SCHEMA', @level0name=N'dbo', @level1type=N'TABLE', @level1name=N'TB_ITEM_TAROT', @level2type=N'COLUMN', @level2name=N'LEVEL'

GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'정뱡향수치' ,@level0type=N'SCHEMA', @level0name=N'dbo', @level1type=N'TABLE', @level1name=N'TB_ITEM_TAROT', @level2type=N'COLUMN', @level2name=N'STR_VALUE'

GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'약방향수치' ,@level0type=N'SCHEMA', @level0name=N'dbo', @level1type=N'TABLE', @level1name=N'TB_ITEM_TAROT', @level2type=N'COLUMN', @level2name=N'INV_VALUE'

GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'속성' ,@level0type=N'SCHEMA', @level0name=N'dbo', @level1type=N'TABLE', @level1name=N'TB_ITEM_TAROT', @level2type=N'COLUMN', @level2name=N'PROP'

GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'에피소드/1판 < 2판 < 3판 < 4판 ...' ,@level0type=N'SCHEMA', @level0name=N'dbo', @level1type=N'TABLE', @level1name=N'TB_ITEM_TAROT', @level2type=N'COLUMN', @level2name=N'EPISODE'

GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'정방향해석' ,@level0type=N'SCHEMA', @level0name=N'dbo', @level1type=N'TABLE', @level1name=N'TB_ITEM_TAROT', @level2type=N'COLUMN', @level2name=N'STR_DESCRIPTION'

GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'약방향해서' ,@level0type=N'SCHEMA', @level0name=N'dbo', @level1type=N'TABLE', @level1name=N'TB_ITEM_TAROT', @level2type=N'COLUMN', @level2name=N'INV_DESCRIPTION'

GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[TB_ITEM_SPREAD]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[TB_ITEM_SPREAD](
	[IDX] [int] IDENTITY(1,1) NOT NULL,
	[INDEX] [int] NOT NULL,
	[AXIS_ARRAY] [tinyint] NOT NULL,
	[XPOS] [smallint] NOT NULL,
	[YPOS] [smallint] NOT NULL,
	[DIR] [tinyint] NOT NULL CONSTRAINT [DF_TB_ITEM_SPREAD_DIR]  DEFAULT ((0)),
	[CALC] [varchar](2) NOT NULL,
	[VALUE] [int] NOT NULL,
 CONSTRAINT [PK_TB_ITEM_SPREAD] PRIMARY KEY CLUSTERED 
(
	[IDX] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO

IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_ID(N'[dbo].[TB_ITEM_SPREAD]') AND name = N'IX_TB_ITEM_SPREAD')
CREATE NONCLUSTERED INDEX [IX_TB_ITEM_SPREAD] ON [dbo].[TB_ITEM_SPREAD] 
(
	[INDEX] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'고유번호' ,@level0type=N'SCHEMA', @level0name=N'dbo', @level1type=N'TABLE', @level1name=N'TB_ITEM_SPREAD', @level2type=N'COLUMN', @level2name=N'IDX'

GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'인덱스/분류번호' ,@level0type=N'SCHEMA', @level0name=N'dbo', @level1type=N'TABLE', @level1name=N'TB_ITEM_SPREAD', @level2type=N'COLUMN', @level2name=N'INDEX'

GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'좌표 인덱스/배열값 사용 0 ~ 9' ,@level0type=N'SCHEMA', @level0name=N'dbo', @level1type=N'TABLE', @level1name=N'TB_ITEM_SPREAD', @level2type=N'COLUMN', @level2name=N'AXIS_ARRAY'

GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'X좌표' ,@level0type=N'SCHEMA', @level0name=N'dbo', @level1type=N'TABLE', @level1name=N'TB_ITEM_SPREAD', @level2type=N'COLUMN', @level2name=N'XPOS'

GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'Y좌표' ,@level0type=N'SCHEMA', @level0name=N'dbo', @level1type=N'TABLE', @level1name=N'TB_ITEM_SPREAD', @level2type=N'COLUMN', @level2name=N'YPOS'

GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'방향(0둘다/1정방향/2역방향)' ,@level0type=N'SCHEMA', @level0name=N'dbo', @level1type=N'TABLE', @level1name=N'TB_ITEM_SPREAD', @level2type=N'COLUMN', @level2name=N'DIR'

GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'계산식' ,@level0type=N'SCHEMA', @level0name=N'dbo', @level1type=N'TABLE', @level1name=N'TB_ITEM_SPREAD', @level2type=N'COLUMN', @level2name=N'CALC'

GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'계산수치(값)' ,@level0type=N'SCHEMA', @level0name=N'dbo', @level1type=N'TABLE', @level1name=N'TB_ITEM_SPREAD', @level2type=N'COLUMN', @level2name=N'VALUE'

GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[TB_ITEM_TAROT_RESULT]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[TB_ITEM_TAROT_RESULT](
	[IDX] [int] IDENTITY(1,1) NOT NULL,
	[INDEX] [int] NOT NULL,
	[MIN] [int] NOT NULL,
	[MAX] [int] NOT NULL,
	[INFLUENCE_IDX1] [int] NOT NULL,
	[INFLUENCE_IDX2] [int] NOT NULL CONSTRAINT [DF_TB_ITEM_TAROT_RESULT_SKILL2]  DEFAULT ((0)),
	[INFLUENCE_IDX3] [int] NOT NULL CONSTRAINT [DF_TB_ITEM_TAROT_RESULT_SKILL3]  DEFAULT ((0)),
 CONSTRAINT [PK_TB_ITEM_TAROT_RESULT] PRIMARY KEY CLUSTERED 
(
	[IDX] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO

IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_ID(N'[dbo].[TB_ITEM_TAROT_RESULT]') AND name = N'IX_TB_ITEM_TAROT_RESULT')
CREATE NONCLUSTERED INDEX [IX_TB_ITEM_TAROT_RESULT] ON [dbo].[TB_ITEM_TAROT_RESULT] 
(
	[INDEX] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'고유번호' ,@level0type=N'SCHEMA', @level0name=N'dbo', @level1type=N'TABLE', @level1name=N'TB_ITEM_TAROT_RESULT', @level2type=N'COLUMN', @level2name=N'IDX'

GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'인덱스' ,@level0type=N'SCHEMA', @level0name=N'dbo', @level1type=N'TABLE', @level1name=N'TB_ITEM_TAROT_RESULT', @level2type=N'COLUMN', @level2name=N'INDEX'

GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'최소값' ,@level0type=N'SCHEMA', @level0name=N'dbo', @level1type=N'TABLE', @level1name=N'TB_ITEM_TAROT_RESULT', @level2type=N'COLUMN', @level2name=N'MIN'

GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'최대값' ,@level0type=N'SCHEMA', @level0name=N'dbo', @level1type=N'TABLE', @level1name=N'TB_ITEM_TAROT_RESULT', @level2type=N'COLUMN', @level2name=N'MAX'

GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'스킬효과[스킬인덱스참조]' ,@level0type=N'SCHEMA', @level0name=N'dbo', @level1type=N'TABLE', @level1name=N'TB_ITEM_TAROT_RESULT', @level2type=N'COLUMN', @level2name=N'INFLUENCE_IDX1'

GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'스킬효과[스킬인덱스참조]' ,@level0type=N'SCHEMA', @level0name=N'dbo', @level1type=N'TABLE', @level1name=N'TB_ITEM_TAROT_RESULT', @level2type=N'COLUMN', @level2name=N'INFLUENCE_IDX2'

GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'스킬효과[스킬인덱스참조]' ,@level0type=N'SCHEMA', @level0name=N'dbo', @level1type=N'TABLE', @level1name=N'TB_ITEM_TAROT_RESULT', @level2type=N'COLUMN', @level2name=N'INFLUENCE_IDX3'

GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[TB_TITLE]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[TB_TITLE](
	[IDX] [int] IDENTITY(1,1) NOT NULL,
	[REGISTER_DATE] [datetime] NOT NULL CONSTRAINT [DF_TB_TITLE_REGISTER_DATE]  DEFAULT (getdate()),
	[CHARACTER_IDX] [int] NOT NULL,
	[TITLE_IDX] [int] NOT NULL,
	[APPLY] [tinyint] NOT NULL CONSTRAINT [DF_TB_TITLE_APPLY]  DEFAULT ((0)),
 CONSTRAINT [PK_TB_TITLE] PRIMARY KEY CLUSTERED 
(
	[IDX] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO

IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_ID(N'[dbo].[TB_TITLE]') AND name = N'IX_TB_TITLE')
CREATE NONCLUSTERED INDEX [IX_TB_TITLE] ON [dbo].[TB_TITLE] 
(
	[CHARACTER_IDX] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'인덱스' ,@level0type=N'SCHEMA', @level0name=N'dbo', @level1type=N'TABLE', @level1name=N'TB_TITLE', @level2type=N'COLUMN', @level2name=N'IDX'

GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'0 : 보유, 1: 삭제' ,@level0type=N'SCHEMA', @level0name=N'dbo', @level1type=N'TABLE', @level1name=N'TB_TITLE', @level2type=N'COLUMN', @level2name=N'APPLY'

GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[TB_NOTE]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[TB_NOTE](
	[IDX] [int] IDENTITY(1,1) NOT NULL,
	[REGISTER_DATE] [datetime] NOT NULL CONSTRAINT [DF_TB_NOTE_REGISTER_DATE]  DEFAULT (getdate()),
	[CHARACTER_IDX1] [int] NOT NULL,
	[CHARACTER_IDX2] [int] NOT NULL,
	[MESSAGE] [nvarchar](200) NOT NULL,
	[VALID_THRU] [datetime] NOT NULL,
	[APPLY] [tinyint] NOT NULL CONSTRAINT [DF_TB_NOTE_APPLY]  DEFAULT ((0)),
 CONSTRAINT [PK_TB_NOTE] PRIMARY KEY CLUSTERED 
(
	[IDX] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO

IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_ID(N'[dbo].[TB_NOTE]') AND name = N'IX_TB_NOTE')
CREATE NONCLUSTERED INDEX [IX_TB_NOTE] ON [dbo].[TB_NOTE] 
(
	[CHARACTER_IDX2] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'고유번호' ,@level0type=N'SCHEMA', @level0name=N'dbo', @level1type=N'TABLE', @level1name=N'TB_NOTE', @level2type=N'COLUMN', @level2name=N'IDX'

GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'등록일' ,@level0type=N'SCHEMA', @level0name=N'dbo', @level1type=N'TABLE', @level1name=N'TB_NOTE', @level2type=N'COLUMN', @level2name=N'REGISTER_DATE'

GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'보낸 캐릭터 (고유번호)' ,@level0type=N'SCHEMA', @level0name=N'dbo', @level1type=N'TABLE', @level1name=N'TB_NOTE', @level2type=N'COLUMN', @level2name=N'CHARACTER_IDX1'

GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'받는 캐릭터 (고유버호)' ,@level0type=N'SCHEMA', @level0name=N'dbo', @level1type=N'TABLE', @level1name=N'TB_NOTE', @level2type=N'COLUMN', @level2name=N'CHARACTER_IDX2'

GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'메시지' ,@level0type=N'SCHEMA', @level0name=N'dbo', @level1type=N'TABLE', @level1name=N'TB_NOTE', @level2type=N'COLUMN', @level2name=N'MESSAGE'

GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'유효만기' ,@level0type=N'SCHEMA', @level0name=N'dbo', @level1type=N'TABLE', @level1name=N'TB_NOTE', @level2type=N'COLUMN', @level2name=N'VALID_THRU'

GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'적용여부(0사용중/1사용안함)' ,@level0type=N'SCHEMA', @level0name=N'dbo', @level1type=N'TABLE', @level1name=N'TB_NOTE', @level2type=N'COLUMN', @level2name=N'APPLY'

GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[TB_DEFAULT_ITEMS]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[TB_DEFAULT_ITEMS](
	[IDX] [int] IDENTITY(1,1) NOT NULL,
	[REGISTER_DATE] [datetime] NOT NULL CONSTRAINT [DF_TB_DEFAULT_ITEMS_REGISTER_DATE]  DEFAULT (getdate()),
	[CHARACTER_JOB] [int] NOT NULL,
	[ITEM_DEFINE_INDEX] [int] NOT NULL,
	[INVENTORY_NUMBER] [smallint] NOT NULL,
	[INVENTORY_COUNT] [smallint] NOT NULL,
	[DESCRIPTION] [varchar](100) NULL,
	[APPLY] [tinyint] NOT NULL CONSTRAINT [DF_TB_DEFAULT_ITEMS_APPLY]  DEFAULT ((0)),
 CONSTRAINT [PK_TB_DEFAULT_ITEMS] PRIMARY KEY CLUSTERED 
(
	[IDX] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO

IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_ID(N'[dbo].[TB_DEFAULT_ITEMS]') AND name = N'IX_TB_DEFAULT_ITEMS')
CREATE NONCLUSTERED INDEX [IX_TB_DEFAULT_ITEMS] ON [dbo].[TB_DEFAULT_ITEMS] 
(
	[CHARACTER_JOB] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'고유번호' ,@level0type=N'SCHEMA', @level0name=N'dbo', @level1type=N'TABLE', @level1name=N'TB_DEFAULT_ITEMS', @level2type=N'COLUMN', @level2name=N'IDX'

GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'등록일' ,@level0type=N'SCHEMA', @level0name=N'dbo', @level1type=N'TABLE', @level1name=N'TB_DEFAULT_ITEMS', @level2type=N'COLUMN', @level2name=N'REGISTER_DATE'

GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'캐릭터 직업' ,@level0type=N'SCHEMA', @level0name=N'dbo', @level1type=N'TABLE', @level1name=N'TB_DEFAULT_ITEMS', @level2type=N'COLUMN', @level2name=N'CHARACTER_JOB'

GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'아이템 정의 인덱스(분류번호)' ,@level0type=N'SCHEMA', @level0name=N'dbo', @level1type=N'TABLE', @level1name=N'TB_DEFAULT_ITEMS', @level2type=N'COLUMN', @level2name=N'ITEM_DEFINE_INDEX'

GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'인벤토리 번호(슬롯위치)' ,@level0type=N'SCHEMA', @level0name=N'dbo', @level1type=N'TABLE', @level1name=N'TB_DEFAULT_ITEMS', @level2type=N'COLUMN', @level2name=N'INVENTORY_NUMBER'

GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'인벤토리 수량' ,@level0type=N'SCHEMA', @level0name=N'dbo', @level1type=N'TABLE', @level1name=N'TB_DEFAULT_ITEMS', @level2type=N'COLUMN', @level2name=N'INVENTORY_COUNT'

GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'설명' ,@level0type=N'SCHEMA', @level0name=N'dbo', @level1type=N'TABLE', @level1name=N'TB_DEFAULT_ITEMS', @level2type=N'COLUMN', @level2name=N'DESCRIPTION'

GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'적용여부(0사용중/1사용안함)' ,@level0type=N'SCHEMA', @level0name=N'dbo', @level1type=N'TABLE', @level1name=N'TB_DEFAULT_ITEMS', @level2type=N'COLUMN', @level2name=N'APPLY'

GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[TB_QUEST_DEFINE]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[TB_QUEST_DEFINE](
	[IDX] [int] IDENTITY(1,1) NOT NULL,
	[REGISTER_DATE] [datetime] NOT NULL CONSTRAINT [DF_TB_QUEST_DEFINE_REGISTER_DATE]  DEFAULT (getdate()),
	[INDEX] [int] NOT NULL,
	[TITLE_IDX] [int] NOT NULL,
	[TYPE] [tinyint] NOT NULL,
	[GROUPNUM] [smallint] NOT NULL,
	[GIVENPC_IDX] [int] NOT NULL,
	[TAKENPC_IDX] [int] NOT NULL,
	[REPEAT_TYPE] [tinyint] NOT NULL,
	[SELECT_COUNT] [smallint] NOT NULL,
	[COMPLETE] [bigint] NOT NULL,
	[APPLY] [tinyint] NOT NULL CONSTRAINT [DF_TB_QUEST_DEFINE_APPLY]  DEFAULT ((0)),
 CONSTRAINT [PK_TB_QUEST_DEFINE_1] PRIMARY KEY CLUSTERED 
(
	[IDX] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'등록날짜' ,@level0type=N'SCHEMA', @level0name=N'dbo', @level1type=N'TABLE', @level1name=N'TB_QUEST_DEFINE', @level2type=N'COLUMN', @level2name=N'REGISTER_DATE'

GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'타이틀 인덱스' ,@level0type=N'SCHEMA', @level0name=N'dbo', @level1type=N'TABLE', @level1name=N'TB_QUEST_DEFINE', @level2type=N'COLUMN', @level2name=N'TITLE_IDX'

GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'퀘스트분류' ,@level0type=N'SCHEMA', @level0name=N'dbo', @level1type=N'TABLE', @level1name=N'TB_QUEST_DEFINE', @level2type=N'COLUMN', @level2name=N'TYPE'

GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'퀘스트 그룹' ,@level0type=N'SCHEMA', @level0name=N'dbo', @level1type=N'TABLE', @level1name=N'TB_QUEST_DEFINE', @level2type=N'COLUMN', @level2name=N'GROUPNUM'

GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'퀘스트 제공npc' ,@level0type=N'SCHEMA', @level0name=N'dbo', @level1type=N'TABLE', @level1name=N'TB_QUEST_DEFINE', @level2type=N'COLUMN', @level2name=N'GIVENPC_IDX'

GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'퀘스트 보상 npc' ,@level0type=N'SCHEMA', @level0name=N'dbo', @level1type=N'TABLE', @level1name=N'TB_QUEST_DEFINE', @level2type=N'COLUMN', @level2name=N'TAKENPC_IDX'

GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'반복타입 (0: 없음, 1:반복)' ,@level0type=N'SCHEMA', @level0name=N'dbo', @level1type=N'TABLE', @level1name=N'TB_QUEST_DEFINE', @level2type=N'COLUMN', @level2name=N'REPEAT_TYPE'

GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'선택 보상 갯수' ,@level0type=N'SCHEMA', @level0name=N'dbo', @level1type=N'TABLE', @level1name=N'TB_QUEST_DEFINE', @level2type=N'COLUMN', @level2name=N'SELECT_COUNT'

GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'조건 충족시의 완료비트' ,@level0type=N'SCHEMA', @level0name=N'dbo', @level1type=N'TABLE', @level1name=N'TB_QUEST_DEFINE', @level2type=N'COLUMN', @level2name=N'COMPLETE'

GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'퀘스트 사용여부(0:사용1:사용안함)' ,@level0type=N'SCHEMA', @level0name=N'dbo', @level1type=N'TABLE', @level1name=N'TB_QUEST_DEFINE', @level2type=N'COLUMN', @level2name=N'APPLY'

GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[TB_CHARACTER]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[TB_CHARACTER](
	[IDX] [int] IDENTITY(10000,1) NOT NULL,
	[REGISTER_DATE] [datetime] NOT NULL CONSTRAINT [DF_TB_CHARACTER_REGISTER_DATE]  DEFAULT (getdate()),
	[LAST_DATE] [datetime] NOT NULL CONSTRAINT [DF_TB_CHARACTER_LAST_DATE]  DEFAULT (getdate()),
	[NAME] [nvarchar](16) NOT NULL,
	[LEVEL] [tinyint] NOT NULL CONSTRAINT [DF_TB_CHARACTER_LEVEL]  DEFAULT ((1)),
	[RACE] [tinyint] NOT NULL,
	[GENDER] [tinyint] NOT NULL,
	[JOB] [int] NOT NULL,
	[HAIR] [int] NOT NULL,
	[FACE] [int] NOT NULL,
	[HAT] [int] NOT NULL CONSTRAINT [DF_TB_CHARACTER_HAT]  DEFAULT ((0)),
	[BODY1] [int] NOT NULL CONSTRAINT [DF_TB_CHARACTER_BODY1]  DEFAULT ((0)),
	[BODY2] [int] NOT NULL CONSTRAINT [DF_TB_CHARACTER_BODY2]  DEFAULT ((0)),
	[HAND] [int] NOT NULL CONSTRAINT [DF_TB_CHARACTER_HAND]  DEFAULT ((0)),
	[FOOT] [int] NOT NULL CONSTRAINT [DF_TB_CHARACTER_FOOT]  DEFAULT ((0)),
	[EARRING] [int] NOT NULL CONSTRAINT [DF_TB_CHARACTER_LEFT_RING]  DEFAULT ((0)),
	[NECKLACE] [int] NOT NULL CONSTRAINT [DF_TB_CHARACTER_RIGHT_RING]  DEFAULT ((0)),
	[BROOCH] [int] NOT NULL CONSTRAINT [DF_TB_CHARACTER_NECKLACE]  DEFAULT ((0)),
	[BRACELET] [int] NOT NULL CONSTRAINT [DF_TB_CHARACTER_ARMLET]  DEFAULT ((0)),
	[RING] [int] NOT NULL CONSTRAINT [DF_TB_CHARACTER_BELT]  DEFAULT ((0)),
	[LEFT_HAND] [int] NOT NULL CONSTRAINT [DF_TB_CHARACTER_LEFT_HAND]  DEFAULT ((0)),
	[LEFT_HAND_ENHANCED] [tinyint] NOT NULL CONSTRAINT [DF_TB_CHARACTER_LEFT_HAND_ENHANCED]  DEFAULT ((0)),
	[RIGHT_HAND] [int] NOT NULL CONSTRAINT [DF_TB_CHARACTER_RIGHT_HAND]  DEFAULT ((0)),
	[RIGHT_HAND_ENHANCED] [tinyint] NOT NULL CONSTRAINT [DF_TB_CHARACTER_RIGHT_HAND_ENHANCED]  DEFAULT ((0)),
	[ACTIVE_WEAPON] [tinyint] NOT NULL CONSTRAINT [DF_TB_CHARACTER_WEAPON_ACTIVE]  DEFAULT ((0)),
	[MAP_NUM] [smallint] NOT NULL CONSTRAINT [DF_TB_CHARACTER_MAP_NUM]  DEFAULT ((1)),
	[XPOS] [float] NOT NULL CONSTRAINT [DF_TB_CHARACTER_XPOS]  DEFAULT ((0)),
	[YPOS] [float] NOT NULL CONSTRAINT [DF_TB_CHARACTER_YPOS]  DEFAULT ((0)),
	[MAX_LEVEL] [tinyint] NOT NULL CONSTRAINT [DF_TB_CHARACTER_MAX_LEVEL]  DEFAULT ((0)),
	[EXP] [int] NOT NULL CONSTRAINT [DF_TB_CHARACTER_EXP]  DEFAULT ((0)),
	[SKILL_EXP] [int] NOT NULL CONSTRAINT [DF_TB_CHARACTER_ABILITY_EXP]  DEFAULT ((0)),
	[SKILL_POINT_REMAIN] [int] NOT NULL CONSTRAINT [DF_TB_CHARACTER_REMAIN_SKILL_POINT]  DEFAULT ((0)),
	[SKILL_POINT_TOTAL] [int] NOT NULL CONSTRAINT [DF_TB_CHARACTER_SKILL_POINT_TOTAL]  DEFAULT ((0)),
	[HP] [int] NOT NULL,
	[MP] [int] NOT NULL,
	[FAME] [int] NOT NULL CONSTRAINT [DF_TB_CHARACTER_FAME]  DEFAULT ((0)),
	[RANK] [tinyint] NOT NULL CONSTRAINT [DF_TB_CHARACTER_RANK]  DEFAULT ((0)),
	[SKILL_LEVEL] [tinyint] NOT NULL CONSTRAINT [DF_TB_CHARACTER_SKILL_LEVEL]  DEFAULT ((1)),
	[TAROT_POINT] [int] NOT NULL CONSTRAINT [DF_TB_CHARACTER_TAROT_POINT]  DEFAULT ((0)),
	[MONEY] [bigint] NOT NULL CONSTRAINT [DF_TB_CHARACTER_MONEY]  DEFAULT ((0)),
	[DEPOSIT] [bigint] NOT NULL CONSTRAINT [DF_TB_CHARACTER_DEPOSIT]  DEFAULT ((0)),
	[OPTION1] [int] NOT NULL CONSTRAINT [DF_TB_CHARACTER_OPTION1]  DEFAULT (0x03FF),
	[STAND_IDX] [tinyint] NOT NULL,
	[USER_IDX] [int] NOT NULL,
	[FORCE_TYPE] [tinyint] NOT NULL CONSTRAINT [DF_TB_CHARACTER_FORCE]  DEFAULT ((0)),
	[PVP_POINT] [int] NOT NULL CONSTRAINT [DF_TB_CHARACTER_PVP_POINT]  DEFAULT ((0)),
	[FIRE_POINT] [int] NOT NULL CONSTRAINT [DF_TB_CHARACTER_FIRE_POINT]  DEFAULT ((0)),
	[FIRE_FRIENDLY] [int] NOT NULL CONSTRAINT [DF_TB_CHARACTER_FIRE_FRIENDLY]  DEFAULT ((0)),
	[WATER_POINT] [int] NOT NULL CONSTRAINT [DF_TB_CHARACTER_WATER_POINT]  DEFAULT ((0)),
	[WATER_FRIENDLY] [int] NOT NULL CONSTRAINT [DF_TB_CHARACTER_WATER_FRIENDLY]  DEFAULT ((0)),
	[WIND_POINT] [int] NOT NULL CONSTRAINT [DF_TB_CHARACTER_WIND_POINT]  DEFAULT ((0)),
	[WIND_FRIENDLY] [int] NOT NULL CONSTRAINT [DF_TB_CHARACTER_WIND_FRIENDLY]  DEFAULT ((0)),
	[EARTH_POINT] [int] NOT NULL CONSTRAINT [DF_TB_CHARACTER_EARTH_POINT]  DEFAULT ((0)),
	[EARTH_FRIENDLY] [int] NOT NULL CONSTRAINT [DF_TB_CHARACTER_EARTH_FRIENDLY]  DEFAULT ((0)),
	[TITLE_INDEX] [int] NOT NULL CONSTRAINT [DF_TB_CHARACTER_TITLE_INDEX]  DEFAULT ((0)),
	[GUILD_INDEX] [int] NOT NULL CONSTRAINT [DF_TB_CHARACTER_GUILD_INDEX]  DEFAULT ((0)),
	[GUILD_POSITION] [tinyint] NOT NULL CONSTRAINT [DF_TB_CHARACTER_GUILD_POSITION]  DEFAULT ((0)),
	[MAKE_SKILL1] [tinyint] NOT NULL CONSTRAINT [DF_TB_CHARACTER_MAKESKILL1]  DEFAULT ((0)),
	[MAKE_SKILL2] [tinyint] NOT NULL CONSTRAINT [DF_TB_CHARACTER_MAKESKILL2]  DEFAULT ((0)),
	[APPLY] [tinyint] NOT NULL CONSTRAINT [DF_TB_CHARACTER_APPLY]  DEFAULT ((0)),
 CONSTRAINT [PK_TB_CHARACTER] PRIMARY KEY CLUSTERED 
(
	[IDX] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO

SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

CREATE TRIGGER [INSERT_DEFAULT_ITEM]
   ON  [dbo].[TB_CHARACTER]
   AFTER INSERT

AS

SET NOCOUNT ON;

DECLARE @CHARACTER_IDX	[int]
 SELECT @CHARACTER_IDX=IDX FROM INSERTED

DECLARE @TAROT_NUM      [int]
       ,@MAX_TAROT_NUM  [int]

DECLARE @SPREAD_NUM     [int]
       ,@MAX_SPREAD_NUM [int]

SET @TAROT_NUM=0
SET @MAX_TAROT_NUM=21

WHILE @TAROT_NUM <= @MAX_TAROT_NUM
	BEGIN
		INSERT [dbo].[TB_INVENTORY]
			  ([CHARACTER_IDX]
			  ,[ITEM_DEFINE_INDEX]
			  ,[NUMBER]
			  ,[COUNT])
		VALUES(@CHARACTER_IDX
			  ,1010001+@TAROT_NUM
			  ,383+@TAROT_NUM
			  ,1)

		SET @TAROT_NUM = @TAROT_NUM + 1
	END

UPDATE [dbo].[TB_CHARACTER]
   SET [MONEY]=100000
 WHERE [IDX]=@CHARACTER_IDX

--SET @SPREAD_NUM=0
--SET @MAX_SPREAD_NUM=4
--
--WHILE @SPREAD_NUM <= @MAX_SPREAD_NUM
--	BEGIN
--		INSERT [dbo].[TB_INVENTORY]
--			  ([CHARACTER_IDX]
--			  ,[ITEM_DEFINE_INDEX]
--			  ,[NUMBER]
--			  ,[COUNT])
--		VALUES(@CHARACTER_IDX
--			  ,1000001+@SPREAD_NUM
--			  ,405+@SPREAD_NUM
--			  ,1)
--
--		SET @SPREAD_NUM = @SPREAD_NUM + 1
--	END
--

GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'고유번호' ,@level0type=N'SCHEMA', @level0name=N'dbo', @level1type=N'TABLE', @level1name=N'TB_CHARACTER', @level2type=N'COLUMN', @level2name=N'IDX'

GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'등록일' ,@level0type=N'SCHEMA', @level0name=N'dbo', @level1type=N'TABLE', @level1name=N'TB_CHARACTER', @level2type=N'COLUMN', @level2name=N'REGISTER_DATE'

GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'마지막 접속일' ,@level0type=N'SCHEMA', @level0name=N'dbo', @level1type=N'TABLE', @level1name=N'TB_CHARACTER', @level2type=N'COLUMN', @level2name=N'LAST_DATE'

GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'이름' ,@level0type=N'SCHEMA', @level0name=N'dbo', @level1type=N'TABLE', @level1name=N'TB_CHARACTER', @level2type=N'COLUMN', @level2name=N'NAME'

GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'레벨' ,@level0type=N'SCHEMA', @level0name=N'dbo', @level1type=N'TABLE', @level1name=N'TB_CHARACTER', @level2type=N'COLUMN', @level2name=N'LEVEL'

GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'종족' ,@level0type=N'SCHEMA', @level0name=N'dbo', @level1type=N'TABLE', @level1name=N'TB_CHARACTER', @level2type=N'COLUMN', @level2name=N'RACE'

GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'성별' ,@level0type=N'SCHEMA', @level0name=N'dbo', @level1type=N'TABLE', @level1name=N'TB_CHARACTER', @level2type=N'COLUMN', @level2name=N'GENDER'

GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'직업' ,@level0type=N'SCHEMA', @level0name=N'dbo', @level1type=N'TABLE', @level1name=N'TB_CHARACTER', @level2type=N'COLUMN', @level2name=N'JOB'

GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'헤어' ,@level0type=N'SCHEMA', @level0name=N'dbo', @level1type=N'TABLE', @level1name=N'TB_CHARACTER', @level2type=N'COLUMN', @level2name=N'HAIR'

GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'얼굴' ,@level0type=N'SCHEMA', @level0name=N'dbo', @level1type=N'TABLE', @level1name=N'TB_CHARACTER', @level2type=N'COLUMN', @level2name=N'FACE'

GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'아이템/악세사리' ,@level0type=N'SCHEMA', @level0name=N'dbo', @level1type=N'TABLE', @level1name=N'TB_CHARACTER', @level2type=N'COLUMN', @level2name=N'HAT'

GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'아이템/방어구' ,@level0type=N'SCHEMA', @level0name=N'dbo', @level1type=N'TABLE', @level1name=N'TB_CHARACTER', @level2type=N'COLUMN', @level2name=N'BODY1'

GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'아이템/방어구' ,@level0type=N'SCHEMA', @level0name=N'dbo', @level1type=N'TABLE', @level1name=N'TB_CHARACTER', @level2type=N'COLUMN', @level2name=N'BODY2'

GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'아이템/방어구' ,@level0type=N'SCHEMA', @level0name=N'dbo', @level1type=N'TABLE', @level1name=N'TB_CHARACTER', @level2type=N'COLUMN', @level2name=N'HAND'

GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'아이템/방어구' ,@level0type=N'SCHEMA', @level0name=N'dbo', @level1type=N'TABLE', @level1name=N'TB_CHARACTER', @level2type=N'COLUMN', @level2name=N'FOOT'

GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'아이템/악세사리' ,@level0type=N'SCHEMA', @level0name=N'dbo', @level1type=N'TABLE', @level1name=N'TB_CHARACTER', @level2type=N'COLUMN', @level2name=N'EARRING'

GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'아이템/악세사리' ,@level0type=N'SCHEMA', @level0name=N'dbo', @level1type=N'TABLE', @level1name=N'TB_CHARACTER', @level2type=N'COLUMN', @level2name=N'NECKLACE'

GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'아이템/악세사리' ,@level0type=N'SCHEMA', @level0name=N'dbo', @level1type=N'TABLE', @level1name=N'TB_CHARACTER', @level2type=N'COLUMN', @level2name=N'BROOCH'

GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'아이템/악세사리' ,@level0type=N'SCHEMA', @level0name=N'dbo', @level1type=N'TABLE', @level1name=N'TB_CHARACTER', @level2type=N'COLUMN', @level2name=N'BRACELET'

GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'아이템/악세사리' ,@level0type=N'SCHEMA', @level0name=N'dbo', @level1type=N'TABLE', @level1name=N'TB_CHARACTER', @level2type=N'COLUMN', @level2name=N'RING'

GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'아이템/무기' ,@level0type=N'SCHEMA', @level0name=N'dbo', @level1type=N'TABLE', @level1name=N'TB_CHARACTER', @level2type=N'COLUMN', @level2name=N'LEFT_HAND'

GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'아이템/무기' ,@level0type=N'SCHEMA', @level0name=N'dbo', @level1type=N'TABLE', @level1name=N'TB_CHARACTER', @level2type=N'COLUMN', @level2name=N'RIGHT_HAND'

GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'활성 무기정보 (0 Front, 1 Back)' ,@level0type=N'SCHEMA', @level0name=N'dbo', @level1type=N'TABLE', @level1name=N'TB_CHARACTER', @level2type=N'COLUMN', @level2name=N'ACTIVE_WEAPON'

GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'맵 번호' ,@level0type=N'SCHEMA', @level0name=N'dbo', @level1type=N'TABLE', @level1name=N'TB_CHARACTER', @level2type=N'COLUMN', @level2name=N'MAP_NUM'

GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'X 위치' ,@level0type=N'SCHEMA', @level0name=N'dbo', @level1type=N'TABLE', @level1name=N'TB_CHARACTER', @level2type=N'COLUMN', @level2name=N'XPOS'

GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'Y 위치' ,@level0type=N'SCHEMA', @level0name=N'dbo', @level1type=N'TABLE', @level1name=N'TB_CHARACTER', @level2type=N'COLUMN', @level2name=N'YPOS'

GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'최고 레벨' ,@level0type=N'SCHEMA', @level0name=N'dbo', @level1type=N'TABLE', @level1name=N'TB_CHARACTER', @level2type=N'COLUMN', @level2name=N'MAX_LEVEL'

GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'현재 경험치' ,@level0type=N'SCHEMA', @level0name=N'dbo', @level1type=N'TABLE', @level1name=N'TB_CHARACTER', @level2type=N'COLUMN', @level2name=N'EXP'

GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'현재 스킬-경험치' ,@level0type=N'SCHEMA', @level0name=N'dbo', @level1type=N'TABLE', @level1name=N'TB_CHARACTER', @level2type=N'COLUMN', @level2name=N'SKILL_EXP'

GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'스킬-잔여포인트' ,@level0type=N'SCHEMA', @level0name=N'dbo', @level1type=N'TABLE', @level1name=N'TB_CHARACTER', @level2type=N'COLUMN', @level2name=N'SKILL_POINT_REMAIN'

GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'스킬-총 획득포인트' ,@level0type=N'SCHEMA', @level0name=N'dbo', @level1type=N'TABLE', @level1name=N'TB_CHARACTER', @level2type=N'COLUMN', @level2name=N'SKILL_POINT_TOTAL'

GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'남은 생명력' ,@level0type=N'SCHEMA', @level0name=N'dbo', @level1type=N'TABLE', @level1name=N'TB_CHARACTER', @level2type=N'COLUMN', @level2name=N'HP'

GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'남은 마나' ,@level0type=N'SCHEMA', @level0name=N'dbo', @level1type=N'TABLE', @level1name=N'TB_CHARACTER', @level2type=N'COLUMN', @level2name=N'MP'

GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'명성 포인트' ,@level0type=N'SCHEMA', @level0name=N'dbo', @level1type=N'TABLE', @level1name=N'TB_CHARACTER', @level2type=N'COLUMN', @level2name=N'FAME'

GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'지위' ,@level0type=N'SCHEMA', @level0name=N'dbo', @level1type=N'TABLE', @level1name=N'TB_CHARACTER', @level2type=N'COLUMN', @level2name=N'RANK'

GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'타로 포인트' ,@level0type=N'SCHEMA', @level0name=N'dbo', @level1type=N'TABLE', @level1name=N'TB_CHARACTER', @level2type=N'COLUMN', @level2name=N'TAROT_POINT'

GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'소지금액' ,@level0type=N'SCHEMA', @level0name=N'dbo', @level1type=N'TABLE', @level1name=N'TB_CHARACTER', @level2type=N'COLUMN', @level2name=N'MONEY'

GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'예치금액' ,@level0type=N'SCHEMA', @level0name=N'dbo', @level1type=N'TABLE', @level1name=N'TB_CHARACTER', @level2type=N'COLUMN', @level2name=N'DEPOSIT'

GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'OPTION1(선택항목)' ,@level0type=N'SCHEMA', @level0name=N'dbo', @level1type=N'TABLE', @level1name=N'TB_CHARACTER', @level2type=N'COLUMN', @level2name=N'OPTION1'

GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'캐릭터 생성 위치 N/5' ,@level0type=N'SCHEMA', @level0name=N'dbo', @level1type=N'TABLE', @level1name=N'TB_CHARACTER', @level2type=N'COLUMN', @level2name=N'STAND_IDX'

GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'사용자 계정-고유번호(인덱스)' ,@level0type=N'SCHEMA', @level0name=N'dbo', @level1type=N'TABLE', @level1name=N'TB_CHARACTER', @level2type=N'COLUMN', @level2name=N'USER_IDX'

GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'현재 설정된 호칭인덱스' ,@level0type=N'SCHEMA', @level0name=N'dbo', @level1type=N'TABLE', @level1name=N'TB_CHARACTER', @level2type=N'COLUMN', @level2name=N'TITLE_INDEX'

GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'길드인덱스(0: 없음)' ,@level0type=N'SCHEMA', @level0name=N'dbo', @level1type=N'TABLE', @level1name=N'TB_CHARACTER', @level2type=N'COLUMN', @level2name=N'GUILD_INDEX'

GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'길드직위(0:길드장,1:부길장,2:장로,3:상의원,4:하의원,5:일반' ,@level0type=N'SCHEMA', @level0name=N'dbo', @level1type=N'TABLE', @level1name=N'TB_CHARACTER', @level2type=N'COLUMN', @level2name=N'GUILD_POSITION'

GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'사용여부 (0사용중/1사용안함)' ,@level0type=N'SCHEMA', @level0name=N'dbo', @level1type=N'TABLE', @level1name=N'TB_CHARACTER', @level2type=N'COLUMN', @level2name=N'APPLY'

GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[TB_ITEM_CARD_SLOT]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[TB_ITEM_CARD_SLOT](
	[IDX] [int] IDENTITY(1,1) NOT NULL,
	[INDEX] [int] NOT NULL,
	[SLOT1] [tinyint] NOT NULL,
	[SLOT2] [tinyint] NOT NULL,
	[SLOT3] [tinyint] NOT NULL,
	[SLOT4] [tinyint] NOT NULL,
	[SLOT5] [tinyint] NOT NULL,
 CONSTRAINT [PK_TB_ITEM_CARD_SLOT] PRIMARY KEY CLUSTERED 
(
	[IDX] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO

IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_ID(N'[dbo].[TB_ITEM_CARD_SLOT]') AND name = N'IX_TB_ITEM_CARD_SLOT')
CREATE NONCLUSTERED INDEX [IX_TB_ITEM_CARD_SLOT] ON [dbo].[TB_ITEM_CARD_SLOT] 
(
	[INDEX] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'고유번호' ,@level0type=N'SCHEMA', @level0name=N'dbo', @level1type=N'TABLE', @level1name=N'TB_ITEM_CARD_SLOT', @level2type=N'COLUMN', @level2name=N'IDX'

GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'인덱스/분류번호' ,@level0type=N'SCHEMA', @level0name=N'dbo', @level1type=N'TABLE', @level1name=N'TB_ITEM_CARD_SLOT', @level2type=N'COLUMN', @level2name=N'INDEX'

GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'카드슬롯1(0없음/1A형/2B형/3AB형/4O형)' ,@level0type=N'SCHEMA', @level0name=N'dbo', @level1type=N'TABLE', @level1name=N'TB_ITEM_CARD_SLOT', @level2type=N'COLUMN', @level2name=N'SLOT1'

GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'카드슬롯2(0없음/1A형/2B형/3AB형/4O형)' ,@level0type=N'SCHEMA', @level0name=N'dbo', @level1type=N'TABLE', @level1name=N'TB_ITEM_CARD_SLOT', @level2type=N'COLUMN', @level2name=N'SLOT2'

GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'카드슬롯3(0없음/1A형/2B형/3AB형/4O형)' ,@level0type=N'SCHEMA', @level0name=N'dbo', @level1type=N'TABLE', @level1name=N'TB_ITEM_CARD_SLOT', @level2type=N'COLUMN', @level2name=N'SLOT3'

GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'카드슬롯4(0없음/1A형/2B형/3AB형/4O형)' ,@level0type=N'SCHEMA', @level0name=N'dbo', @level1type=N'TABLE', @level1name=N'TB_ITEM_CARD_SLOT', @level2type=N'COLUMN', @level2name=N'SLOT4'

GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'카드슬롯5(0없음/1A형/2B형/3AB형/4O형)' ,@level0type=N'SCHEMA', @level0name=N'dbo', @level1type=N'TABLE', @level1name=N'TB_ITEM_CARD_SLOT', @level2type=N'COLUMN', @level2name=N'SLOT5'

GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[TB_ITEM_ABILITY]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[TB_ITEM_ABILITY](
	[IDX] [int] IDENTITY(1,1) NOT NULL,
	[INDEX] [int] NOT NULL,
	[DEFENSE_TYPE] [smallint] NOT NULL CONSTRAINT [DF_TB_ITEM_ABILITY_DEFENSE_TYPE]  DEFAULT ((0)),
	[RANGE_TYPE] [tinyint] NOT NULL CONSTRAINT [DF_TB_ITEM_ABILITY_RANGE_TYPE]  DEFAULT ((0)),
	[TARGET_TYPE] [tinyint] NOT NULL CONSTRAINT [DF_TB_ITEM_ABILITY_TARGET_TYPE]  DEFAULT ((0)),
	[USE_RANGE] [smallint] NOT NULL CONSTRAINT [DF_TB_ITEM_ABILITY_USE_RANGE]  DEFAULT ((0)),
	[DEFENSE_P] [smallint] NOT NULL CONSTRAINT [DF_TB_ITEM_ABILITY_DEFENSE_P]  DEFAULT ((0)),
	[DEFENSE_M] [smallint] NOT NULL CONSTRAINT [DF_TB_ITEM_ABILITY_DEFENSE_M]  DEFAULT ((0)),
	[ATTACK_RANGE] [smallint] NOT NULL CONSTRAINT [DF_TB_ITEM_ABILITY_ATTACK_RANGE]  DEFAULT ((0)),
	[ATTACK_SPEED] [smallint] NOT NULL CONSTRAINT [DF_TB_ITEM_ABILITY_ATTACK_SPEED]  DEFAULT ((0)),
	[COOL_TIME1] [int] NOT NULL CONSTRAINT [DF_TB_ITEM_ABILITY_COOL_TIME1]  DEFAULT ((0)),
	[COOL_TIME2] [int] NOT NULL CONSTRAINT [DF_TB_ITEM_ABILITY_COOL_TIME2]  DEFAULT ((0)),
	[ATTACK_P_MIN] [smallint] NOT NULL CONSTRAINT [DF_TB_ITEM_ABILITY_ATTACK_P_MIN]  DEFAULT ((0)),
	[ATTACK_P_MAX] [smallint] NOT NULL CONSTRAINT [DF_TB_ITEM_ABILITY_ATTACK_P_MAX]  DEFAULT ((0)),
	[ATTACK_M_MIN] [smallint] NOT NULL CONSTRAINT [DF_TB_ITEM_ABILITY_ATTACK_M_MIN]  DEFAULT ((0)),
	[ATTACK_M_MAX] [smallint] NOT NULL CONSTRAINT [DF_TB_ITEM_ABILITY_ATTACK_M_MAX]  DEFAULT ((0)),
	[OPT01_INDEX] [smallint] NOT NULL CONSTRAINT [DF_TB_ITEM_ABILITY_ATTACK_RATE_P]  DEFAULT ((0)),
	[OPT01_VALUE] [smallint] NOT NULL CONSTRAINT [DF_TB_ITEM_ABILITY_ATTACK_RATE_M]  DEFAULT ((0)),
	[OPT02_INDEX] [smallint] NOT NULL CONSTRAINT [DF_TB_ITEM_ABILITY_CRITICAL_P]  DEFAULT ((0)),
	[OPT02_VALUE] [smallint] NOT NULL CONSTRAINT [DF_TB_ITEM_ABILITY_CRITICAL_M]  DEFAULT ((0)),
	[OPT03_INDEX] [smallint] NOT NULL CONSTRAINT [DF_TB_ITEM_ABILITY_PLUS_POW]  DEFAULT ((0)),
	[OPT03_VALUE] [smallint] NOT NULL CONSTRAINT [DF_TB_ITEM_ABILITY_PLUS_RAP]  DEFAULT ((0)),
	[OPT04_INDEX] [smallint] NOT NULL CONSTRAINT [DF_TB_ITEM_ABILITY_PLUS_STR]  DEFAULT ((0)),
	[OPT04_VALUE] [smallint] NOT NULL CONSTRAINT [DF_TB_ITEM_ABILITY_PLUS_INT]  DEFAULT ((0)),
	[OPT05_INDEX] [smallint] NOT NULL CONSTRAINT [DF_TB_ITEM_ABILITY_PLUS_WIS]  DEFAULT ((0)),
	[OPT05_VALUE] [smallint] NOT NULL CONSTRAINT [DF_TB_ITEM_ABILITY_PLUS_DOD]  DEFAULT ((0)),
	[OPT06_INDEX] [smallint] NOT NULL CONSTRAINT [DF_TB_ITEM_ABILITY_PLUS_WEI]  DEFAULT ((0)),
	[OPT06_VALUE] [smallint] NOT NULL CONSTRAINT [DF_TB_ITEM_ABILITY_PLUS_MOVE]  DEFAULT ((0)),
	[OPT07_INDEX] [smallint] NOT NULL,
	[OPT07_VALUE] [smallint] NOT NULL CONSTRAINT [DF_TB_ITEM_ABILITY_PLUS_HP]  DEFAULT ((0)),
	[OPT08_INDEX] [smallint] NOT NULL,
	[OPT08_VALUE] [smallint] NOT NULL CONSTRAINT [DF_TB_ITEM_ABILITY_PLUS_MP]  DEFAULT ((0)),
	[OPT09_INDEX] [smallint] NOT NULL CONSTRAINT [DF_TB_ITEM_ABILITY_PLUS_ATTACK_PHYSIC]  DEFAULT ((0)),
	[OPT09_VALUE] [smallint] NOT NULL CONSTRAINT [DF_TB_ITEM_ABILITY_PLUS_ATTACK_MAGIC]  DEFAULT ((0)),
	[OPT10_INDEX] [smallint] NOT NULL CONSTRAINT [DF_TB_ITEM_ABILITY_PLUS_DEFENSE_PHYSIC]  DEFAULT ((0)),
	[OPT10_VALUE] [smallint] NOT NULL CONSTRAINT [DF_TB_ITEM_ABILITY_PLUS_DEFENSE_MAGIC]  DEFAULT ((0)),
	[INFLUENCE_IDX] [int] NOT NULL CONSTRAINT [DF_TB_ITEM_ABILITY_INFLUENCE_IDX]  DEFAULT ((0)),
 CONSTRAINT [PK_TB_ITEM_ABILITY] PRIMARY KEY CLUSTERED 
(
	[IDX] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO

IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_ID(N'[dbo].[TB_ITEM_ABILITY]') AND name = N'IX_TB_ITEM_ABILITY')
CREATE NONCLUSTERED INDEX [IX_TB_ITEM_ABILITY] ON [dbo].[TB_ITEM_ABILITY] 
(
	[INDEX] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'고유번호' ,@level0type=N'SCHEMA', @level0name=N'dbo', @level1type=N'TABLE', @level1name=N'TB_ITEM_ABILITY', @level2type=N'COLUMN', @level2name=N'IDX'

GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'인덱스/분류번호' ,@level0type=N'SCHEMA', @level0name=N'dbo', @level1type=N'TABLE', @level1name=N'TB_ITEM_ABILITY', @level2type=N'COLUMN', @level2name=N'INDEX'

GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'방어구재질' ,@level0type=N'SCHEMA', @level0name=N'dbo', @level1type=N'TABLE', @level1name=N'TB_ITEM_ABILITY', @level2type=N'COLUMN', @level2name=N'DEFENSE_TYPE'

GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'범위방식(0범위없음, 1시전자, 2타겟, 3 필드)' ,@level0type=N'SCHEMA', @level0name=N'dbo', @level1type=N'TABLE', @level1name=N'TB_ITEM_ABILITY', @level2type=N'COLUMN', @level2name=N'RANGE_TYPE'

GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'효과적용타겟(0사용불가, 1나, 2 적, 3 동료, 4 파티)' ,@level0type=N'SCHEMA', @level0name=N'dbo', @level1type=N'TABLE', @level1name=N'TB_ITEM_ABILITY', @level2type=N'COLUMN', @level2name=N'TARGET_TYPE'

GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'사용거리' ,@level0type=N'SCHEMA', @level0name=N'dbo', @level1type=N'TABLE', @level1name=N'TB_ITEM_ABILITY', @level2type=N'COLUMN', @level2name=N'USE_RANGE'

GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'물리 방어력' ,@level0type=N'SCHEMA', @level0name=N'dbo', @level1type=N'TABLE', @level1name=N'TB_ITEM_ABILITY', @level2type=N'COLUMN', @level2name=N'DEFENSE_P'

GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'마법 방어력' ,@level0type=N'SCHEMA', @level0name=N'dbo', @level1type=N'TABLE', @level1name=N'TB_ITEM_ABILITY', @level2type=N'COLUMN', @level2name=N'DEFENSE_M'

GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'사정거리' ,@level0type=N'SCHEMA', @level0name=N'dbo', @level1type=N'TABLE', @level1name=N'TB_ITEM_ABILITY', @level2type=N'COLUMN', @level2name=N'ATTACK_RANGE'

GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'공격속도' ,@level0type=N'SCHEMA', @level0name=N'dbo', @level1type=N'TABLE', @level1name=N'TB_ITEM_ABILITY', @level2type=N'COLUMN', @level2name=N'ATTACK_SPEED'

GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'쿨타임' ,@level0type=N'SCHEMA', @level0name=N'dbo', @level1type=N'TABLE', @level1name=N'TB_ITEM_ABILITY', @level2type=N'COLUMN', @level2name=N'COOL_TIME1'

GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'그룹 쿨 타임' ,@level0type=N'SCHEMA', @level0name=N'dbo', @level1type=N'TABLE', @level1name=N'TB_ITEM_ABILITY', @level2type=N'COLUMN', @level2name=N'COOL_TIME2'

GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'공격력-최소(물리)' ,@level0type=N'SCHEMA', @level0name=N'dbo', @level1type=N'TABLE', @level1name=N'TB_ITEM_ABILITY', @level2type=N'COLUMN', @level2name=N'ATTACK_P_MIN'

GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'공격력-최대(물리)' ,@level0type=N'SCHEMA', @level0name=N'dbo', @level1type=N'TABLE', @level1name=N'TB_ITEM_ABILITY', @level2type=N'COLUMN', @level2name=N'ATTACK_P_MAX'

GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'공격력-최소(마법)' ,@level0type=N'SCHEMA', @level0name=N'dbo', @level1type=N'TABLE', @level1name=N'TB_ITEM_ABILITY', @level2type=N'COLUMN', @level2name=N'ATTACK_M_MIN'

GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'공격력-최대(마법)' ,@level0type=N'SCHEMA', @level0name=N'dbo', @level1type=N'TABLE', @level1name=N'TB_ITEM_ABILITY', @level2type=N'COLUMN', @level2name=N'ATTACK_M_MAX'

GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'옵션인덱스' ,@level0type=N'SCHEMA', @level0name=N'dbo', @level1type=N'TABLE', @level1name=N'TB_ITEM_ABILITY', @level2type=N'COLUMN', @level2name=N'OPT01_INDEX'

GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'옵션효과값' ,@level0type=N'SCHEMA', @level0name=N'dbo', @level1type=N'TABLE', @level1name=N'TB_ITEM_ABILITY', @level2type=N'COLUMN', @level2name=N'OPT01_VALUE'

GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'옵션인덱스' ,@level0type=N'SCHEMA', @level0name=N'dbo', @level1type=N'TABLE', @level1name=N'TB_ITEM_ABILITY', @level2type=N'COLUMN', @level2name=N'OPT02_INDEX'

GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'옵션효과값' ,@level0type=N'SCHEMA', @level0name=N'dbo', @level1type=N'TABLE', @level1name=N'TB_ITEM_ABILITY', @level2type=N'COLUMN', @level2name=N'OPT02_VALUE'

GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'옵션인덱스' ,@level0type=N'SCHEMA', @level0name=N'dbo', @level1type=N'TABLE', @level1name=N'TB_ITEM_ABILITY', @level2type=N'COLUMN', @level2name=N'OPT03_INDEX'

GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'옵션효과값' ,@level0type=N'SCHEMA', @level0name=N'dbo', @level1type=N'TABLE', @level1name=N'TB_ITEM_ABILITY', @level2type=N'COLUMN', @level2name=N'OPT03_VALUE'

GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'옵션인덱스' ,@level0type=N'SCHEMA', @level0name=N'dbo', @level1type=N'TABLE', @level1name=N'TB_ITEM_ABILITY', @level2type=N'COLUMN', @level2name=N'OPT04_INDEX'

GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'옵션효과값' ,@level0type=N'SCHEMA', @level0name=N'dbo', @level1type=N'TABLE', @level1name=N'TB_ITEM_ABILITY', @level2type=N'COLUMN', @level2name=N'OPT04_VALUE'

GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'옵션인덱스' ,@level0type=N'SCHEMA', @level0name=N'dbo', @level1type=N'TABLE', @level1name=N'TB_ITEM_ABILITY', @level2type=N'COLUMN', @level2name=N'OPT05_INDEX'

GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'옵션효과값' ,@level0type=N'SCHEMA', @level0name=N'dbo', @level1type=N'TABLE', @level1name=N'TB_ITEM_ABILITY', @level2type=N'COLUMN', @level2name=N'OPT05_VALUE'

GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'옵션인덱스' ,@level0type=N'SCHEMA', @level0name=N'dbo', @level1type=N'TABLE', @level1name=N'TB_ITEM_ABILITY', @level2type=N'COLUMN', @level2name=N'OPT06_INDEX'

GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'옵션효과값' ,@level0type=N'SCHEMA', @level0name=N'dbo', @level1type=N'TABLE', @level1name=N'TB_ITEM_ABILITY', @level2type=N'COLUMN', @level2name=N'OPT06_VALUE'

GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'옵션인덱스' ,@level0type=N'SCHEMA', @level0name=N'dbo', @level1type=N'TABLE', @level1name=N'TB_ITEM_ABILITY', @level2type=N'COLUMN', @level2name=N'OPT07_INDEX'

GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'옵션효과값' ,@level0type=N'SCHEMA', @level0name=N'dbo', @level1type=N'TABLE', @level1name=N'TB_ITEM_ABILITY', @level2type=N'COLUMN', @level2name=N'OPT07_VALUE'

GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'옵션인덱스' ,@level0type=N'SCHEMA', @level0name=N'dbo', @level1type=N'TABLE', @level1name=N'TB_ITEM_ABILITY', @level2type=N'COLUMN', @level2name=N'OPT08_INDEX'

GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'옵션효과값' ,@level0type=N'SCHEMA', @level0name=N'dbo', @level1type=N'TABLE', @level1name=N'TB_ITEM_ABILITY', @level2type=N'COLUMN', @level2name=N'OPT08_VALUE'

GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'옵션인덱스' ,@level0type=N'SCHEMA', @level0name=N'dbo', @level1type=N'TABLE', @level1name=N'TB_ITEM_ABILITY', @level2type=N'COLUMN', @level2name=N'OPT09_INDEX'

GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'옵션효과값' ,@level0type=N'SCHEMA', @level0name=N'dbo', @level1type=N'TABLE', @level1name=N'TB_ITEM_ABILITY', @level2type=N'COLUMN', @level2name=N'OPT09_VALUE'

GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'옵션인덱스' ,@level0type=N'SCHEMA', @level0name=N'dbo', @level1type=N'TABLE', @level1name=N'TB_ITEM_ABILITY', @level2type=N'COLUMN', @level2name=N'OPT10_INDEX'

GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'옵션효과값' ,@level0type=N'SCHEMA', @level0name=N'dbo', @level1type=N'TABLE', @level1name=N'TB_ITEM_ABILITY', @level2type=N'COLUMN', @level2name=N'OPT10_VALUE'

GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'스킬효과' ,@level0type=N'SCHEMA', @level0name=N'dbo', @level1type=N'TABLE', @level1name=N'TB_ITEM_ABILITY', @level2type=N'COLUMN', @level2name=N'INFLUENCE_IDX'

GO
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[GP_INVENTORY_SELECT]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'
/**********************************************************************
 *<
	FILE: GP_INVENTORY_SELECT.SQL

	DESCRIPTION:

	CREATED BY:	곽철중

	HISTORY:	2008-03-17 테이블 필드 삭제(TYPE)및 수정(SEAL).

 *>	Copyright (c) 2007, All Rights Reserved.
 **********************************************************************/

CREATE PROCEDURE [dbo].[GP_INVENTORY_SELECT]
	(@CHARACTER_IDX	[int])	--캐릭터 고유번호

AS

SET NOCOUNT ON

SELECT [IDX]
	  ,(SELECT [IDX] FROM [dbo].[TB_ITEM_DEFINE] WHERE [INDEX]=[ITEM_DEFINE_INDEX]) AS ''ITEM_DEFINE_IDX''
	  ,[ITEM_DEFINE_INDEX]
	  ,[NUMBER]
	  ,[COUNT]
	  ,[ENHANCED]
	  ,[CARD_SLOT1]
	  ,[CARD_SLOT2]
	  ,[CARD_SLOT3]
	  ,[CARD_SLOT4]
	  ,[CARD_SLOT5]
	  ,[SEAL]
	  ,[APPLY]
  FROM [dbo].[TB_INVENTORY]
 WHERE [CHARACTER_IDX]=@CHARACTER_IDX AND [APPLY]=0
' 
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[GP_CHARACTER_ACTIVE_WEAPON]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'/**********************************************************************
 *<
	FILE: GP_CHARACTER_ACTIVE_WEAPON.SQL

	DESCRIPTION:

	CREATED BY: 곽철중

	HISTORY: Created	08/18/08	SQLServer2005

 *>	Copyright (c) 2008, All Rights Reserved.
 **********************************************************************/

CREATE PROCEDURE [dbo].[GP_CHARACTER_ACTIVE_WEAPON]
	(@IDX			[int]
	,@ACTIVE_WEAPON	[tinyint]
	,@RETVALUE		[int]OUTPUT)

AS

DECLARE @ERRORCODE	[int]
DECLARE @ROWCOUNT	[int]

SET NOCOUNT ON

UPDATE [dbo].[TB_CHARACTER]
   SET [ACTIVE_WEAPON]=@ACTIVE_WEAPON
 WHERE [IDX]=@IDX

SELECT @ERRORCODE = @@ERROR, @ROWCOUNT = @@ROWCOUNT

IF @ERRORCODE <> 0 OR @ROWCOUNT <> 1
	BEGIN
		SET @RETVALUE = 1	--업데이트 실패
		RETURN @ERRORCODE
	END
ELSE
	BEGIN
		SET @RETVALUE = 0	--업데이트 성공
	END
' 
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[GP_CHARACTER_OPTION]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'
/**********************************************************************
 *<
	FILE: GP_CHARACTER_OPTION.SQL

	DESCRIPTION: 캐릭터 옵션 업데이트

	CREATED BY: 곽철중

	HISTORY: Created	07/07/08	SQLServer2005

 *>	Copyright (c) 2008, All Rights Reserved.
 **********************************************************************/

CREATE PROCEDURE [dbo].[GP_CHARACTER_OPTION]
	(@IDX		[int]
	,@OPTION1	[int]
	,@RETVALUE	[int]OUTPUT)

AS

DECLARE @ERRORCODE	[int]
DECLARE @ROWCOUNT	[int]

SET NOCOUNT ON

UPDATE [dbo].[TB_CHARACTER]
   SET [OPTION1]=@OPTION1
 WHERE [IDX]=@IDX

SELECT @ERRORCODE = @@ERROR, @ROWCOUNT = @@ROWCOUNT

IF @ERRORCODE <> 0 OR @ROWCOUNT <> 1
	BEGIN
		SET @RETVALUE = 1	--업데이트 실패
		RETURN @ERRORCODE
	END
ELSE
	BEGIN
		SET @RETVALUE = 0	--업데이트 성공
	END

' 
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[TB_ITEM_LIMIT]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[TB_ITEM_LIMIT](
	[IDX] [int] IDENTITY(1,1) NOT NULL,
	[INDEX] [int] NOT NULL,
	[CHAR_RACE] [tinyint] NOT NULL CONSTRAINT [DF_TB_ITEM_LIMIT_CHAR_RACE]  DEFAULT ((0)),
	[CHAR_GENDER] [tinyint] NOT NULL CONSTRAINT [DF_TB_ITEM_LIMIT_CHAR_GENDER]  DEFAULT ((0)),
	[CHAR_JOB] [int] NOT NULL CONSTRAINT [DF_TB_ITEM_LIMIT_CHAR_JOB]  DEFAULT ((0)),
	[CHAR_LEVEL] [tinyint] NOT NULL CONSTRAINT [DF_TB_ITEM_LIMIT_CHAR_LEVEL]  DEFAULT ((0)),
	[PVP_ONLY] [tinyint] NOT NULL CONSTRAINT [DF_TB_ITEM_LIMIT_PVP_ONLY]  DEFAULT ((0)),
	[DESCRIPTION] [nvarchar](max) NULL,
 CONSTRAINT [PK_TB_ITEM_LIMIT] PRIMARY KEY CLUSTERED 
(
	[IDX] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO

IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_ID(N'[dbo].[TB_ITEM_LIMIT]') AND name = N'IX_TB_ITEM_LIMIT')
CREATE NONCLUSTERED INDEX [IX_TB_ITEM_LIMIT] ON [dbo].[TB_ITEM_LIMIT] 
(
	[INDEX] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'고유번호' ,@level0type=N'SCHEMA', @level0name=N'dbo', @level1type=N'TABLE', @level1name=N'TB_ITEM_LIMIT', @level2type=N'COLUMN', @level2name=N'IDX'

GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'인덱스/분류번호' ,@level0type=N'SCHEMA', @level0name=N'dbo', @level1type=N'TABLE', @level1name=N'TB_ITEM_LIMIT', @level2type=N'COLUMN', @level2name=N'INDEX'

GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'직업' ,@level0type=N'SCHEMA', @level0name=N'dbo', @level1type=N'TABLE', @level1name=N'TB_ITEM_LIMIT', @level2type=N'COLUMN', @level2name=N'CHAR_JOB'

GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'레벨' ,@level0type=N'SCHEMA', @level0name=N'dbo', @level1type=N'TABLE', @level1name=N'TB_ITEM_LIMIT', @level2type=N'COLUMN', @level2name=N'CHAR_LEVEL'

GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'전장전용(0없음/1전장전용)' ,@level0type=N'SCHEMA', @level0name=N'dbo', @level1type=N'TABLE', @level1name=N'TB_ITEM_LIMIT', @level2type=N'COLUMN', @level2name=N'PVP_ONLY'

GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'설명' ,@level0type=N'SCHEMA', @level0name=N'dbo', @level1type=N'TABLE', @level1name=N'TB_ITEM_LIMIT', @level2type=N'COLUMN', @level2name=N'DESCRIPTION'

GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[TB_ITEM_CHANGE]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[TB_ITEM_CHANGE](
	[IDX] [int] IDENTITY(1,1) NOT NULL,
	[INDEX] [int] NOT NULL,
	[MIN_MONEY] [int] NOT NULL,
	[MAX_MONEY] [int] NOT NULL,
	[RATE] [varchar](max) NOT NULL,
	[ITEM_DEFINE_INDEXS] [varchar](max) NOT NULL,
	[INVENTORY_COUNTS] [varchar](max) NOT NULL,
 CONSTRAINT [PK_TB_ITEM_CHANGE] PRIMARY KEY CLUSTERED 
(
	[IDX] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO

IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_ID(N'[dbo].[TB_ITEM_CHANGE]') AND name = N'IX_TB_ITEM_CHANGE')
CREATE NONCLUSTERED INDEX [IX_TB_ITEM_CHANGE] ON [dbo].[TB_ITEM_CHANGE] 
(
	[INDEX] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'고유번호' ,@level0type=N'SCHEMA', @level0name=N'dbo', @level1type=N'TABLE', @level1name=N'TB_ITEM_CHANGE', @level2type=N'COLUMN', @level2name=N'IDX'

GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'인덱스/분류번호' ,@level0type=N'SCHEMA', @level0name=N'dbo', @level1type=N'TABLE', @level1name=N'TB_ITEM_CHANGE', @level2type=N'COLUMN', @level2name=N'INDEX'

GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'지급금액(최소)' ,@level0type=N'SCHEMA', @level0name=N'dbo', @level1type=N'TABLE', @level1name=N'TB_ITEM_CHANGE', @level2type=N'COLUMN', @level2name=N'MIN_MONEY'

GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'지급금액(최대)' ,@level0type=N'SCHEMA', @level0name=N'dbo', @level1type=N'TABLE', @level1name=N'TB_ITEM_CHANGE', @level2type=N'COLUMN', @level2name=N'MAX_MONEY'

GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'아이템 추가 확률[ANY]' ,@level0type=N'SCHEMA', @level0name=N'dbo', @level1type=N'TABLE', @level1name=N'TB_ITEM_CHANGE', @level2type=N'COLUMN', @level2name=N'RATE'

GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'TB_ITEM_DEFINE::INDEX[ANY]' ,@level0type=N'SCHEMA', @level0name=N'dbo', @level1type=N'TABLE', @level1name=N'TB_ITEM_CHANGE', @level2type=N'COLUMN', @level2name=N'ITEM_DEFINE_INDEXS'

GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'TB_INVENTORY::COUNTX[ANY]' ,@level0type=N'SCHEMA', @level0name=N'dbo', @level1type=N'TABLE', @level1name=N'TB_ITEM_CHANGE', @level2type=N'COLUMN', @level2name=N'INVENTORY_COUNTS'

GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[TB_FORCE_COUNT]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[TB_FORCE_COUNT](
	[FORCE_TYPE] [tinyint] NOT NULL,
	[COUNT] [int] NOT NULL CONSTRAINT [DF_TB_FORCE_COUNT_COUNT]  DEFAULT ((0)),
 CONSTRAINT [PK_TB_FORCE_COUNT] PRIMARY KEY CLUSTERED 
(
	[FORCE_TYPE] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[GP_VERIFY_GUILD]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'




/**********************************************************************
 *<
	FILE: GP_VERIFY_GUILD.SQL

	DESCRIPTION:

	CREATED BY:

	HISTORY:

 *>	Copyright (c) 2008, All Rights Reserved.
 **********************************************************************/

CREATE PROCEDURE [dbo].[GP_VERIFY_GUILD]
	(@COUNT    [int]OUTPUT
	,@TOTAL	   [int]OUTPUT
	,@RETVALUE [int]OUTPUT)

AS

SET NOCOUNT ON

DECLARE @MAX [int]

SELECT @TOTAL=COUNT(IDX)
      ,@MAX  =MAX(IDX)
  FROM [dbo].[TB_GUILD]

SELECT @COUNT=COUNT(IDX)
  FROM [dbo].[TB_GUILD]
 WHERE [APPLY]=0
  
SET @RETVALUE = @TOTAL - @MAX




' 
END
GO
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[GP_STALL_SELL_CLEAR]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'
/**********************************************************************
 *<
	FILE: GP_STALL_SELL_CLEAR.SQL

	DESCRIPTION:

	CREATED BY:

	HISTORY:

 *>	Copyright (c) 2008, All Rights Reserved.
 **********************************************************************/

CREATE PROCEDURE [dbo].[GP_STALL_SELL_CLEAR]
	(@CHARACTER_IDX	[int]			--캐릭터 고유번호
	,@RETVALUE		[int]OUTPUT)	--반환값

AS

SET NOCOUNT ON

UPDATE [dbo].[TB_STALL_SELL]
   SET [APPLY]=1
 WHERE [CHARACTER_IDX]=@CHARACTER_IDX
   AND [APPLY]=0

SELECT @RETVALUE = @@ERROR
' 
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[TB_ITEM_DEFINE]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[TB_ITEM_DEFINE](
	[IDX] [int] IDENTITY(1,1) NOT NULL,
	[REGISTER_DATE] [datetime] NOT NULL CONSTRAINT [DF_TB_ITEM_DEFINE_REGISTER_DATE]  DEFAULT (getdate()),
	[INDEX] [int] NOT NULL,
	[NAME] [nvarchar](50) NOT NULL,
	[TYPE] [tinyint] NOT NULL CONSTRAINT [DF_TB_ITEM_DEFINE_TYPE]  DEFAULT ((0)),
	[SUB_TYPE] [tinyint] NOT NULL CONSTRAINT [DF_TB_ITEM_DEFINE_SUB_TYPE]  DEFAULT ((0)),
	[WEIGHT] [smallint] NOT NULL CONSTRAINT [DF_TB_ITEM_DEFINE_WEIGHT]  DEFAULT ((0)),
	[CAPACITY] [smallint] NOT NULL CONSTRAINT [DF_TB_ITEM_DEFINE_CAPACITY]  DEFAULT ((0)),
	[SELL_TYPE] [int] NOT NULL CONSTRAINT [DF_TB_ITEM_DEFINE_SELL_TYPE]  DEFAULT ((0)),
	[SELL_PRICE] [int] NOT NULL CONSTRAINT [DF_TB_ITEM_DEFINE_SELL_PRICE]  DEFAULT ((0)),
	[BUY_TYPE] [int] NOT NULL CONSTRAINT [DF_TB_ITEM_DEFINE_BUY_TYPE]  DEFAULT ((0)),
	[BUY_PRICE] [int] NOT NULL CONSTRAINT [DF_TB_ITEM_DEFINE_BUY_PRICE]  DEFAULT ((0)),
	[PRESENT] [int] NOT NULL CONSTRAINT [DF_TB_ITEM_DEFINE_PRESENT]  DEFAULT ((0)),
	[MAX_PRESENT] [int] NOT NULL CONSTRAINT [DF_TB_ITEM_DEFINE_MAX_PRESENT]  DEFAULT ((0)),
	[EXCHANGE] [tinyint] NOT NULL CONSTRAINT [DF_TB_ITEM_DEFINE_EXCHANGE]  DEFAULT ((0)),
	[MAX_INVENTORY] [int] NOT NULL CONSTRAINT [DF_TB_ITEM_DEFINE_MAX_INVENTORY]  DEFAULT ((0)),
	[ABILITY_INDEX] [int] NOT NULL CONSTRAINT [DF_TB_ITEM_DEFINE_ABILITY_IDX]  DEFAULT ((0)),
	[LIMIT_INDEX] [int] NOT NULL CONSTRAINT [DF_TB_ITEM_DEFINE_LIMIT_IDX]  DEFAULT ((0)),
	[CARD_INDEX] [int] NOT NULL CONSTRAINT [DF_TB_ITEM_DEFINE_CARD_IDX]  DEFAULT ((0)),
	[CARD_SLOT_INDEX] [int] NOT NULL CONSTRAINT [DF_TB_ITEM_DEFINE_CARD_SLOT_INDEX]  DEFAULT ((0)),
	[TAROT_INDEX] [int] NOT NULL CONSTRAINT [DF_TB_ITEM_DEFINE_TAROT_INDEX]  DEFAULT ((0)),
	[SPREAD_INDEX] [int] NOT NULL CONSTRAINT [DF_TB_ITEM_DEFINE_SPREAD_INDEX]  DEFAULT ((0)),
	[ENHANCED_INDEX] [int] NOT NULL CONSTRAINT [DF_TB_ITEM_DEFINE_ENHANCED_INDEX]  DEFAULT ((0)),
	[ENHANCED_RATE_INDEX] [int] NOT NULL CONSTRAINT [DF_TB_ITEM_DEFINE_ENHANCED_RATE_INDEX]  DEFAULT ((0)),
	[DISJOINT_INDEX] [int] NOT NULL CONSTRAINT [DF_TB_ITEM_DEFINE_DISJOINT_INDEX]  DEFAULT ((0)),
	[CHANGE_INDEX] [int] NOT NULL CONSTRAINT [DF_TB_ITEM_DEFINE_CHANGE_INDEX]  DEFAULT ((0)),
	[TITLE_INDEX] [int] NOT NULL CONSTRAINT [DF_TB_ITEM_DEFINE_TITLE_INDEX]  DEFAULT ((0)),
	[DESCRIPTION] [nvarchar](max) NULL,
	[APPLY] [tinyint] NOT NULL CONSTRAINT [DF_TB_ITEM_DEFINE_APPLY]  DEFAULT ((0)),
 CONSTRAINT [PK_TB_ITEM_DEFINE] PRIMARY KEY CLUSTERED 
(
	[IDX] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO

IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_ID(N'[dbo].[TB_ITEM_DEFINE]') AND name = N'IX_TB_ITEM_DEFINE')
CREATE NONCLUSTERED INDEX [IX_TB_ITEM_DEFINE] ON [dbo].[TB_ITEM_DEFINE] 
(
	[INDEX] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'고유번호' ,@level0type=N'SCHEMA', @level0name=N'dbo', @level1type=N'TABLE', @level1name=N'TB_ITEM_DEFINE', @level2type=N'COLUMN', @level2name=N'IDX'

GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'등록일' ,@level0type=N'SCHEMA', @level0name=N'dbo', @level1type=N'TABLE', @level1name=N'TB_ITEM_DEFINE', @level2type=N'COLUMN', @level2name=N'REGISTER_DATE'

GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'인덱스/분류번호' ,@level0type=N'SCHEMA', @level0name=N'dbo', @level1type=N'TABLE', @level1name=N'TB_ITEM_DEFINE', @level2type=N'COLUMN', @level2name=N'INDEX'

GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'이름' ,@level0type=N'SCHEMA', @level0name=N'dbo', @level1type=N'TABLE', @level1name=N'TB_ITEM_DEFINE', @level2type=N'COLUMN', @level2name=N'NAME'

GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'종류(기획서 참조)' ,@level0type=N'SCHEMA', @level0name=N'dbo', @level1type=N'TABLE', @level1name=N'TB_ITEM_DEFINE', @level2type=N'COLUMN', @level2name=N'TYPE'

GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'종류(세부항목)' ,@level0type=N'SCHEMA', @level0name=N'dbo', @level1type=N'TABLE', @level1name=N'TB_ITEM_DEFINE', @level2type=N'COLUMN', @level2name=N'SUB_TYPE'

GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'무게' ,@level0type=N'SCHEMA', @level0name=N'dbo', @level1type=N'TABLE', @level1name=N'TB_ITEM_DEFINE', @level2type=N'COLUMN', @level2name=N'WEIGHT'

GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'겹침 가능 갯수' ,@level0type=N'SCHEMA', @level0name=N'dbo', @level1type=N'TABLE', @level1name=N'TB_ITEM_DEFINE', @level2type=N'COLUMN', @level2name=N'CAPACITY'

GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'판매가격' ,@level0type=N'SCHEMA', @level0name=N'dbo', @level1type=N'TABLE', @level1name=N'TB_ITEM_DEFINE', @level2type=N'COLUMN', @level2name=N'SELL_PRICE'

GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'구입가격' ,@level0type=N'SCHEMA', @level0name=N'dbo', @level1type=N'TABLE', @level1name=N'TB_ITEM_DEFINE', @level2type=N'COLUMN', @level2name=N'BUY_PRICE'

GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'현재 출현수' ,@level0type=N'SCHEMA', @level0name=N'dbo', @level1type=N'TABLE', @level1name=N'TB_ITEM_DEFINE', @level2type=N'COLUMN', @level2name=N'PRESENT'

GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'최대 출현수' ,@level0type=N'SCHEMA', @level0name=N'dbo', @level1type=N'TABLE', @level1name=N'TB_ITEM_DEFINE', @level2type=N'COLUMN', @level2name=N'MAX_PRESENT'

GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'사용자간 거래 여부(0거래가능/1거래불가)' ,@level0type=N'SCHEMA', @level0name=N'dbo', @level1type=N'TABLE', @level1name=N'TB_ITEM_DEFINE', @level2type=N'COLUMN', @level2name=N'EXCHANGE'

GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'속성 테이블 인덱스' ,@level0type=N'SCHEMA', @level0name=N'dbo', @level1type=N'TABLE', @level1name=N'TB_ITEM_DEFINE', @level2type=N'COLUMN', @level2name=N'ABILITY_INDEX'

GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'제한 테이블 인덱스' ,@level0type=N'SCHEMA', @level0name=N'dbo', @level1type=N'TABLE', @level1name=N'TB_ITEM_DEFINE', @level2type=N'COLUMN', @level2name=N'LIMIT_INDEX'

GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'카드 테이블 인덱스' ,@level0type=N'SCHEMA', @level0name=N'dbo', @level1type=N'TABLE', @level1name=N'TB_ITEM_DEFINE', @level2type=N'COLUMN', @level2name=N'CARD_INDEX'

GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'카드슬롯 테이블 인덱스' ,@level0type=N'SCHEMA', @level0name=N'dbo', @level1type=N'TABLE', @level1name=N'TB_ITEM_DEFINE', @level2type=N'COLUMN', @level2name=N'CARD_SLOT_INDEX'

GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'타로 테이블 인덱스' ,@level0type=N'SCHEMA', @level0name=N'dbo', @level1type=N'TABLE', @level1name=N'TB_ITEM_DEFINE', @level2type=N'COLUMN', @level2name=N'TAROT_INDEX'

GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'스프레드 테이블 인덱스' ,@level0type=N'SCHEMA', @level0name=N'dbo', @level1type=N'TABLE', @level1name=N'TB_ITEM_DEFINE', @level2type=N'COLUMN', @level2name=N'SPREAD_INDEX'

GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'강화 테이블 인덱스' ,@level0type=N'SCHEMA', @level0name=N'dbo', @level1type=N'TABLE', @level1name=N'TB_ITEM_DEFINE', @level2type=N'COLUMN', @level2name=N'ENHANCED_INDEX'

GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'강화확률 테이블 인덱스' ,@level0type=N'SCHEMA', @level0name=N'dbo', @level1type=N'TABLE', @level1name=N'TB_ITEM_DEFINE', @level2type=N'COLUMN', @level2name=N'ENHANCED_RATE_INDEX'

GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'분해 테이블 인덱스' ,@level0type=N'SCHEMA', @level0name=N'dbo', @level1type=N'TABLE', @level1name=N'TB_ITEM_DEFINE', @level2type=N'COLUMN', @level2name=N'DISJOINT_INDEX'

GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'변환 테이블 인덱스' ,@level0type=N'SCHEMA', @level0name=N'dbo', @level1type=N'TABLE', @level1name=N'TB_ITEM_DEFINE', @level2type=N'COLUMN', @level2name=N'CHANGE_INDEX'

GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'호칭 테이블 인덱스' ,@level0type=N'SCHEMA', @level0name=N'dbo', @level1type=N'TABLE', @level1name=N'TB_ITEM_DEFINE', @level2type=N'COLUMN', @level2name=N'TITLE_INDEX'

GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'설명' ,@level0type=N'SCHEMA', @level0name=N'dbo', @level1type=N'TABLE', @level1name=N'TB_ITEM_DEFINE', @level2type=N'COLUMN', @level2name=N'DESCRIPTION'

GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'적용여부(0미사용/1사용중/2사용안함)' ,@level0type=N'SCHEMA', @level0name=N'dbo', @level1type=N'TABLE', @level1name=N'TB_ITEM_DEFINE', @level2type=N'COLUMN', @level2name=N'APPLY'

GO
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[GP_STALL_SELL_REMOVE]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'
/**********************************************************************
 *<
	FILE: GP_STALL_SELL_REMOVE.SQL

	DESCRIPTION:

	CREATED BY:

	HISTORY:

 *>	Copyright (c) 2008, All Rights Reserved.
 **********************************************************************/

CREATE PROCEDURE [dbo].[GP_STALL_SELL_REMOVE]
	(@INVENTORY_IDX	[int]			--인벤토리 고유번호
	,@RETVALUE		[int]OUTPUT)	--반환값

AS

SET NOCOUNT ON

UPDATE [dbo].[TB_STALL_SELL]
   SET [APPLY]=1
 WHERE [INVENTORY_IDX]=@INVENTORY_IDX
   AND [APPLY]=0

SELECT @RETVALUE = @@ERROR
' 
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[TB_ITEM_CARD]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[TB_ITEM_CARD](
	[IDX] [int] IDENTITY(1,1) NOT NULL,
	[INDEX] [int] NOT NULL,
	[EPISODE] [int] NOT NULL,
	[NUMBER] [int] NOT NULL,
	[LEVEL] [tinyint] NOT NULL,
	[TYPE] [tinyint] NOT NULL,
	[SUBTYPE] [tinyint] NOT NULL,
 CONSTRAINT [PK_TB_ITEM_CARD] PRIMARY KEY CLUSTERED 
(
	[IDX] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO

IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_ID(N'[dbo].[TB_ITEM_CARD]') AND name = N'IX_TB_ITEM_CARD')
CREATE NONCLUSTERED INDEX [IX_TB_ITEM_CARD] ON [dbo].[TB_ITEM_CARD] 
(
	[INDEX] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'고유번호' ,@level0type=N'SCHEMA', @level0name=N'dbo', @level1type=N'TABLE', @level1name=N'TB_ITEM_CARD', @level2type=N'COLUMN', @level2name=N'IDX'

GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'인덱스/분류번호' ,@level0type=N'SCHEMA', @level0name=N'dbo', @level1type=N'TABLE', @level1name=N'TB_ITEM_CARD', @level2type=N'COLUMN', @level2name=N'INDEX'

GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'판' ,@level0type=N'SCHEMA', @level0name=N'dbo', @level1type=N'TABLE', @level1name=N'TB_ITEM_CARD', @level2type=N'COLUMN', @level2name=N'EPISODE'

GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'카드번호' ,@level0type=N'SCHEMA', @level0name=N'dbo', @level1type=N'TABLE', @level1name=N'TB_ITEM_CARD', @level2type=N'COLUMN', @level2name=N'NUMBER'

GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'희귀도' ,@level0type=N'SCHEMA', @level0name=N'dbo', @level1type=N'TABLE', @level1name=N'TB_ITEM_CARD', @level2type=N'COLUMN', @level2name=N'LEVEL'

GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'카드분류' ,@level0type=N'SCHEMA', @level0name=N'dbo', @level1type=N'TABLE', @level1name=N'TB_ITEM_CARD', @level2type=N'COLUMN', @level2name=N'TYPE'

GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'장착위치' ,@level0type=N'SCHEMA', @level0name=N'dbo', @level1type=N'TABLE', @level1name=N'TB_ITEM_CARD', @level2type=N'COLUMN', @level2name=N'SUBTYPE'

GO
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[GP_CHARACTER_NAME]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'
/**********************************************************************
 *<
	FILE: GP_CHARACTER_NAME.SQL

	DESCRIPTION:

	CREATED BY:

	HISTORY:

 *>	Copyright (c) 2007, All Rights Reserved.
 **********************************************************************/

CREATE PROCEDURE [dbo].[GP_CHARACTER_NAME]
	(@NAME			[nvarchar](16)	--이름
	,@RETVALUE		[int]OUTPUT)	--반환값

AS

SET NOCOUNT ON

IF EXISTS (SELECT * FROM [dbo].[TB_CHARACTER] WHERE [NAME]=@NAME AND [APPLY]=0)
	BEGIN
		SET @RETVALUE = 1	--실패
	END
ELSE
	BEGIN
		SET @RETVALUE = 0	--성공
	END
' 
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[TB_INVENTORY]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[TB_INVENTORY](
	[IDX] [int] IDENTITY(1,1) NOT NULL,
	[REGISTER_DATE] [datetime] NOT NULL CONSTRAINT [DF_TB_INVENTORY_REGISTER_DATE]  DEFAULT (getdate()),
	[CHARACTER_IDX] [int] NOT NULL,
	[ITEM_DEFINE_INDEX] [int] NOT NULL,
	[NUMBER] [smallint] NOT NULL,
	[COUNT] [smallint] NOT NULL,
	[ENHANCED] [tinyint] NOT NULL CONSTRAINT [DF_TB_INVENTORY_ENHANCED]  DEFAULT ((0)),
	[CARD_SLOT1] [int] NOT NULL CONSTRAINT [DF_TB_INVENTORY_ITEM_CARD_IDX1]  DEFAULT ((0)),
	[CARD_SLOT2] [int] NOT NULL CONSTRAINT [DF_TB_INVENTORY_ITEM_CARD_IDX2]  DEFAULT ((0)),
	[CARD_SLOT3] [int] NOT NULL CONSTRAINT [DF_TB_INVENTORY_ITEM_CARD_IDX3]  DEFAULT ((0)),
	[CARD_SLOT4] [int] NOT NULL CONSTRAINT [DF_TB_INVENTORY_SLOT04]  DEFAULT ((0)),
	[CARD_SLOT5] [int] NOT NULL CONSTRAINT [DF_TB_INVENTORY_SLOT05]  DEFAULT ((0)),
	[SEAL] [tinyint] NOT NULL CONSTRAINT [DF_TB_INVENTORY_LOCK]  DEFAULT ((0)),
	[APPLY] [tinyint] NOT NULL CONSTRAINT [DF_TB_INVENTORY_APPLY]  DEFAULT ((0)),
 CONSTRAINT [PK_TB_INVENTORY] PRIMARY KEY CLUSTERED 
(
	[IDX] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO

IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_ID(N'[dbo].[TB_INVENTORY]') AND name = N'IX_TB_INVENTORY')
CREATE NONCLUSTERED INDEX [IX_TB_INVENTORY] ON [dbo].[TB_INVENTORY] 
(
	[CHARACTER_IDX] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'고유번호(인덱스)' ,@level0type=N'SCHEMA', @level0name=N'dbo', @level1type=N'TABLE', @level1name=N'TB_INVENTORY', @level2type=N'COLUMN', @level2name=N'IDX'

GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'등록일' ,@level0type=N'SCHEMA', @level0name=N'dbo', @level1type=N'TABLE', @level1name=N'TB_INVENTORY', @level2type=N'COLUMN', @level2name=N'REGISTER_DATE'

GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'캐릭터 인덱스' ,@level0type=N'SCHEMA', @level0name=N'dbo', @level1type=N'TABLE', @level1name=N'TB_INVENTORY', @level2type=N'COLUMN', @level2name=N'CHARACTER_IDX'

GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'아이템 정의 인덱스' ,@level0type=N'SCHEMA', @level0name=N'dbo', @level1type=N'TABLE', @level1name=N'TB_INVENTORY', @level2type=N'COLUMN', @level2name=N'ITEM_DEFINE_INDEX'

GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'번호(인벤위치)' ,@level0type=N'SCHEMA', @level0name=N'dbo', @level1type=N'TABLE', @level1name=N'TB_INVENTORY', @level2type=N'COLUMN', @level2name=N'NUMBER'

GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'보유 수량' ,@level0type=N'SCHEMA', @level0name=N'dbo', @level1type=N'TABLE', @level1name=N'TB_INVENTORY', @level2type=N'COLUMN', @level2name=N'COUNT'

GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'강화단계' ,@level0type=N'SCHEMA', @level0name=N'dbo', @level1type=N'TABLE', @level1name=N'TB_INVENTORY', @level2type=N'COLUMN', @level2name=N'ENHANCED'

GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'카드슬롯1' ,@level0type=N'SCHEMA', @level0name=N'dbo', @level1type=N'TABLE', @level1name=N'TB_INVENTORY', @level2type=N'COLUMN', @level2name=N'CARD_SLOT1'

GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'카드슬롯2' ,@level0type=N'SCHEMA', @level0name=N'dbo', @level1type=N'TABLE', @level1name=N'TB_INVENTORY', @level2type=N'COLUMN', @level2name=N'CARD_SLOT2'

GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'카드슬롯3' ,@level0type=N'SCHEMA', @level0name=N'dbo', @level1type=N'TABLE', @level1name=N'TB_INVENTORY', @level2type=N'COLUMN', @level2name=N'CARD_SLOT3'

GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'카드슬롯4' ,@level0type=N'SCHEMA', @level0name=N'dbo', @level1type=N'TABLE', @level1name=N'TB_INVENTORY', @level2type=N'COLUMN', @level2name=N'CARD_SLOT4'

GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'카드슬롯5' ,@level0type=N'SCHEMA', @level0name=N'dbo', @level1type=N'TABLE', @level1name=N'TB_INVENTORY', @level2type=N'COLUMN', @level2name=N'CARD_SLOT5'

GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'봉인(0봉인해제/1봉인됨)' ,@level0type=N'SCHEMA', @level0name=N'dbo', @level1type=N'TABLE', @level1name=N'TB_INVENTORY', @level2type=N'COLUMN', @level2name=N'SEAL'

GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'적용여부(0사용중/1사용중지)' ,@level0type=N'SCHEMA', @level0name=N'dbo', @level1type=N'TABLE', @level1name=N'TB_INVENTORY', @level2type=N'COLUMN', @level2name=N'APPLY'

GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[TB_STALL_SELL]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[TB_STALL_SELL](
	[IDX] [int] IDENTITY(1,1) NOT NULL,
	[REGISTER_DATE] [datetime] NOT NULL CONSTRAINT [DF_TB_STALL_SELL_REGISTER_DATE]  DEFAULT (getdate()),
	[CHANNEL_NUM] [int] NOT NULL,
	[INVENTORY_IDX] [int] NOT NULL,
	[CHARACTER_IDX] [int] NOT NULL,
	[ITEM_DEFINE_INDEX] [int] NOT NULL,
	[ENHANCED] [tinyint] NOT NULL,
	[PRICE] [int] NOT NULL,
	[APPLY] [tinyint] NOT NULL CONSTRAINT [DF_TB_STALL_SELL_APPLY]  DEFAULT ((0)),
 CONSTRAINT [PK_TB_STALL_SELL] PRIMARY KEY CLUSTERED 
(
	[IDX] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO

IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_ID(N'[dbo].[TB_STALL_SELL]') AND name = N'IX_TB_STALL_SELL')
CREATE NONCLUSTERED INDEX [IX_TB_STALL_SELL] ON [dbo].[TB_STALL_SELL] 
(
	[INVENTORY_IDX] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'고유번호' ,@level0type=N'SCHEMA', @level0name=N'dbo', @level1type=N'TABLE', @level1name=N'TB_STALL_SELL', @level2type=N'COLUMN', @level2name=N'IDX'

GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'등록일' ,@level0type=N'SCHEMA', @level0name=N'dbo', @level1type=N'TABLE', @level1name=N'TB_STALL_SELL', @level2type=N'COLUMN', @level2name=N'REGISTER_DATE'

GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'채널번호' ,@level0type=N'SCHEMA', @level0name=N'dbo', @level1type=N'TABLE', @level1name=N'TB_STALL_SELL', @level2type=N'COLUMN', @level2name=N'CHANNEL_NUM'

GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'인벤토리 고유번호' ,@level0type=N'SCHEMA', @level0name=N'dbo', @level1type=N'TABLE', @level1name=N'TB_STALL_SELL', @level2type=N'COLUMN', @level2name=N'INVENTORY_IDX'

GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'캐릭터 고유번호' ,@level0type=N'SCHEMA', @level0name=N'dbo', @level1type=N'TABLE', @level1name=N'TB_STALL_SELL', @level2type=N'COLUMN', @level2name=N'CHARACTER_IDX'

GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'검색조건-아이템 정의 인덱스' ,@level0type=N'SCHEMA', @level0name=N'dbo', @level1type=N'TABLE', @level1name=N'TB_STALL_SELL', @level2type=N'COLUMN', @level2name=N'ITEM_DEFINE_INDEX'

GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'검색조건-강화단계' ,@level0type=N'SCHEMA', @level0name=N'dbo', @level1type=N'TABLE', @level1name=N'TB_STALL_SELL', @level2type=N'COLUMN', @level2name=N'ENHANCED'

GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'정렬조건-개당가격' ,@level0type=N'SCHEMA', @level0name=N'dbo', @level1type=N'TABLE', @level1name=N'TB_STALL_SELL', @level2type=N'COLUMN', @level2name=N'PRICE'

GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'적용여부(0사용중/1사용안함)' ,@level0type=N'SCHEMA', @level0name=N'dbo', @level1type=N'TABLE', @level1name=N'TB_STALL_SELL', @level2type=N'COLUMN', @level2name=N'APPLY'

GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[TB_QUEST_PROGRESS]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[TB_QUEST_PROGRESS](
	[IDX] [int] IDENTITY(1,1) NOT NULL,
	[REGISTER_DATE] [datetime] NOT NULL CONSTRAINT [DF_TB_QUEST_PROGRESS_REGISTER_DATE]  DEFAULT (getdate()),
	[VALID_THRU] [datetime] NOT NULL CONSTRAINT [DF_TB_QUEST_PROGRESS_VALID_THRU]  DEFAULT (getdate()),
	[CHARACTER_IDX] [int] NOT NULL,
	[QUEST_IDX] [int] NOT NULL,
	[CHECK] [bigint] NOT NULL CONSTRAINT [DF_TB_QUEST_PROGRESS_CHECK]  DEFAULT ((0)),
	[TIME_TYPE] [tinyint] NOT NULL CONSTRAINT [DF_TB_QUEST_PROGRESS_TIME_TYPE]  DEFAULT ((0)),
	[REST_TIME] [int] NOT NULL CONSTRAINT [DF_TB_QUEST_PROGRESS_REST_TIME]  DEFAULT ((0)),
	[APPLY] [tinyint] NOT NULL CONSTRAINT [DF_TB_QUEST_PROGRESS_APPLY]  DEFAULT ((0)),
 CONSTRAINT [PK_TB_QUEST_PROGRESS] PRIMARY KEY CLUSTERED 
(
	[IDX] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO

IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_ID(N'[dbo].[TB_QUEST_PROGRESS]') AND name = N'IX_TB_QUEST_PROGRESS_A')
CREATE NONCLUSTERED INDEX [IX_TB_QUEST_PROGRESS_A] ON [dbo].[TB_QUEST_PROGRESS] 
(
	[APPLY] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
GO

IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_ID(N'[dbo].[TB_QUEST_PROGRESS]') AND name = N'IX_TB_QUEST_PROGRESS_C')
CREATE NONCLUSTERED INDEX [IX_TB_QUEST_PROGRESS_C] ON [dbo].[TB_QUEST_PROGRESS] 
(
	[CHARACTER_IDX] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'등록시간' ,@level0type=N'SCHEMA', @level0name=N'dbo', @level1type=N'TABLE', @level1name=N'TB_QUEST_PROGRESS', @level2type=N'COLUMN', @level2name=N'REGISTER_DATE'

GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'캐릭터인덱스' ,@level0type=N'SCHEMA', @level0name=N'dbo', @level1type=N'TABLE', @level1name=N'TB_QUEST_PROGRESS', @level2type=N'COLUMN', @level2name=N'CHARACTER_IDX'

GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'퀘스트인덱스' ,@level0type=N'SCHEMA', @level0name=N'dbo', @level1type=N'TABLE', @level1name=N'TB_QUEST_PROGRESS', @level2type=N'COLUMN', @level2name=N'QUEST_IDX'

GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'진행정보 비트' ,@level0type=N'SCHEMA', @level0name=N'dbo', @level1type=N'TABLE', @level1name=N'TB_QUEST_PROGRESS', @level2type=N'COLUMN', @level2name=N'CHECK'

GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'남은시간' ,@level0type=N'SCHEMA', @level0name=N'dbo', @level1type=N'TABLE', @level1name=N'TB_QUEST_PROGRESS', @level2type=N'COLUMN', @level2name=N'REST_TIME'

GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'적용여부(0:진행중, 1:완료, 2:진행완료, 3:포기,  5:강제삭제)' ,@level0type=N'SCHEMA', @level0name=N'dbo', @level1type=N'TABLE', @level1name=N'TB_QUEST_PROGRESS', @level2type=N'COLUMN', @level2name=N'APPLY'

GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[GP_ITEM_DEFINE_SELECT]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'


/**********************************************************************
 *<
	FILE: GP_ITEM_DEFINE_SELECT.SQL

	DESCRIPTION: TB_ITEM_DEFINE를 분할 로딩.

	CREATED BY: 곽철중

	HISTORY: 08/03/26 GP_ITEM_DEFINE_TABLE.SQL를 수정하여 새로 코딩.

 *>	Copyright (c) 2008, All Rights Reserved.
 **********************************************************************/

CREATE PROCEDURE [dbo].[GP_ITEM_DEFINE_SELECT]
	(@IDX	[int])		--고유번호

AS

SET NOCOUNT ON

SELECT [IDX] 
      ,ISNULL((SELECT [IDX] FROM [dbo].[TB_ITEM_ABILITY      ] WHERE [INDEX]=[ABILITY_INDEX      ]), 0) AS ''IDX_ABILITY''
      ,ISNULL((SELECT [IDX] FROM [dbo].[TB_ITEM_LIMIT        ] WHERE [INDEX]=[LIMIT_INDEX        ]), 0) AS ''IDX_LIMIT''
      ,ISNULL((SELECT [IDX] FROM [dbo].[TB_ITEM_CARD         ] WHERE [INDEX]=[CARD_INDEX         ]), 0) AS ''IDX_CARD''
      ,ISNULL((SELECT [IDX] FROM [dbo].[TB_ITEM_CARD_SLOT    ] WHERE [INDEX]=[CARD_SLOT_INDEX    ]), 0) AS ''IDX_CARD_SLOT''
	  ,ISNULL((SELECT [IDX] FROM [dbo].[TB_ITEM_TAROT        ] WHERE [INDEX]=[TAROT_INDEX        ]), 0) AS ''IDX_TAROT''
	  ,ISNULL((SELECT [IDX] FROM [dbo].[TB_ITEM_ENHANCED     ] WHERE [INDEX]=[ENHANCED_INDEX     ]), 0) AS ''IDX_ENHANCED''
	  ,ISNULL((SELECT [IDX] FROM [dbo].[TB_ITEM_ENHANCED_RATE] WHERE [INDEX]=[ENHANCED_RATE_INDEX]), 0) AS ''IDX_ENHANCED_RATE''
	  ,ISNULL((SELECT [IDX] FROM [dbo].[TB_ITEM_DISJOINT     ] WHERE [INDEX]=[DISJOINT_INDEX     ]), 0) AS ''IDX_DISJOINT''
	  ,ISNULL((SELECT [IDX] FROM [dbo].[TB_ITEM_CHANGE       ] WHERE [INDEX]=[CHANGE_INDEX       ]), 0) AS ''IDX_CHANGE''
      ,[INDEX]
      ,[NAME]
      ,[TYPE]
      ,[SUB_TYPE]
      ,[WEIGHT]
      ,[CAPACITY]
      ,[SELL_TYPE]
      ,[SELL_PRICE]
      ,[BUY_TYPE]
      ,[BUY_PRICE]
      ,[PRESENT]
      ,[MAX_PRESENT]
      ,[EXCHANGE]
      ,[MAX_INVENTORY]
      ,[ABILITY_INDEX]
      ,[LIMIT_INDEX]
      ,[CARD_INDEX]
      ,[CARD_SLOT_INDEX]
	  ,[TAROT_INDEX]
      ,[SPREAD_INDEX]
      ,[ENHANCED_INDEX]
      ,[ENHANCED_RATE_INDEX]
      ,[DISJOINT_INDEX]
      ,[CHANGE_INDEX]
	  ,[TITLE_INDEX]
      ,[APPLY]
  FROM [dbo].[TB_ITEM_DEFINE]
 WHERE [IDX]=@IDX


' 
END
GO
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[GP_ITEM_DISJOINT_SELECT]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'
/**********************************************************************
 *<
	FILE: GP_ITEM_DISJOINT_SELECT.SQL

	DESCRIPTION: TB_ITEM_DISJOINT를 분할 로딩.

	CREATED BY: 곽철중

	HISTORY:

 *>	Copyright (c) 2008, All Rights Reserved.
 **********************************************************************/

CREATE PROCEDURE [dbo].[GP_ITEM_DISJOINT_SELECT]
	(@IDX	[int])	--고유번호

AS

SET NOCOUNT ON

SELECT [IDX]
      ,[INDEX]
      ,[PRICE]
      ,[ITEM_DEFINE_INDEX1]
      ,[INVENTORY_COUNT1]
      ,[ITEM_DEFINE_INDEX2]
      ,[INVENTORY_COUNT2]
      ,[ITEM_DEFINE_INDEX3]
      ,[INVENTORY_COUNT3]
      ,[ITEM_DEFINE_INDEX4]
      ,[INVENTORY_COUNT4]
      ,[ITEM_DEFINE_INDEX5]
      ,[INVENTORY_COUNT5]
      ,[ITEM_DEFINE_INDEX6]
      ,[INVENTORY_COUNT6]
  FROM [dbo].[TB_ITEM_DISJOINT]
 WHERE [IDX]=@IDX
' 
END
GO
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[GP_VERIFY_ITEM_DISJOINT]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'
/**********************************************************************
 *<
	FILE: GP_VERIFY_ITEM_DISJOINT.SQL

	DESCRIPTION:

	CREATED BY:

	HISTORY:

 *>	Copyright (c) 2008, All Rights Reserved.
 **********************************************************************/

CREATE PROCEDURE [dbo].[GP_VERIFY_ITEM_DISJOINT]
	(@COUNT    [int]OUTPUT
	,@RETVALUE [int]OUTPUT)

AS

SET NOCOUNT ON

DECLARE @MAX [int]

SELECT @COUNT=COUNT(IDX)
      ,@MAX  =MAX(IDX)
  FROM [dbo].[TB_ITEM_DISJOINT]
  
SET @RETVALUE = @COUNT - @MAX
' 
END
GO
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[GP_ITEM_DISJOINT_INSERT]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'
/**********************************************************************
 *<
	FILE: GP_ITEM_DISJOINT_INSERT.SQL

	DESCRIPTION:

	CREATED BY:

	HISTORY:

 *>	Copyright (c) 2008, All Rights Reserved.
 **********************************************************************/

CREATE PROCEDURE [dbo].[GP_ITEM_DISJOINT_INSERT]
	(@INDEX					[int]			--기획:분류번호
    ,@PRICE					[int]			--가격
    ,@ITEM_DEFINE_INDEX1	[int]
    ,@INVENTORY_COUNT1		[smallint]
    ,@ITEM_DEFINE_INDEX2	[int]
    ,@INVENTORY_COUNT2		[smallint]
    ,@ITEM_DEFINE_INDEX3	[int]
    ,@INVENTORY_COUNT3		[smallint]
    ,@ITEM_DEFINE_INDEX4	[int]
    ,@INVENTORY_COUNT4		[smallint]
    ,@ITEM_DEFINE_INDEX5	[int]
    ,@INVENTORY_COUNT5		[smallint]
    ,@ITEM_DEFINE_INDEX6	[int]
    ,@INVENTORY_COUNT6		[smallint]
    ,@RETVALUE				[int]OUTPUT)	--반환값

AS

SET NOCOUNT ON

DECLARE @ERRORCODE		[int]
DECLARE @ROWCOUNT		[int]

INSERT [dbo].[TB_ITEM_DISJOINT]
	   ([INDEX]
       ,[PRICE]
       ,[ITEM_DEFINE_INDEX1]
       ,[INVENTORY_COUNT1]
       ,[ITEM_DEFINE_INDEX2]
       ,[INVENTORY_COUNT2]
       ,[ITEM_DEFINE_INDEX3]
       ,[INVENTORY_COUNT3]
       ,[ITEM_DEFINE_INDEX4]
       ,[INVENTORY_COUNT4]
       ,[ITEM_DEFINE_INDEX5]
       ,[INVENTORY_COUNT5]
       ,[ITEM_DEFINE_INDEX6]
       ,[INVENTORY_COUNT6])

VALUES (@INDEX
       ,@PRICE
       ,@ITEM_DEFINE_INDEX1
       ,@INVENTORY_COUNT1
       ,@ITEM_DEFINE_INDEX2
       ,@INVENTORY_COUNT2
       ,@ITEM_DEFINE_INDEX3
       ,@INVENTORY_COUNT3
       ,@ITEM_DEFINE_INDEX4
       ,@INVENTORY_COUNT4
       ,@ITEM_DEFINE_INDEX5
       ,@INVENTORY_COUNT5
       ,@ITEM_DEFINE_INDEX6
       ,@INVENTORY_COUNT6)

SELECT @ERRORCODE=@@ERROR, @ROWCOUNT=@@ROWCOUNT

IF @ERRORCODE <> 0 OR @ROWCOUNT <> 1
	BEGIN
		SET @RETVALUE = -1	--등록실패
	END
ELSE
	BEGIN
		SET @RETVALUE = 0	--등록성공
	END
' 
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[GP_CHARACTER_DEFALUTSKILL_INSERT]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'











/**********************************************************************
 *<
	FILE: GP_CHARACTER_DEFALUTSKILL_INSERT.SQL

	DESCRIPTION:

	CREATED BY:

	HISTORY:

 *>	Copyright (c) 2006, All Rights Reserved.
 **********************************************************************/

CREATE PROCEDURE [dbo].[GP_CHARACTER_DEFALUTSKILL_INSERT]
(
	@CHARACTER_IDX [int],
	@JOB_STEP		[int],
	@CHARACTER_RACE [tinyint],
	@RETVALUE		[int]OUTPUT
)

AS

SET NOCOUNT ON


DECLARE @ERRORCODE			[int]
DECLARE @ROWCOUNT			[int]


SELECT	@ROWCOUNT = COUNT(*)
FROM	[dbo].[TB_DEFAULT_SKILL]
WHERE	[SKILL_IDX]	NOT IN (SELECT [SKILL_IDX] FROM [dbo].[TB_SKILLLIST_PC])
AND		[JOB_STEP] = @JOB_STEP
AND		[RACE_TYPE] = @CHARACTER_RACE

IF @ROWCOUNT <> 0
BEGIN
	SET @RETVALUE = 1		-- 기본스킬 입력용 데이타 오류
	RETURN
END


SELECT	@ROWCOUNT = COUNT(*)
FROM	[TB_CHARACTER_SKILL]
WHERE	[CHARACTER_IDX] = @CHARACTER_IDX
AND		[SKILL_IDX] IN 
(	SELECT	[SKILL_IDX] 
	FROM	[dbo].[TB_DEFAULT_SKILL]
	WHERE	[JOB_STEP] = @JOB_STEP
	AND		[RACE_TYPE] = @CHARACTER_RACE
)

IF @ROWCOUNT <> 0
BEGIN
	SET @RETVALUE = 2		-- 중복 등록 오류
	RETURN
END


BEGIN TRAN

INSERT INTO TB_CHARACTER_SKILL
(
	[CHARACTER_IDX],
	[SKILL_IDX],
	[SKILL_STEP],
	[END_COOLTIME]
)
(
	SELECT		@CHARACTER_IDX, [SKILL_IDX], 0, GETDATE()
	FROM		[dbo].[TB_DEFAULT_SKILL]
	WHERE		[JOB_STEP] = @JOB_STEP
	AND			[RACE_TYPE] = @CHARACTER_RACE
)

--스킬 수량 확인.
SELECT @ERRORCODE = @@ERROR, @ROWCOUNT = @@ROWCOUNT
IF	@ERRORCODE <> 0 
OR	@ROWCOUNT <> 
		(	SELECT	COUNT(*)	
			FROM	[dbo].[TB_DEFAULT_SKILL]
			WHERE	[JOB_STEP] = @JOB_STEP
			AND		[RACE_TYPE] = @CHARACTER_RACE
		)
BEGIN
	ROLLBACK TRAN
	SET @RETVALUE = 3		-- 입력 수량 오류
	RETURN
END


COMMIT TRAN
SET @RETVALUE = 0








' 
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[GP_DEFAULT_SKILL_INSERT]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'


/**********************************************************************
 *<
	FILE: GP_DEFAULTSKILL_INSERT.SQL

	DESCRIPTION:

	CREATED BY:

	HISTORY:

 *>	Copyright (c) 2007, All Rights Reserved.
 **********************************************************************/

CREATE PROCEDURE [dbo].[GP_DEFAULT_SKILL_INSERT]
(
	@JOB_STEP			[int],
	@SKILL_IDX			[int],
	@RACE_TYPE			[tinyint],
	@RETVALUE			[int]OUTPUT
)
AS

SET NOCOUNT ON

DECLARE @ERRORCODE		[int]
DECLARE @ROWCOUNT		[int]

INSERT [dbo].[TB_DEFAULT_SKILL]
(
	[JOB_STEP],
	[SKILL_IDX],
	[RACE_TYPE]
)
VALUES	
(
	@JOB_STEP,
	@SKILL_IDX,
	@RACE_TYPE
)
       
SELECT @ERRORCODE=@@ERROR, @ROWCOUNT=@@ROWCOUNT

IF @ERRORCODE <> 0 OR @ROWCOUNT <> 1
	BEGIN
		SET @RETVALUE = -1	--등록실패
	END
ELSE
	BEGIN
		SET @RETVALUE = 0	--등록성공
	END


' 
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[GP_CHARACTER_SKILL_RESET]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'


/**********************************************************************
 *<
	FILE: GP_CHARACTER_SKILL_RESET.SQL

	DESCRIPTION:

	CREATED BY:

	HISTORY:

 *>	Copyright (c) 2006, All Rights Reserved.
 **********************************************************************/

CREATE PROCEDURE [dbo].[GP_CHARACTER_SKILL_RESET]
(
	@CHARACTER_IDX	[int],
	@CHARACTER_RACE [tinyint],
	@JOB_STEP		[int],
	@INVENTORY_IDX	[int],			--사용아이템
	@RETVALUE		[int]OUTPUT
)

AS

set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON

SET NOCOUNT ON

BEGIN TRAN

--사용 아이템
IF @INVENTORY_IDX > 0
BEGIN
	-- 아이템 수량 감소
	UPDATE [DBO].[TB_INVENTORY]
	   SET [COUNT]=[COUNT]-1
	 WHERE [IDX]=@INVENTORY_IDX

	IF @@ERROR <> 0 OR @@ROWCOUNT <> 1
		BEGIN
			SET @RETVALUE = 1
			ROLLBACK TRAN
			RETURN
		END

	-- 갯수가 0이면 사용 안함 플레그 설정
	UPDATE [dbo].[TB_INVENTORY]
	   SET [APPLY]=1
	 WHERE [IDX]=@INVENTORY_IDX
	   AND [COUNT]=0

	IF @@ERROR <> 0 OR @@ROWCOUNT > 1
		BEGIN
			SET @RETVALUE = 2
			ROLLBACK TRAN
			RETURN
		END
END

-- 캐릭터 테이블에 스킬포인트 증가
UPDATE		[DBO].[TB_CHARACTER]
SET			[SKILL_POINT_REMAIN] = [SKILL_POINT_TOTAL]
WHERE		[IDX] = @CHARACTER_IDX

IF @@ERROR <> 0 OR @@ROWCOUNT <> 1
	BEGIN
		SET @RETVALUE = 3
		ROLLBACK TRAN
		RETURN
	END

-- 기존에 보유한 모든 스킬 제거
DELETE FROM	[DBO].[TB_CHARACTER_SKILL]
WHERE		[CHARACTER_IDX] = @CHARACTER_IDX;

IF @@ERROR <> 0
	BEGIN
		SET @RETVALUE = 4
		ROLLBACK TRAN
		RETURN
	END


-- 자동 지급 스킬
INSERT INTO TB_CHARACTER_SKILL(	[CHARACTER_IDX], [SKILL_IDX], [SKILL_STEP], [END_COOLTIME] )
(
	SELECT		@CHARACTER_IDX, [SKILL_IDX], 0, GETDATE()
	FROM		[dbo].[TB_DEFAULT_SKILL]
	WHERE		[JOB_STEP] <= @JOB_STEP
	AND			[RACE_TYPE] = @CHARACTER_RACE
)

DECLARE		@CNT [int]

/*
SELECT	@CNT = COUNT(*)	
FROM	[dbo].[TB_DEFAULT_SKILL]
WHERE	[JOB_STEP] <= @JOB_STEP
AND		[RACE_TYPE] = @CHARACTER_RACE
*/

--스킬 수량 확인.
IF	@@ERROR <> 0 -- OR	@@ROWCOUNT <> @CNT
	BEGIN
		ROLLBACK TRAN
		SET @RETVALUE = 5		-- 입력 수량 오류
		RETURN
	END

COMMIT TRAN

-- 자동 습득 스킬
SELECT		[SKILL_IDX],
			[SKILL_STEP]			
FROM		[dbo].[TB_CHARACTER_SKILL]
WHERE		[CHARACTER_IDX] = @CHARACTER_IDX

SELECT		[IDX],
			(SELECT [IDX] FROM [dbo].[TB_ITEM_DEFINE] WHERE [INDEX]=[ITEM_DEFINE_INDEX]) AS ''ITEM_DEFINE_IDX'',
			[ITEM_DEFINE_INDEX],
			[NUMBER],
			[COUNT],
			[ENHANCED],
			[CARD_SLOT1],
			[CARD_SLOT2],
			[CARD_SLOT3],
			[CARD_SLOT4],
			[CARD_SLOT5],
			[SEAL],
			[APPLY]
FROM		[dbo].[TB_INVENTORY]
WHERE		[IDX]=@INVENTORY_IDX

SET @RETVALUE = 0	-- 성공


' 
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[GP_GUILD_UPDATE]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'




   
 /**********************************************************************
 *<
	FILE: GP_GUILD_UPDATE.SQL

	DESCRIPTION:

	CREATED BY:

	HISTORY:

 *>	Copyright (c) 2007, All Rights Reserved.
 **********************************************************************/
 
 CREATE PROCEDURE [dbo].[GP_GUILD_UPDATE]
				(@IDX				[int]
				,@NOTICE			[nvarchar](100)	-- 공지내용
				,@RETVALUE			[int]OUTPUT)		
        
AS

-- 적용행 출력 금지
SET NOCOUNT ON
DECLARE @ERRORCODE		[int]
DECLARE @ROWCOUNT		[int]

-- 길드 포인트 저장
UPDATE [dbo].[TB_GUILD]
   SET [NOTICE]=@NOTICE
 WHERE [IDX]=@IDX

IF @@ERROR <> 0 OR @@ROWCOUNT <> 1
	SET @RETVALUE = 1						-- 등록실패 :알수 없는 오류
ELSE
	SET @RETVALUE = 0						-- 성공


' 
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[GP_GUILD_DELETE]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'


   
 /**********************************************************************
 *<
	FILE: GP_GUILD_DELETE.SQL

	DESCRIPTION:

	CREATED BY:

	HISTORY:

 *>	Copyright (c) 2007, All Rights Reserved.
 **********************************************************************/
 
 CREATE PROCEDURE [dbo].[GP_GUILD_DELETE]
				(@IDX				[int]
				,@CHARACTER_IDX		[int]
				,@RETVALUE			[int]OUTPUT)		
        
AS

-- 적용행 출력 금지
SET NOCOUNT ON
DECLARE @ERRORCODE		[int]
DECLARE @ROWCOUNT		[int]

BEGIN TRAN

--/// 1. 길드 유저 삭제
UPDATE [dbo].[TB_GUILD_USER]
   SET [APPLY]=1
 WHERE [INDEX]=@IDX AND [CHARACTER_IDX]=@CHARACTER_IDX AND [APPLY]=0
 
IF @@ERROR <> 0 OR @@ROWCOUNT <> 1
	BEGIN
		SET @RETVALUE = 1
		GOTO ROLLBACK_TRAN
	END

--/// 2. 길드 삭제
UPDATE [dbo].[TB_GUILD]
   SET [APPLY]=1
 WHERE [IDX]=@IDX AND [MASTER_IDX]=@CHARACTER_IDX AND [APPLY]=0

IF @@ERROR <> 0 OR @@ROWCOUNT <> 1
	BEGIN
		SET @RETVALUE = 2
		GOTO ROLLBACK_TRAN
	END

--/// 3. 플레이어 길드 정보 삭제
UPDATE [dbo].[TB_CHARACTER]
   SET [GUILD_INDEX]=''0''
	 , [GUILD_POSITION]=''0''
 WHERE [IDX]=@CHARACTER_IDX 

IF @@ERROR <> 0 OR @@ROWCOUNT <> 1
	BEGIN
		SET @RETVALUE = 3
		GOTO ROLLBACK_TRAN
	END
--
COMMIT TRAN
SET @RETVALUE = 0						-- 성공
RETURN
--
ROLLBACK_TRAN:
	ROLLBACK TRAN
RETURN







' 
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[GP_GUILD_SELECT]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'











    
 /**********************************************************************
 *<
	FILE: GP_GUILD_SELECT.SQL

	DESCRIPTION:

	CREATED BY:

	HISTORY:

 *>	Copyright (c) 2007, All Rights Reserved.
 **********************************************************************/
 
 CREATE PROCEDURE [dbo].[GP_GUILD_SELECT]
				(@IDX	[int])		--고유번호
        
AS

-- 적용행 출력 금지
SET NOCOUNT ON

SELECT [IDX]
	 , [NAME]
	 , [MASTER_IDX]
	 , [MASTER_NAME]
	 , [NOTICE]
	 , [MARK_IDX]
	 , [MARK]
	 , [APPLY]
  FROM [dbo].[TB_GUILD]
 WHERE [IDX]=@IDX












' 
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[GP_GUILDMARK_UPDATE]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'









   
 /**********************************************************************
 *<
	FILE: GP_GUILDMARK_UPDATE.SQL

	DESCRIPTION:

	CREATED BY:

	HISTORY:

 *>	Copyright (c) 2007, All Rights Reserved.
 **********************************************************************/
 
 CREATE PROCEDURE [dbo].[GP_GUILDMARK_UPDATE]
				(@IDX				int
				,@MARK_INDEX		int				-- 마크인덱스
				,@MARK				binary(2348)		-- 마크
				--,@MARK				varbinary(4096)		-- 마크
				,@RETVALUE			int OUTPUT)		
        
AS

-- 적용행 출력 금지
SET NOCOUNT ON
DECLARE @ERRORCODE		[int]
DECLARE @ROWCOUNT		[int]

UPDATE [dbo].[TB_GUILD]
   SET [MARK_IDX]=@MARK_INDEX
	  ,[MARK]=@MARK
 WHERE [IDX]=@IDX

IF @@ERROR <> 0 OR @@ROWCOUNT <> 1
	SET @RETVALUE = 1						-- 등록실패 :알수 없는 오류
ELSE
	SET @RETVALUE = 0						-- 성공







' 
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[GP_CHARACTER_RECIPE_COOLTIME]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'
/**********************************************************************
 *<
	FILE: GP_CHARACTER_RECIPE_COOLTIME.SQL

	DESCRIPTION:

	CREATED BY: PKH

	HISTORY: 2009/01/20

 *>	Copyright (c) 2006, All Rights Reserved.
 **********************************************************************/

CREATE PROCEDURE [dbo].[GP_CHARACTER_RECIPE_COOLTIME]
(
	@CHARACTER_IDX	[int],
	@MAKE_SKILL		[tinyint],
	@RECIPE_IDX		[int],
	@END_COOLTIME	[int],
	@RETVALUE		[int]OUTPUT
)

AS

DECLARE @ERRORCODE			[int]
DECLARE @ROWCOUNT			[int]

SET NOCOUNT ON

BEGIN TRAN

-- 쿨타임 갱신
UPDATE	[dbo].[TB_CHARACTER_MAKESKILL]
SET		[COOL_TIME] = DATEADD( second, @END_COOLTIME, GETDATE() )
WHERE	[CHARACTER_IDX] = @CHARACTER_IDX
AND		[MAKESKILL] = @MAKE_SKILL
AND		[RECIPE_IDX] = @RECIPE_IDX

SELECT @ERRORCODE=@@ERROR, @ROWCOUNT=@@ROWCOUNT

IF @ERRORCODE <> 0 OR @ROWCOUNT <> 1
BEGIN
	SET @RETVALUE = 1
	ROLLBACK TRAN
END

ELSE

BEGIN
	SET @RETVALUE = 0			--등록성공
	COMMIT TRAN
END










' 
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[GP_CHARACTER_RECIPE_INSERT]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'





/**********************************************************************
 *<
	FILE: GP_CHARACTER_RECIPE_INSERT.SQL

	DESCRIPTION:

	CREATED BY: PKH

	HISTORY:

 *>	Copyright (c) 2009, All Rights Reserved.
 **********************************************************************/

CREATE PROCEDURE [dbo].[GP_CHARACTER_RECIPE_INSERT]
(
	@CHARACTER_IDX	[int],			-- 캐릭터 고유번호
	@MAKESKILL		[tinyint],		-- 전문기술
	@RECIPE_IDX		[int],			-- 레시피
	@INVENTORY_IDX	[int],			-- 사용아이템
	@RETVALUE		[int]OUTPUT
)
AS

SET @RETVALUE = 0

DECLARE @ERRORCODE			[int]
DECLARE @ROWCOUNT			[int]

SET NOCOUNT ON

BEGIN TRAN

--사용 아이템
IF @INVENTORY_IDX > 0
BEGIN
	-- 아이템 수량 감소
	UPDATE [DBO].[TB_INVENTORY]
	   SET [COUNT]=[COUNT]-1
	 WHERE [IDX]=@INVENTORY_IDX

	IF @@ERROR <> 0 OR @@ROWCOUNT <> 1
		BEGIN
			SET @RETVALUE = 1
			ROLLBACK TRAN
			RETURN
		END

	-- 갯수가 0이면 사용 안함 플레그 설정
	UPDATE [dbo].[TB_INVENTORY]
	   SET [APPLY]=1
	 WHERE [IDX]=@INVENTORY_IDX
	   AND [COUNT]=0

	IF @@ERROR <> 0 OR @@ROWCOUNT <> 1
		BEGIN
			SET @RETVALUE = 2
			ROLLBACK TRAN
			RETURN
		END
END

INSERT INTO	[DBO].[TB_CHARACTER_MAKESKILL] ( CHARACTER_IDX, MAKESKILL, RECIPE_IDX )
VALUES		( @CHARACTER_IDX, @MAKESKILL, @RECIPE_IDX  )

SELECT		@ERRORCODE=@@ERROR, @ROWCOUNT=@@ROWCOUNT

IF @ERRORCODE <> 0 OR @ROWCOUNT <> 1
	BEGIN
		SET @RETVALUE = 3
		ROLLBACK TRAN
		RETURN
	END

SELECT		[IDX],
			(SELECT [IDX] FROM [dbo].[TB_ITEM_DEFINE] WHERE [INDEX]=[ITEM_DEFINE_INDEX]) AS ''ITEM_DEFINE_IDX'',
			[ITEM_DEFINE_INDEX],
			[NUMBER],
			[COUNT],
			[ENHANCED],
			[CARD_SLOT1],
			[CARD_SLOT2],
			[CARD_SLOT3],
			[CARD_SLOT4],
			[CARD_SLOT5],
			[SEAL],
			[APPLY]
FROM		[dbo].[TB_INVENTORY]
WHERE		[IDX]=@INVENTORY_IDX

SELECT @ROWCOUNT=@@ROWCOUNT

IF @ERRORCODE <> 0 OR @ROWCOUNT > 1
BEGIN
	SET @RETVALUE = 4
	ROLLBACK TRAN
	RETURN
END

SET @RETVALUE = 0
COMMIT TRAN











' 
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[GP_CHARACTER_MAKESKILL_SELECT]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'

/**********************************************************************
 *<
	FILE: GP_CHARACTER_MAKESKILL_SELECT.SQL

	DESCRIPTION:

	CREATED BY: PKH

	HISTORY:

 *>	Copyright (c) 2009, All Rights Reserved.
 **********************************************************************/

CREATE PROCEDURE [dbo].[GP_CHARACTER_MAKESKILL_SELECT]
(
	@CHARACTER_IDX	[int]	-- 캐릭터 고유번호
)

AS

SET NOCOUNT ON

BEGIN
	SELECT		[MAKESKILL],
				[RECIPE_IDX],
				DATEDIFF( second, GETDATE(), [COOL_TIME] )
	FROM		[dbo].[TB_CHARACTER_MAKESKILL]
	WHERE		[CHARACTER_IDX] = @CHARACTER_IDX

END


' 
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[GP_GUILDUSER_OUT]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'







   
 /**********************************************************************
 *<
	FILE: GP_GUILDUSER_OUT.SQL

	DESCRIPTION:

	CREATED BY:

	HISTORY:

 *>	Copyright (c) 2007, All Rights Reserved.
 **********************************************************************/
 
 CREATE PROCEDURE [dbo].[GP_GUILDUSER_OUT]
				(@IDX				[int]
				,@CHARACTER_IDX		[int]
				,@RETVALUE			[int]OUTPUT)		
        
AS

-- 적용행 출력 금지
SET NOCOUNT ON
DECLARE @ERRORCODE		[int]
DECLARE @ROWCOUNT		[int]

BEGIN TRAN

--/// 1. 길드 유저 삭제
UPDATE [dbo].[TB_GUILD_USER]
   SET [APPLY]=1
 WHERE [INDEX]=@IDX AND [CHARACTER_IDX]=@CHARACTER_IDX AND [APPLY]=0
 
IF @@ERROR <> 0 OR @@ROWCOUNT <> 1
	GOTO ROLLBACK_TRAN

--/// 2. 플레이어 길드 정보 삭제
UPDATE [dbo].[TB_CHARACTER]
   SET [GUILD_INDEX]=''0''
	 , [GUILD_POSITION]=''0''
 WHERE [IDX]=@CHARACTER_IDX 

IF @@ERROR <> 0 OR @@ROWCOUNT <> 1
	GOTO ROLLBACK_TRAN
--
COMMIT TRAN
SET @RETVALUE = 0						-- 성공
RETURN
--
ROLLBACK_TRAN:
	ROLLBACK TRAN
	SET @RETVALUE = 1						-- 등록실패 :알수 없는 오류
RETURN








' 
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[GP_GUILDUSER_SELECT]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'



    
 /**********************************************************************
 *<
	FILE: GP_GUILDUSER_SELECT.SQL

	DESCRIPTION:

	CREATED BY:

	HISTORY:

 *>	Copyright (c) 2007, All Rights Reserved.
 **********************************************************************/
 
 CREATE PROCEDURE [dbo].[GP_GUILDUSER_SELECT]
				(@GUILD_IDX		[int])
        
AS

-- 적용행 출력 금지
SET NOCOUNT ON

SELECT A.[IDX]
	 , [NAME]
	 , [LEVEL]
	 , [JOB]
	 , [MAP_NUM]
	 , [GUILD_POSITION]
FROM [dbo].[TB_CHARACTER] A
INNER JOIN [dbo].[TB_GUILD_USER] B
		ON A.[IDX] = B.[CHARACTER_IDX]
	 WHERE B.[INDEX]=@GUILD_IDX AND B.[APPLY]=0		
	   AND A.[APPLY]=0

/* 위의 소스는 아래소스를 JOIN 형태로 바꾼것
SELECT [IDX]
	 , [NAME]
	 , [LEVEL]
	 , [JOB]
	 , [MAP_NUM]
FROM [dbo].[TB_CHARACTER] 
WHERE [IDX] in ( SELECT [CHARACTER_IDX] 
				   FROM [dbo].[TB_GUILD_USER] 
				  WHERE [INDEX]=@GUILD_IDX AND [APPLY]=0 )
*/



' 
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[GP_GUILDUSER_ADD]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'

   
 /**********************************************************************
 *<
	FILE: GP_GUILDUSER_ADD.SQL

	DESCRIPTION:

	CREATED BY:

	HISTORY:

 *>	Copyright (c) 2007, All Rights Reserved.
 **********************************************************************/
 
 CREATE PROCEDURE [dbo].[GP_GUILDUSER_ADD]
				(@IDX				[int]
				,@CHARACTER_IDX		[int]
				,@RETVALUE			[int]OUTPUT)		
        
AS

-- 적용행 출력 금지
SET NOCOUNT ON
DECLARE @ERRORCODE		[int]
DECLARE @ROWCOUNT		[int]

BEGIN TRAN 

-- 길드 유저 리스트 등록
INSERT [dbo].[TB_GUILD_USER]
	   ([INDEX]
	   ,[CHARACTER_IDX])
VALUES (@IDX
       ,@CHARACTER_IDX)

IF @@ERROR <> 0 OR @@ROWCOUNT <> 1
	GOTO ROLLBACK_TRAN

-- 플레이어 길드 정보 삽입
UPDATE [dbo].[TB_CHARACTER]
   SET [GUILD_INDEX]=@IDX
	 , [GUILD_POSITION]=''6''		-- 일반유저로 세팅
 WHERE [IDX]=@CHARACTER_IDX

IF @@ERROR <> 0 OR @@ROWCOUNT <> 1
	GOTO ROLLBACK_TRAN

--
COMMIT TRAN
SET @RETVALUE = 0						-- 성공
RETURN
--
ROLLBACK_TRAN:
	ROLLBACK TRAN
	SET @RETVALUE = 1						-- 등록실패 :알수 없는 오류
RETURN

' 
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[GP_CHARACTER_DELETE]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'

/**********************************************************************
 *<
	FILE: GP_CHARACTER_DELETE.SQL

	DESCRIPTION:

	CREATED BY:

	HISTORY:

 *>	Copyright (c) 2006, All Rights Reserved.
 **********************************************************************/

CREATE PROCEDURE [dbo].[GP_CHARACTER_DELETE]
	(@IDX			[int]
	,@USER_IDX		[int]
	,@RETVALUE      [int]OUTPUT)

AS

DECLARE @ERRORCODE	[int]
DECLARE @ROWCOUNT	[int]
DECLARE @GUILD_POS	[int]

SET NOCOUNT ON

SELECT @GUILD_POS=[GUILD_POSITION]
  FROM [dbo].[TB_CHARACTER]
 WHERE [IDX]=@IDX

-- 길드내 직책이 마스터인경우 실패
IF @GUILD_POS = 1 
	BEGIN
		SET @RETVALUE = 2	--실패 - 길드마스터
		RETURN
	END

--기본
UPDATE [dbo].[TB_CHARACTER]
   SET [APPLY] = 1			--사용안함
     , [GUILD_INDEX] = 0
     , [GUILD_POSITION] = 0
 WHERE ([USER_IDX]=@USER_IDX AND [IDX]=@IDX)

SELECT @ERRORCODE = @@ERROR, @ROWCOUNT = @@ROWCOUNT

UPDATE [dbo].[TB_GUILD_USER]
   SET [APPLY] = 1
 WHERE [CHARACTER_IDX]=@USER_IDX

--부가정보[쿨타임 삭제]
DELETE [dbo].[TB_INVENTORY_COOLTIME]
 WHERE [CHARACTER_IDX]=@IDX

IF @ERRORCODE <> 0 OR @ROWCOUNT <> 1
	BEGIN
		SET @RETVALUE = 1	--삭제실패
	END
ELSE
	BEGIN
		SET @RETVALUE = 0	--삭제성공
	END
' 
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[GP_GUILD_CREATE]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'




   
 /**********************************************************************
 *<
	FILE: GP_GUILD_CREATE.SQL

	DESCRIPTION:

	CREATED BY:

	HISTORY:

 *>	Copyright (c) 2007, All Rights Reserved.
 **********************************************************************/
 
 CREATE PROCEDURE [dbo].[GP_GUILD_CREATE]
				(@IDX				[int]OUTPUT
				,@NAME				[nvarchar](50)	--길드 명
				,@MASTER_IDX		[int]			--길드 장 인덱스
				,@MASTER_NAME		[nvarchar](50)	--길드장 명
				,@MONEY				[int]			--비용
				,@RETVALUE			[int]OUTPUT)		
        
AS

-- 적용행 출력 금지
SET NOCOUNT ON
DECLARE @ERRORCODE		[int]
DECLARE @ROWCOUNT		[int]

BEGIN TRAN

-- 1. 금액 지불
UPDATE [dbo].[TB_CHARACTER]
   SET [MONEY]=[MONEY]+@MONEY
 WHERE [IDX]=@MASTER_IDX

IF @@ERROR <> 0 OR @@ROWCOUNT <> 1
	GOTO ROLLBACK_TRAN

--/// 2. 길드 등록
INSERT [dbo].[TB_GUILD]
	   ([NAME]
	   ,[MASTER_IDX]
	   ,[MASTER_NAME])
VALUES (@NAME
       ,@MASTER_IDX
	   ,@MASTER_NAME)				-- 기본으로 1명 추가

IF @@ERROR <> 0 OR @@ROWCOUNT <> 1
	GOTO ROLLBACK_TRAN

-- 고유번호 세팅
SELECT @IDX=MAX(IDX)
  FROM [dbo].[TB_GUILD]

--/// 3. 길드 유저 리스트 등록
INSERT [dbo].[TB_GUILD_USER]
	   ([INDEX]
	   ,[CHARACTER_IDX])
VALUES (@IDX
       ,@MASTER_IDX)
 
IF @@ERROR <> 0 OR @@ROWCOUNT <> 1
	GOTO ROLLBACK_TRAN

--/// 3. 플레이어 길드 정보 삽입
UPDATE [dbo].[TB_CHARACTER]
   SET [GUILD_INDEX]=@IDX
	 , [GUILD_POSITION]=''1''		-- 마스터로 세팅
 WHERE [IDX]=@MASTER_IDX

--
COMMIT TRAN
SET @RETVALUE = 0						-- 성공
RETURN
--
ROLLBACK_TRAN:
	ROLLBACK TRAN
	SET @RETVALUE = 1						-- 등록실패 :알수 없는 오류
RETURN





' 
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[GP_SHORTCUT_UPDATE]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'


/**********************************************************************
 *<
	FILE: GP_SHORTCUT_UPDATE.SQL

	DESCRIPTION:

	CREATED BY:

	HISTORY:

 *>	Copyright (c) 2007, All Rights Reserved.
 **********************************************************************/

CREATE PROCEDURE [dbo].[GP_SHORTCUT_UPDATE]
	(@CHARACTER_IDX	int				--캐릭터 고유번호
	,@DATA			varbinary(500))	--데이타

AS

SET NOCOUNT ON

DECLARE @ERRORCODE			[int]
DECLARE @ROWCOUNT			[int]

IF EXISTS (SELECT *
             FROM [dbo].[TB_SHORTCUT]
            WHERE [CHARACTER_IDX]=@CHARACTER_IDX)
	BEGIN
		UPDATE [dbo].[TB_SHORTCUT]
		   SET [BINARY]=@DATA
		 WHERE [CHARACTER_IDX]=@CHARACTER_IDX

		SELECT @ERRORCODE=@@ERROR, @ROWCOUNT=@@ROWCOUNT
	END
ELSE
	BEGIN
		INSERT [dbo].[TB_SHORTCUT]
			  ([CHARACTER_IDX]
              ,[BINARY])
        VALUES(@CHARACTER_IDX
              ,@DATA)

		SELECT @ERRORCODE=@@ERROR, @ROWCOUNT=@@ROWCOUNT
	END


' 
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[GP_SHORTCUT_SELECT]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'



/**********************************************************************
 *<
	FILE: GP_SHORTCUT_SELECT.SQL

	DESCRIPTION:

	CREATED BY:

	HISTORY:

 *>	Copyright (c) 2007, All Rights Reserved.
 **********************************************************************/

CREATE PROCEDURE [dbo].[GP_SHORTCUT_SELECT]
	(@CHARACTER_IDX	[int]
	,@ROWCOUNT		[int]OUTPUT ) --캐릭터 고유번호

AS

SET NOCOUNT ON

SELECT [BINARY]
  FROM [dbo].[TB_SHORTCUT]
 WHERE [CHARACTER_IDX]=@CHARACTER_IDX

SET @ROWCOUNT = @@ROWCOUNT



' 
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[GP_CHARACTER_SKILL_COOLTIME]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'





/**********************************************************************
 *<
	FILE: GP_CHARACTER_SKILL_COOLTIME.SQL

	DESCRIPTION:

	CREATED BY: PKH

	HISTORY: 2007/08/24

 *>	Copyright (c) 2006, All Rights Reserved.
 **********************************************************************/

CREATE PROCEDURE [dbo].[GP_CHARACTER_SKILL_COOLTIME]
(
	@CHARACTER_IDX	[int],
	@SKILL_IDX		[int],
	@END_COOLTIME	[int],
	@RETVALUE		[int]OUTPUT
)

AS

DECLARE @ERRORCODE			[int]
DECLARE @ROWCOUNT			[int]

SET NOCOUNT ON

-- 갱신할 데이타 검색
SELECT	@ROWCOUNT = COUNT(*)
FROM	[dbo].[TB_CHARACTER_SKILL]
WHERE	[CHARACTER_IDX] = @CHARACTER_IDX
AND		[SKILL_IDX] = @SKILL_IDX

SELECT @ERRORCODE=@@ERROR

IF @ERRORCODE <> 0 OR @ROWCOUNT <> 1
BEGIN
	SET @RETVALUE = 1
	RETURN
END


BEGIN TRAN

-- 쿨타임 갱신
UPDATE	[dbo].[TB_CHARACTER_SKILL]
SET		[END_COOLTIME] = DATEADD( second, @END_COOLTIME, GETDATE() )
WHERE	[CHARACTER_IDX] = @CHARACTER_IDX
AND		[SKILL_IDX] = @SKILL_IDX

SELECT @ERRORCODE=@@ERROR, @ROWCOUNT=@@ROWCOUNT

IF @ERRORCODE <> 0 OR @ROWCOUNT <> 1
BEGIN
	SET @RETVALUE = 2
	ROLLBACK TRAN
END

ELSE

BEGIN
	SET @RETVALUE = 0			--등록성공
	COMMIT TRAN
END









' 
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[GP_CHARACTER_SKILL_INSERT]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'




/**********************************************************************
 *<
	FILE: GP_CHARACTER_SKILL_INSERT.SQL

	DESCRIPTION:

	CREATED BY: PKH

	HISTORY: 2007/08/24

 *>	Copyright (c) 2006, All Rights Reserved.
 **********************************************************************/

CREATE PROCEDURE [dbo].[GP_CHARACTER_SKILL_INSERT]
(
	@CHARACTER_IDX	[int],
	@SKILL_IDX		[int],
	@SKILL_NEED_POINT	[smallint],
	@SKILL_LEVEL		[tinyint],
	@SKILL_POINT		[int],
	@RETVALUE		[int]OUTPUT
)

AS

SET @RETVALUE = 0

DECLARE @ERRORCODE			[int]
DECLARE @ROWCOUNT			[int]
DECLARE @SELECT_SKILL_POINT	[int]
DECLARE @SELECT_SKILL_LEVEL	[tinyint]

SET NOCOUNT ON

-- 중복 체크
IF EXISTS (SELECT * FROM [dbo].[TB_CHARACTER_SKILL] WHERE [CHARACTER_IDX]=@CHARACTER_IDX AND [SKILL_IDX]=@SKILL_IDX)
	BEGIN
		SET @RETVALUE = 1
		RETURN
	END

/*
-- 스킬 목록 확인
IF NOT EXISTS (SELECT * FROM [dbo].[TB_SKILLLIST_PC] WHERE [SKILL_IDX]=@SKILL_IDX)
	BEGIN
		SET @RETVALUE = 2
		RETURN
	END
*/

-- 스킬 포인트 확인
SELECT	@SELECT_SKILL_POINT = SKILL_POINT_REMAIN,
		@SELECT_SKILL_LEVEL = SKILL_LEVEL
FROM	[dbo].[TB_CHARACTER]
WHERE	[IDX]=@CHARACTER_IDX

IF @SELECT_SKILL_POINT < @SKILL_NEED_POINT
	BEGIN
		SET @RETVALUE = 3
	END

BEGIN TRAN

-- 스킬 포인트 감소
UPDATE	[dbo].[TB_CHARACTER]
SET		SKILL_POINT_REMAIN = @SKILL_POINT,
		SKILL_LEVEL = @SKILL_LEVEL
WHERE	[IDX]=@CHARACTER_IDX

SELECT @ERRORCODE=@@ERROR, @ROWCOUNT=@@ROWCOUNT

IF @ERRORCODE <> 0 OR @ROWCOUNT <> 1
	BEGIN
		SET @RETVALUE = 4
		ROLLBACK TRAN
		RETURN
	END

-- 스킬 생성
INSERT [dbo].[TB_CHARACTER_SKILL]
(
		[CHARACTER_IDX],
		[SKILL_IDX],
		[SKILL_STEP],
		[END_COOLTIME]
)
VALUES 
(
		@CHARACTER_IDX,
		@SKILL_IDX,
		0,
		GETDATE()
)

SELECT @ERRORCODE=@@ERROR, @ROWCOUNT=@@ROWCOUNT

IF @ERRORCODE <> 0 OR @ROWCOUNT <> 1
	BEGIN
		SET @RETVALUE = 5
		ROLLBACK TRAN
	END

ELSE

	BEGIN
		COMMIT TRAN
	END





























' 
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[GP_CHARACTER_SKILL_UPDATE]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'


/**********************************************************************
 *<
	FILE: GP_CHARACTER_SKILL_UPDATE.SQL

	DESCRIPTION:

	CREATED BY: PKH

	HISTORY: 2007/08/24

 *>	Copyright (c) 2006, All Rights Reserved.
 **********************************************************************/

CREATE PROCEDURE [dbo].[GP_CHARACTER_SKILL_UPDATE]
(
	@CHARACTER_IDX	[int],
	@SKILL_IDX		[int],
	@SKILL_STEP		[tinyint],
	@SKILL_NEED_POINT	[smallint],
	@SKILL_LEVEL	[tinyint],
	@SKILL_POINT	[int],
	@RETVALUE		[int]OUTPUT
)

AS

DECLARE @ERRORCODE			[int]
DECLARE @ROWCOUNT			[int]
DECLARE @SELECT_SKILL_LEVEL	[int]
DECLARE @SELECT_SKILL_POINT	[int]

SET NOCOUNT ON

SET @RETVALUE = 0

-- 보유 스킬 확인
SELECT	*
FROM	[dbo].[TB_CHARACTER_SKILL]
WHERE	[CHARACTER_IDX] = @CHARACTER_IDX
AND		[SKILL_IDX] = @SKILL_IDX

SELECT @ERRORCODE=@@ERROR, @ROWCOUNT=@@ROWCOUNT

IF @ERRORCODE <> 0 OR @ROWCOUNT <> 1
	BEGIN
		SET @RETVALUE = 1
		RETURN
	END

-- 스킬포인트 확인
SELECT	@SELECT_SKILL_LEVEL = SKILL_LEVEL,
		@SELECT_SKILL_POINT = SKILL_POINT_REMAIN		
FROM	[dbo].[TB_CHARACTER]
WHERE	[IDX]=@CHARACTER_IDX

IF @SELECT_SKILL_POINT < @SKILL_NEED_POINT
	BEGIN
		SET @RETVALUE = 2
	END

BEGIN TRAN

-- 스킬 포인트 갱신
UPDATE	[dbo].[TB_CHARACTER]
SET		SKILL_POINT_REMAIN = @SKILL_POINT,
		SKILL_LEVEL = @SKILL_LEVEL
WHERE	[IDX]=@CHARACTER_IDX

SELECT @ERRORCODE=@@ERROR, @ROWCOUNT=@@ROWCOUNT

IF @ERRORCODE <> 0 OR @ROWCOUNT <> 1
	BEGIN
		SET @RETVALUE = 3
		ROLLBACK TRAN
		RETURN
	END

-- 스킬 단계 갱신
UPDATE	[dbo].[TB_CHARACTER_SKILL]
SET		[SKILL_STEP] = @SKILL_STEP
WHERE	[CHARACTER_IDX] = @CHARACTER_IDX
AND		[SKILL_IDX] = @SKILL_IDX

SELECT @ERRORCODE=@@ERROR, @ROWCOUNT=@@ROWCOUNT

IF @ERRORCODE <> 0 OR @ROWCOUNT <> 1
	BEGIN
		SET @RETVALUE = 4
		ROLLBACK TRAN
	END

ELSE

	BEGIN
		COMMIT TRAN
	END


















' 
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[GP_CHARACTER_SKILL_SELECT]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'





/**********************************************************************
 *<
	FILE: GP_CHARACTER_SKILL_SELECT.SQL

	DESCRIPTION:

	CREATED BY:

	HISTORY:

 *>	Copyright (c) 2007, All Rights Reserved.
 **********************************************************************/

CREATE PROCEDURE [dbo].[GP_CHARACTER_SKILL_SELECT]
(
	@CHARACTER_IDX	[int]	-- 캐릭터 고유번호
)

AS

SET NOCOUNT ON

BEGIN
/*
	SELECT		[SKILL_IDX],
				[SKILL_STEP],
				DATEDIFF( second, GETDATE(), [END_COOLTIME] )
	FROM		[dbo].[TB_CHARACTER_SKILL]
	WHERE		[CHARACTER_IDX] = @CHARACTER_IDX
	AND			[SKILL_IDX] IN ( SELECT [SKILL_IDX] FROM [dbo].[TB_SKILLLIST_PC] )
*/

	SELECT		[SKILL_IDX],
				[SKILL_STEP],
				DATEDIFF( second, GETDATE(), [END_COOLTIME] )
	FROM		[dbo].[TB_CHARACTER_SKILL]
	WHERE		[CHARACTER_IDX] = @CHARACTER_IDX

END



' 
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[GP_CHARACTER_BLOCK_SELECT]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'



/**********************************************************************
 *<
	FILE: GP_CHARACTER_BLOCK_SELECT.SQL

	DESCRIPTION:

	CREATED BY:

	HISTORY:

 *>	Copyright (c) 2009, All Rights Reserved.
 **********************************************************************/

CREATE PROCEDURE [dbo].[GP_CHARACTER_BLOCK_SELECT]
	(@CHARACTER_IDX	[int]			--캐릭터 고유번호
	,@ROWCOUNT		[int]OUTPUT)	--적용행수

AS

SET NOCOUNT ON

SELECT TOP 1
	   DATEDIFF(SECOND, GETDATE(), [VALID_THRU]) AS ''VALID_THRU''
  FROM [dbo].[TB_CHARACTER_BLOCK]
 WHERE [BLOCK_CHARACTER_IDX]=@CHARACTER_IDX
   AND [APPLY]=0
 ORDER BY [IDX] DESC

SET @ROWCOUNT=@@ROWCOUNT



' 
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[GP_CHARACTER_BLOCK_INSERT]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'


/**********************************************************************
 *<
	FILE: GP_CHARACTER_BLOCK_INSERT.SQL

	DESCRIPTION:

	CREATED BY:

	HISTORY:

 *>	Copyright (c) 2009, All Rights Reserved.
 **********************************************************************/

CREATE PROCEDURE [dbo].[GP_CHARACTER_BLOCK_INSERT]
	(@BLOCK_CHARACTER_IDX	[int]
	,@ADMIN_CHARACTER_IDX	[int]
	,@VALID_THRU			[int])

AS

SET NOCOUNT ON

DECLARE @VALID_THRU2 [datetime]
    SET @VALID_THRU2 = DATEADD(SECOND, @VALID_THRU, GETDATE())

INSERT [dbo].[TB_CHARACTER_BLOCK]
	  ([BLOCK_CHARACTER_IDX]
      ,[ADMIN_CHARACTER_IDX]
      ,[VALID_THRU])
VALUES(@BLOCK_CHARACTER_IDX
      ,@ADMIN_CHARACTER_IDX
      ,@VALID_THRU2)

IF @@ERROR <> 0 OR @@ROWCOUNT <> 1
	BEGIN
		RETURN 99 -- 적용실패
	END

' 
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[GP_SKILLLIST_PC_INSERT]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'






/**********************************************************************
 *<
	FILE: GP_SKILLLIST_PC_INSERT.SQL

	DESCRIPTION:

	CREATED BY:

	HISTORY:

 *>	Copyright (c) 2007, All Rights Reserved.
 **********************************************************************/

CREATE PROCEDURE [dbo].[GP_SKILLLIST_PC_INSERT]
	(@SKILLIDX			[int]
	,@NAMEIDX			[int]
	,@ICONIDX			[int]
	,@RACE				[tinyint]
	,@LEARNSKILLIDX1	[int]
	,@LEARNSKILLSTEP1	[tinyint]
	,@LEARNSKILLIDX2	[int]
	,@LEARNSKILLSTEP2	[tinyint]
	,@USEEQUIPMENT		[tinyint]
	,@USESTATE			[tinyint]
	,@USEITEM			[int]
	,@TYPE				[int]
	,@ATTRIBUTETYPE		[int]
	,@SHOTTYPE			[int]
	,@BOUNDTYPE			[int]
	,@APPLYTYPE			[int]
	,@RANGETYPE			[int]
	,@ISGLOBALCOOLTIME	[tinyint]
	,@GROUPCOOLTIMEIDX	[int]
	,@STEPMAX			[int]
	,@RETVALUE			[int]OUTPUT
)
AS

SET NOCOUNT ON

DECLARE @ERRORCODE		[int]
DECLARE @ROWCOUNT		[int]

INSERT [dbo].[TB_SKILLLIST_PC]
		([SKILL_IDX]
		,[NAME_IDX]
		,[ICON_IDX]
		,[RACE]
		,[LEARNSKILLIDX1]
		,[LEARNSKILLSTEP1]
		,[LEARNSKILLIDX2]
		,[LEARNSKILLSTEP2]
		,[USEEQUIPMENT]
		,[USESTATE]
		,[USEITEM]
		,[TYPE]
		,[ATTRIBUTETYPE]
		,[SHOTTYPE]
		,[BOUNDTYPE]
		,[APPLYTYPE]
		,[RANGETYPE]
		,[ISGLOBALCOOLTIME]
		,[GROUPCOOLTIMEIDX]
		,[STEPMAX]
		)
VALUES	(@SKILLIDX	
		,@NAMEIDX	
		,@ICONIDX	
		,@RACE	
		,@LEARNSKILLIDX1	
		,@LEARNSKILLSTEP1	
		,@LEARNSKILLIDX2	
		,@LEARNSKILLSTEP2	
		,@USEEQUIPMENT	
		,@USESTATE	
		,@USEITEM	
		,@TYPE	
		,@ATTRIBUTETYPE	
		,@SHOTTYPE	
		,@BOUNDTYPE	
		,@APPLYTYPE	
		,@RANGETYPE	
		,@ISGLOBALCOOLTIME	
		,@GROUPCOOLTIMEIDX	
		,@STEPMAX	
		)
       
SELECT @ERRORCODE=@@ERROR, @ROWCOUNT=@@ROWCOUNT

IF @ERRORCODE <> 0 OR @ROWCOUNT <> 1
	BEGIN
		SET @RETVALUE = -1	--등록실패
	END
ELSE
	BEGIN
		SET @RETVALUE = 0	--등록성공
	END






' 
END
GO
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[GP_ITEM_ENHANCED_RATE_INSERT]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'
/**********************************************************************
 *<
	FILE: GP_ITEM_ENHANCED_RATE_INSERT.SQL

	DESCRIPTION:

	CREATED BY: 곽철중

	HISTORY: 08/04/28 생성

 *>	Copyright (c) 2008, All Rights Reserved.
 **********************************************************************/

CREATE PROCEDURE [dbo].[GP_ITEM_ENHANCED_RATE_INSERT]
	(@INDEX					[int]			--기획:분류번호
    ,@SUCCESS				[varchar](MAX)	--성공확률
    ,@DOWN					[varchar](MAX)	--감소확률
    ,@DESTRUCT				[varchar](MAX)	--파괴확률
    ,@RETVALUE				[int]OUTPUT)	--반환값

AS

SET NOCOUNT ON

DECLARE @ERRORCODE		[int]
DECLARE @ROWCOUNT		[int]

INSERT [dbo].[TB_ITEM_ENHANCED_RATE]
       ([INDEX]
       ,[SUCCESS]
       ,[DOWN]
       ,[DESTRUCT])
VALUES
       (@INDEX
       ,@SUCCESS
       ,@DOWN
       ,@DESTRUCT)

SELECT @ERRORCODE=@@ERROR, @ROWCOUNT=@@ROWCOUNT

IF @ERRORCODE <> 0 OR @ROWCOUNT <> 1
	BEGIN
		SET @RETVALUE = -1	--등록실패
	END
ELSE
	BEGIN
		SET @RETVALUE = 0	--등록성공
	END
' 
END
GO
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[GP_ITEM_ENHANCED_RATE_SELECT]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'
/**********************************************************************
 *<
	FILE: GP_ITEM_ENHANCED_RATE_SELECT.SQL

	DESCRIPTION:  TB_ITEM_ENHANCED_RATE분할 로딩.

	CREATED BY: 곽철중

	HISTORY: 08/03/26 생성

 *>	Copyright (c) 2008, All Rights Reserved.
 **********************************************************************/

CREATE PROCEDURE [dbo].[GP_ITEM_ENHANCED_RATE_SELECT]
	(@IDX	[int])		--고유번호

AS

SET NOCOUNT ON

SELECT [IDX]
      ,[INDEX]
      ,[SUCCESS]
      ,[DOWN]
      ,[DESTRUCT]
  FROM [dbo].[TB_ITEM_ENHANCED_RATE]
 WHERE [IDX]=@IDX
' 
END
GO
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[GP_VERIFY_ITEM_ENHANCED_RATE]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'
/**********************************************************************
 *<
	FILE: GP_VERIFY_ITEM_ENHANCED_RATE.SQL

	DESCRIPTION:

	CREATED BY:

	HISTORY:

 *>	Copyright (c) 2008, All Rights Reserved.
 **********************************************************************/

CREATE PROCEDURE [dbo].[GP_VERIFY_ITEM_ENHANCED_RATE]
	(@COUNT    [int]OUTPUT
	,@RETVALUE [int]OUTPUT)

AS

SET NOCOUNT ON

DECLARE @MAX [int]

SELECT @COUNT=COUNT(IDX)
      ,@MAX  =MAX(IDX)
  FROM [dbo].[TB_ITEM_ENHANCED_RATE]
  
SET @RETVALUE = @COUNT - @MAX
' 
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[GP_INVENTORY_COOLTIME_INSERT]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'

 

/**********************************************************************
 *<
	FILE: GP_INVENTORY_COOLTIME_INSERT.SQL

	DESCRIPTION:

	CREATED BY:

	HISTORY:

 *>	Copyright (c) 2008, All Rights Reserved.
 **********************************************************************/

CREATE PROCEDURE [dbo].[GP_INVENTORY_COOLTIME_INSERT]
	(@CHARACTER_IDX		[int]	--캐릭터 고유번호
	,@ITEM_DEFINE_INDEX	[int]	--아이템 정의 인덱스
	,@COOL_TIME1		[int]	--총 적용 시간
	,@COOL_TIME2		[int]	--그룹 번호
	,@COOL_TIME			[int])	--적용시간

AS

SET NOCOUNT ON

DECLARE @VALID_THRU		[datetime]

--쿨타임 적용중 검사
IF NOT EXISTS (SELECT *
				 FROM [dbo].[TB_INVENTORY_COOLTIME]
				WHERE [CHARACTER_IDX]=@CHARACTER_IDX
				  AND [ITEM_DEFINE_INDEX]=@ITEM_DEFINE_INDEX
				  AND [VALID_THRU]>GETDATE())
	BEGIN
		SET @VALID_THRU = DATEADD(MS, @COOL_TIME, GETDATE())

		INSERT [dbo].[TB_INVENTORY_COOLTIME]
			   ([VALID_THRU]
			   ,[CHARACTER_IDX]
			   ,[ITEM_DEFINE_INDEX]
			   ,[COOL_TIME1]
			   ,[COOL_TIME2])

		VALUES (@VALID_THRU
			   ,@CHARACTER_IDX
			   ,@ITEM_DEFINE_INDEX
			   ,@COOL_TIME1
			   ,@COOL_TIME2)
	END
' 
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[GP_SHUTDOWN]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'

/**********************************************************************
 *<
	FILE: GP_SHUTDOWN.SQL

	DESCRIPTION:

	CREATED BY:

	HISTORY:

 *>	Copyright (c) 2007, All Rights Reserved.
 **********************************************************************/

CREATE PROCEDURE [dbo].[GP_SHUTDOWN]
	(@CHANNEL_NUM				[int]			--채널번호
	,@REMOVE_COOLTIME_COUNT		[int]OUTPUT		--영향받은 행 수
	,@REMOVE_STALL_SELL_COUNT	[int]OUTPUT)	--영향받은 행 수

AS

SET NOCOUNT ON -- 영향받은 행의 갯수를 반환하지 않는다.

--CLEAR TB_INVENTORY_COOLTIME
DELETE [dbo].[TB_INVENTORY_COOLTIME]
 WHERE [VALID_THRU]<GETDATE()

SELECT @REMOVE_COOLTIME_COUNT=@@ROWCOUNT

--CLEAR TB_STALL_SELL
UPDATE [dbo].[TB_STALL_SELL]
   SET [APPLY]=1
 WHERE [CHANNEL_NUM]=@CHANNEL_NUM
   AND [APPLY]=0

SELECT @REMOVE_STALL_SELL_COUNT=@@ROWCOUNT
' 
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[GP_INVENTORY_COOLTIME_SELECT]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'
 

/**********************************************************************
 *<
	FILE: GP_INVENTORY_COOLTIME_SELECT.SQL

	DESCRIPTION:

	CREATED BY:

	HISTORY:

 *>	Copyright (c) 2007, All Rights Reserved.
 **********************************************************************/

CREATE PROCEDURE [dbo].[GP_INVENTORY_COOLTIME_SELECT]
	(@CHARACTER_IDX		[int])			--캐릭터 고유번호

AS

SET NOCOUNT ON

SELECT [ITEM_DEFINE_INDEX]
	  ,[COOL_TIME2]
	  ,DATEDIFF(MS, GETDATE(), [VALID_THRU]) AS ''COOL_TIME''
	  ,[COOL_TIME1]
  FROM [dbo].[TB_INVENTORY_COOLTIME]
 WHERE [CHARACTER_IDX]=@CHARACTER_IDX
   AND [VALID_THRU]>GETDATE()
' 
END
GO
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[GP_FRIEND_DELETE]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'
/**********************************************************************
 *<
	FILE: GP_FRIEND_DELETE.SQL

	DESCRIPTION:

	CREATED BY:

	HISTORY:

 *>	Copyright (c) 2007, All Rights Reserved.
 **********************************************************************/

CREATE PROCEDURE [dbo].[GP_FRIEND_DELETE]
	(@IDX1				[int]			--고유번호
	,@CHARACTER_IDX1	[int]			--캐릭터 고유번호
	,@CHARACTER_IDX2	[int]OUTPUT)	--캐릭터 고유번호

AS

SET NOCOUNT ON

SELECT @CHARACTER_IDX2=[CHARACTER_IDX2]
  FROM [dbo].[TB_FRIEND]
 WHERE [IDX]=@IDX1
   AND [CHARACTER_IDX1]=@CHARACTER_IDX1

--신청
UPDATE [dbo].[TB_FRIEND]
   SET [APPLY]=1			--삭제.
 WHERE [IDX]=@IDX1
   AND [CHARACTER_IDX1]=@CHARACTER_IDX1

--대상
UPDATE [dbo].[TB_FRIEND]
   SET [BLOCK]=1			--차단.
 WHERE [CHARACTER_IDX1]=@CHARACTER_IDX2
   AND [CHARACTER_IDX2]=@CHARACTER_IDX1
' 
END
GO
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[GP_FRIEND_UPDATE]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'
/**********************************************************************
 *<
	FILE: GP_FRIEND_UPDATE.SQL

	DESCRIPTION:

	CREATED BY:

	HISTORY:

 *>	Copyright (c) 2007, All Rights Reserved.
 **********************************************************************/

CREATE PROCEDURE [dbo].[GP_FRIEND_UPDATE]
	(@IDX1				[int]			--고유번호
	,@CHARACTER_IDX1	[int]			--캐릭터 고유번호
	,@CHARACTER_IDX2	[int]OUTPUT)	--캐릭터 고유번호

AS

SET NOCOUNT ON

SELECT @CHARACTER_IDX2=[CHARACTER_IDX2]
  FROM [dbo].[TB_FRIEND]
 WHERE [IDX]=@IDX1
   AND [CHARACTER_IDX1]=@CHARACTER_IDX1

--신청
UPDATE [dbo].[TB_FRIEND]
   SET [STATUS]=0			--신청수락.
 WHERE [IDX]=@IDX1
   AND [CHARACTER_IDX1]=@CHARACTER_IDX1

--대상
UPDATE [dbo].[TB_FRIEND]
   SET [BLOCK]=0			--차단해제.
 WHERE [CHARACTER_IDX1]=@CHARACTER_IDX2
   AND [CHARACTER_IDX2]=@CHARACTER_IDX1
' 
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[GP_FRIEND_INSERT]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N' 
/**********************************************************************
 *<
	FILE: GP_FRIEND_INSERT.SQL

	DESCRIPTION:

	CREATED BY:

	HISTORY:

 *>	Copyright (c) 2007, All Rights Reserved.
 **********************************************************************/

CREATE PROCEDURE [dbo].[GP_FRIEND_INSERT]
	(@CHARACTER_IDX1	[int]			--캐릭터 고유번호
	,@CHARACTER_IDX2	[int]OUTPUT		--받는 캐릭터(고유번호)
	,@CHARACTER_NAME	[nvarchar](16)	--캐릭터 이름(친구)
	,@RETVALUE			[int]OUTPUT)	--반환값

AS

SET NOCOUNT ON

DECLARE @ERRORCODE			[int]
DECLARE @ROWCOUNT			[int]

SELECT @CHARACTER_IDX2=[IDX]
  FROM [dbo].[TB_CHARACTER]
 WHERE [NAME]=@CHARACTER_NAME
   AND [APPLY]=0

SELECT @ERRORCODE = @@ERROR, @ROWCOUNT = @@ROWCOUNT
IF @ERRORCODE <> 0 OR @ROWCOUNT <> 1
	BEGIN
		SET @RETVALUE = 1			--실패 - 존재하지 않는 캐릭터
		RETURN
	END

IF ((SELECT COUNT(*) FROM [dbo].[TB_FRIEND] WHERE [CHARACTER_IDX1]=@CHARACTER_IDX1 AND [APPLY]=0) >= 50)
	BEGIN
		SET @RETVALUE = 2			--실패 - 등록갯수 초과/신청
		RETURN
	END

IF ((SELECT COUNT(*) FROM [dbo].[TB_FRIEND] WHERE [CHARACTER_IDX1]=@CHARACTER_IDX2 AND [APPLY]=0) >= 50)
	BEGIN
		SET @RETVALUE = 3			--실패 - 등록갯수 초과/대상
		RETURN
	END

IF EXISTS (SELECT * FROM [dbo].[TB_FRIEND] WHERE [CHARACTER_IDX1]=@CHARACTER_IDX1 AND [CHARACTER_IDX2]=@CHARACTER_IDX2)
	BEGIN
		UPDATE [dbo].[TB_FRIEND]
		   SET [STATUS]=0
		      ,[APPLY]=0
		 WHERE [CHARACTER_IDX1]=@CHARACTER_IDX1
           AND [CHARACTER_IDX2]=@CHARACTER_IDX2

		UPDATE [dbo].[TB_FRIEND]
		   SET [BLOCK]=0
		 WHERE [CHARACTER_IDX1]=@CHARACTER_IDX2
           AND [CHARACTER_IDX2]=@CHARACTER_IDX1

		SET @RETVALUE = 0			--성공
		RETURN
	END


BEGIN TRAN

--신청 / 등록완료.
INSERT [dbo].[TB_FRIEND]
	   ([CHARACTER_IDX1]
       ,[CHARACTER_IDX2]
       ,[STATUS]
       ,[BLOCK])
VALUES (@CHARACTER_IDX1
       ,@CHARACTER_IDX2
       ,0
       ,1)

SELECT @ERRORCODE = @@ERROR, @ROWCOUNT = @@ROWCOUNT
IF @ERRORCODE <> 0 OR @ROWCOUNT <> 1
	BEGIN
		ROLLBACK TRAN
		SET @RETVALUE = 4			--실패 - 알수없는 오류
	END

--대상 / 등록신청.
IF NOT EXISTS (SELECT *
                 FROM [dbo].[TB_FRIEND]
                WHERE [CHARACTER_IDX1]=@CHARACTER_IDX2
                  AND [CHARACTER_IDX2]=@CHARACTER_IDX1
                  AND [APPLY]=0)
	BEGIN
		INSERT [dbo].[TB_FRIEND]
			   ([CHARACTER_IDX1]
			   ,[CHARACTER_IDX2]
			   ,[STATUS]
			   ,[BLOCK])
		VALUES (@CHARACTER_IDX2
			   ,@CHARACTER_IDX1
			   ,1
			   ,0)

		SELECT @ERRORCODE = @@ERROR, @ROWCOUNT = @@ROWCOUNT
		IF @ERRORCODE <> 0 OR @ROWCOUNT <> 1
			BEGIN
				ROLLBACK TRAN
				SET @RETVALUE = 4	--실패 - 알수없는 오류
			END
	END

COMMIT TRAN
SET @RETVALUE = 0					--성공
' 
END
GO
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[GP_FRIEND_SELECT]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'
/**********************************************************************
 *<
	FILE: GP_FRIEND_SELECT.SQL

	DESCRIPTION:

	CREATED BY:

	HISTORY:

 *>	Copyright (c) 2007, All Rights Reserved.
 **********************************************************************/

CREATE PROCEDURE [dbo].[GP_FRIEND_SELECT]
	(@CHARACTER_IDX	[int]) --캐릭터 고유번호

AS

SET NOCOUNT ON

SELECT A.[IDX]
	  ,A.[CHARACTER_IDX2]
	  ,(SELECT C.[NAME]
          FROM [dbo].[TB_CHARACTER] C
         WHERE C.[IDX]=A.[CHARACTER_IDX2]) AS ''CHARACTER_NAME''
	  ,(SELECT C.[RACE]
          FROM [dbo].[TB_CHARACTER] C
         WHERE C.[IDX]=A.[CHARACTER_IDX2]) AS ''CHARACTER_RACE''
	  ,(SELECT C.[GENDER]
          FROM [dbo].[TB_CHARACTER] C
         WHERE C.[IDX]=A.[CHARACTER_IDX2]) AS ''CHARACTER_GENDER''
      ,A.[STATUS]
      ,A.[BLOCK]
  FROM [dbo].[TB_FRIEND] A
 WHERE A.[CHARACTER_IDX1]=@CHARACTER_IDX
   AND A.[APPLY]=0
 ORDER BY [CHARACTER_NAME]
' 
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[GP_CHARACTER_INFLUENCE_INSERT]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'

/**********************************************************************
 *<
	FILE: GP_CHARACTER_INFLUENCE_INSERT.SQL

	DESCRIPTION:

	CREATED BY: PKH

	HISTORY: 2007/08/30

 *>	Copyright (c) 2006, All Rights Reserved.
 **********************************************************************/

CREATE PROCEDURE [dbo].[GP_CHARACTER_INFLUENCE_INSERT]
(
	@CHARACTER_IDX			[int],
	@INFLUENCE_IDX			[int],
	@ATTACKER_IDX			[int],
	@ATTACKER_TYPE			[int],
	@ISREALTIME				[tinyint],
	@RESTTIME				[int],
	@STARTTIME				[datetime],
	@ENDTIME				[datetime],
	@TIME1					[float],
	@TIME2					[float],
	@VALUE1					[int],
	@VALUE2					[int],
	@ATTRIBUTE_TYPE			[int],
	@RETVALUE				[int]OUTPUT,
	@IDX					[int]OUTPUT
)

AS

DECLARE @ERRORCODE			[int]

SET NOCOUNT ON

BEGIN TRAN

-- 처음 생성시 STEP 값은 0
INSERT [dbo].[TB_CHARACTER_INFLUENCE]
(
	[CHARACTER_IDX],
	[INFLUENCE_IDX],
	[ATTACKER_IDX],
	[ATTACKER_TYPE],
	[ISREALTIME],
	[RESTTIME],
	[STARTTIME],
	[ENDTIME],
	[TIME1],
	[TIME2],
	[VALUE1],
	[VALUE2],
	[ATTRIBUTE_TYPE]
)
VALUES
(	
	@CHARACTER_IDX,
	@INFLUENCE_IDX,
	@ATTACKER_IDX,
	@ATTACKER_TYPE,
	@ISREALTIME,
	@RESTTIME,
	@STARTTIME,
	@ENDTIME,
	@TIME1,
	@TIME2,
	@VALUE1,
	@VALUE2,
	@ATTRIBUTE_TYPE
)

SELECT @ERRORCODE=@@ERROR

IF @ERRORCODE <> 0
	BEGIN
		SET @RETVALUE = 1			--등록실패 - 알수없는 오류
		SET @IDX = 0
		ROLLBACK TRAN
	END
ELSE
	BEGIN
		SET @RETVALUE = 0			--등록성공
		SET @IDX = @@IDENTITY
		COMMIT TRAN
	END































' 
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[GP_CHARACTER_INFLUENCE_SELECT]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'






/**********************************************************************
 *<
	FILE: GP_CHARACTER_INFLUENCE_SELECT.SQL

	DESCRIPTION:

	CREATED BY: 2007/08/30

	HISTORY: PKH

 *>	Copyright (c) 2007, All Rights Reserved.
 **********************************************************************/

CREATE PROCEDURE [dbo].[GP_CHARACTER_INFLUENCE_SELECT]
	(@CHARACTER_IDX	[int]	-- 캐릭터 고유번호
	)

AS

SET NOCOUNT ON

SELECT		[IDX],
			[INFLUENCE_IDX],
			[ATTACKER_IDX],
			[ATTACKER_TYPE],
			[ISREALTIME],
			[RESTTIME],
			[STARTTIME],
			[ENDTIME],
			[TIME1],
			[TIME2],
			[VALUE1],
			[VALUE2],
			[ATTRIBUTE_TYPE]
FROM		[dbo].[TB_CHARACTER_INFLUENCE]
WHERE		[CHARACTER_IDX] = @CHARACTER_IDX























' 
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[GP_FORTUNE_UPDATE]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'






   
 /**********************************************************************
 *<
	FILE: GP_FORTUNE_UPDATE.SQL

	DESCRIPTION:

	CREATED BY:

	HISTORY:

 *>	Copyright (c) 2007, All Rights Reserved.
 **********************************************************************/
 
CREATE PROCEDURE [dbo].[GP_FORTUNE_UPDATE]
				(@CHARACTER_IDX		[int]
				,@FORTUNE1			[datetime]
				,@FORTUNE2			[datetime]
				,@FORTUNE3			[datetime]
				,@FORTUNE4			[datetime]
				,@FORTUNE5			[datetime]
				,@TODAY_WORD		[nvarchar](50)	-- 오늘의 한마디
				,@TODAY_COLOR		[int]			-- 오늘의 한마디 색
				,@RETVALUE			[int]OUTPUT)		
        
AS

-- 적용행 출력 금지
SET NOCOUNT ON
DECLARE @ERRORCODE		[int]
DECLARE @ROWCOUNT		[int]
DECLARE @IDX			[int]

-- 기존 정보가 존재하면 업데이트
SELECT @IDX=ISNULL( (SELECT [IDX] FROM [dbo].[TB_FORTUNE] WHERE [CHARACTER_IDX]=@CHARACTER_IDX), 0)

IF @IDX<>0
	BEGIN
		UPDATE [dbo].[TB_FORTUNE]
		   SET [FORTUNE1]=@FORTUNE1
			  ,[FORTUNE2]=@FORTUNE2
			  ,[FORTUNE3]=@FORTUNE3
			  ,[FORTUNE4]=@FORTUNE4
			  ,[FORTUNE5]=@FORTUNE5
			  ,[TODAY_WORD]=@TODAY_WORD
			  ,[TODAY_COLOR]=@TODAY_COLOR
		 WHERE [IDX]=@IDX
		
		IF @@ERROR <> 0 OR @@ROWCOUNT <> 1
			BEGIN
				SET @RETVALUE = 1			-- 등록실패 :알수 없는 오류
			END
		ELSE
			BEGIN
				SET @RETVALUE = 0
				RETURN
			END
	END
ELSE
	BEGIN
		INSERT [dbo].[TB_FORTUNE]
			   ([CHARACTER_IDX]
			   ,[FORTUNE1]
			   ,[FORTUNE2]
			   ,[FORTUNE3]
			   ,[FORTUNE4]
			   ,[FORTUNE5]
			   ,[TODAY_WORD]
			   ,[TODAY_COLOR])
		VALUES (@CHARACTER_IDX
			   ,@FORTUNE1
			   ,@FORTUNE2
			   ,@FORTUNE3
			   ,@FORTUNE4
			   ,@FORTUNE5
			   ,@TODAY_WORD
			   ,@TODAY_COLOR)

		IF @@ERROR <> 0 OR @@ROWCOUNT <> 1
			BEGIN
				SET @RETVALUE = 2			-- 등록실패 :알수 없는 오류
			END
		ELSE
			BEGIN
				SET @RETVALUE = 0
				RETURN
			END
	END

SET @RETVALUE = 3


' 
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[GP_FORTUNE_SELECT]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'


/**********************************************************************
 *<
	FILE: GP_FORTUNE_SELECT.SQL

	DESCRIPTION:

	CREATED BY:

	HISTORY:

 *>	Copyright (c) 2007, All Rights Reserved.
 **********************************************************************/

CREATE PROCEDURE [dbo].[GP_FORTUNE_SELECT]
	(@CHARACTER_IDX	[int]) --캐릭터 고유번호

AS

SET NOCOUNT ON

SELECT [FORTUNE1]
	  ,[FORTUNE2]
	  ,[FORTUNE3]
	  ,[FORTUNE4]
	  ,[FORTUNE5]
	  ,[TODAY_WORD]
	  ,[TODAY_COLOR]
  FROM [dbo].[TB_FORTUNE]
 WHERE [CHARACTER_IDX]=@CHARACTER_IDX


' 
END
GO
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[GP_ITEM_TAROT_RESULT]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'
/**********************************************************************
 *<
	FILE: GP_ITEM_TAROT_RESULT.SQL

	DESCRIPTION:

	CREATED BY:

	HISTORY:

 *>	Copyright (c) 2007, All Rights Reserved.
 **********************************************************************/

CREATE PROCEDURE [dbo].[GP_ITEM_TAROT_RESULT]
	(@ITEM_DEFINE_INDEX	[int]		--아이템 인덱스
	,@VALUE				[int])		--결과값

AS

SET NOCOUNT ON

SELECT INFLUENCE_IDX1
      ,INFLUENCE_IDX2
      ,INFLUENCE_IDX3
  FROM [dbo].[TB_ITEM_TAROT_RESULT]
 WHERE [INDEX]=@ITEM_DEFINE_INDEX
   AND @VALUE >= [MIN]
   AND @VALUE <= [MAX]
' 
END
GO
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[GP_ITEM_TAROT_RESULT_INSERT]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'
/**********************************************************************
 *<
	FILE: GP_ITEM_TAROT_RESULT_INSERT.SQL

	DESCRIPTION:

	CREATED BY:

	HISTORY:

 *>	Copyright (c) 2007, All Rights Reserved.
 **********************************************************************/

CREATE PROCEDURE [dbo].[GP_ITEM_TAROT_RESULT_INSERT]
	(@INDEX				[int]
    ,@MIN				[int]
    ,@MAX				[int]
    ,@INFLUENCE_IDX1	[int]
    ,@INFLUENCE_IDX2	[int]
    ,@INFLUENCE_IDX3	[int]
    ,@RETVALUE			[int]OUTPUT)

AS

SET NOCOUNT ON

DECLARE @ERRORCODE		[int]
DECLARE @ROWCOUNT		[int]


INSERT [dbo].[TB_ITEM_TAROT_RESULT]
	   ([INDEX]
       ,[MIN]
       ,[MAX]
       ,[INFLUENCE_IDX1]
       ,[INFLUENCE_IDX2]
       ,[INFLUENCE_IDX3])

VALUES (@INDEX
       ,@MIN
       ,@MAX
       ,@INFLUENCE_IDX1
       ,@INFLUENCE_IDX2
       ,@INFLUENCE_IDX3)

SELECT @ERRORCODE=@@ERROR, @ROWCOUNT=@@ROWCOUNT

IF @ERRORCODE <> 0 OR @ROWCOUNT <> 1
	BEGIN
		SET @RETVALUE = -1	--등록실패
	END
ELSE
	BEGIN
		SET @RETVALUE = 0	--등록성공
	END
' 
END
GO
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[GP_ITEM_TAROT_INSERT]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'
/**********************************************************************
 *<
	FILE: GP_ITEM_TAROT_INSERT.SQL

	DESCRIPTION:

	CREATED BY:

	HISTORY:

 *>	Copyright (c) 2007, All Rights Reserved.
 **********************************************************************/

CREATE PROCEDURE [dbo].[GP_ITEM_TAROT_INSERT]
	(@INDEX			[int]
    ,@NUMBER		[int]
    ,@LEVEL			[tinyint]
    ,@STR_VALUE		[int]
    ,@INV_VALUE		[int]
    ,@PROP			[int]
    ,@EPISODE		[int]
    ,@RETVALUE		[int]OUTPUT)

AS

SET NOCOUNT ON

DECLARE @ERRORCODE		[int]
DECLARE @ROWCOUNT		[int]


INSERT [dbo].[TB_ITEM_TAROT]
	   ([INDEX]
       ,[NUMBER]
       ,[LEVEL]
       ,[STR_VALUE]
       ,[INV_VALUE]
       ,[PROP]
       ,[EPISODE])

VALUES (@INDEX
       ,@NUMBER
       ,@LEVEL
       ,@STR_VALUE
       ,@INV_VALUE
       ,@PROP
       ,@EPISODE)

SELECT @ERRORCODE=@@ERROR, @ROWCOUNT=@@ROWCOUNT

IF @ERRORCODE <> 0 OR @ROWCOUNT <> 1
	BEGIN
		SET @RETVALUE = -1	--등록실패
	END
ELSE
	BEGIN
		SET @RETVALUE = 0	--등록성공
	END
' 
END
GO
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[GP_ITEM_TAROT_SELECT]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'
/**********************************************************************
 *<
	FILE: GP_ITEM_TAROT_SELECT.SQL

	DESCRIPTION:  TB_ITEM_TAROT를 분할 로딩.

	CREATED BY: 곽철중

	HISTORY: 08/03/26 GP_ITEM_TAROT_TABLE를 수정하여 새로 코딩.

 *>	Copyright (c) 2008, All Rights Reserved.
 **********************************************************************/

CREATE PROCEDURE [dbo].[GP_ITEM_TAROT_SELECT]
	(@IDX	[int])		--고유번호

AS

SET NOCOUNT ON

SELECT [IDX]
      ,[INDEX]
      ,[NUMBER]
      ,[LEVEL]
      ,[STR_VALUE]
      ,[INV_VALUE]
      ,[PROP]
      ,[EPISODE]
  FROM [dbo].[TB_ITEM_TAROT]
 WHERE [IDX]=@IDX
' 
END
GO
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[GP_VERIFY_ITEM_TAROT]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'
/**********************************************************************
 *<
	FILE: GP_VERIFY_ITEM_TAROT.SQL

	DESCRIPTION:

	CREATED BY:

	HISTORY:

 *>	Copyright (c) 2006, All Rights Reserved.
 **********************************************************************/

CREATE PROCEDURE [dbo].[GP_VERIFY_ITEM_TAROT]
	(@COUNT    [int]OUTPUT
	,@RETVALUE [int]OUTPUT)

AS

SET NOCOUNT ON

DECLARE @MAX [int]

SELECT @COUNT=COUNT(IDX)
      ,@MAX  =MAX(IDX)
  FROM [dbo].[TB_ITEM_TAROT]
  
SET @RETVALUE = @COUNT - @MAX
' 
END
GO
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[GP_ITEM_SPREAD_INSERT]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'
/**********************************************************************
 *<
	FILE: GP_ITEM_SPREAD_INSERT.SQL

	DESCRIPTION:

	CREATED BY:

	HISTORY:

 *>	Copyright (c) 2007, All Rights Reserved.
 **********************************************************************/

CREATE PROCEDURE [dbo].[GP_ITEM_SPREAD_INSERT]
	(@INDEX			[int]
    ,@AXIS_ARRAY	[tinyint]
    ,@XPOS			[smallint]
    ,@YPOS			[smallint]
	,@DIR           [tinyint]
    ,@CALC			[varchar](20)
    ,@VALUE			[smallint]
    ,@RETVALUE		[int]OUTPUT)

AS

SET NOCOUNT ON

DECLARE @ERRORCODE		[int]
DECLARE @ROWCOUNT		[int]

INSERT [dbo].[TB_ITEM_SPREAD]
	   ([INDEX]
       ,[AXIS_ARRAY]
       ,[XPOS]
       ,[YPOS]
	   ,[DIR]
       ,[CALC]
       ,[VALUE])

VALUES (@INDEX
       ,@AXIS_ARRAY
       ,@XPOS
       ,@YPOS
	   ,@DIR
       ,@CALC
       ,@VALUE)

SELECT @ERRORCODE=@@ERROR, @ROWCOUNT=@@ROWCOUNT

IF @ERRORCODE <> 0 OR @ROWCOUNT <> 1
	BEGIN
		SET @RETVALUE = -1	--등록실패
	END
ELSE
	BEGIN
		SET @RETVALUE = 0	--등록성공
	END
' 
END
GO
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[GP_ITEM_SPREAD_VALUE]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'
/**********************************************************************
 *<
	FILE: GP_ITEM_SPREAD_VALUE.SQL

	DESCRIPTION:

	CREATED BY:

	HISTORY:

 *>	Copyright (c) 2007, All Rights Reserved.
 **********************************************************************/

CREATE PROCEDURE [dbo].[GP_ITEM_SPREAD_VALUE]
	(@INDEX	[int]
	,@ARRAY	[int]
	,@DIR   [tinyint]
	,@VALUE	[int]OUTPUT)

AS

SET NOCOUNT ON

SELECT @VALUE=(CASE DIR
               WHEN 0    THEN (CASE CALC
							   WHEN ''*'' THEN @VALUE * [value]
							   WHEN ''/'' THEN @VALUE / [value]
							   WHEN ''+'' THEN @VALUE + [value]
							   WHEN ''0'' THEN @VALUE
							   ELSE @VALUE
							   END)
               WHEN @DIR THEN (CASE CALC
							   WHEN ''*'' THEN @VALUE * [value]
					           WHEN ''/'' THEN @VALUE / [value]
					           WHEN ''+'' THEN @VALUE + [value]
					           WHEN ''0'' THEN @VALUE
					           ELSE @VALUE
					           END)
               END)
  FROM TB_ITEM_SPREAD
 WHERE [INDEX]=@INDEX
   AND [AXIS_ARRAY]=@ARRAY
' 
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[GP_TITLE_SELECT]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'



 
 
       
 /**********************************************************************
 *<
	FILE: GP_TITLE_SELECT.SQL

	DESCRIPTION:

	CREATED BY:

	HISTORY:

 *>	Copyright (c) 2007, All Rights Reserved.
 **********************************************************************/
 
 CREATE PROCEDURE [dbo].[GP_TITLE_SELECT]
 	(@CHARACTER_IDX		[int])		
        
AS

SET NOCOUNT ON

SELECT [IDX]
	 , [TITLE_IDX]
  FROM [dbo].[TB_TITLE]
 WHERE [CHARACTER_IDX]=@CHARACTER_IDX
 AND [APPLY]=0

' 
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[GP_TITLE_INSERT]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N' 
       
 /**********************************************************************
 *<
	FILE: GP_TITLE_INSERT.SQL

	DESCRIPTION:

	CREATED BY:

	HISTORY:

 *>	Copyright (c) 2007, All Rights Reserved.
 **********************************************************************/
 
 CREATE PROCEDURE [dbo].[GP_TITLE_INSERT]
 	(@CHARACTER_IDX		[int]			--캐릭터 인덱스
    ,@TITLE_IDX			[int]			--타이틀 인덱스
    ,@RETVALUE			[int]OUTPUT)		
        
AS

SET NOCOUNT ON
DECLARE @ERRORCODE		[int]
DECLARE @ROWCOUNT		[int]

BEGIN TRAN

INSERT [dbo].[TB_TITLE]
	   ([CHARACTER_IDX]
	   ,[TITLE_IDX])
	   
VALUES (@CHARACTER_IDX
       ,@TITLE_IDX )

SELECT @ERRORCODE=@@ERROR, @ROWCOUNT=@@ROWCOUNT

-- SQL_SUCCESS OR SQL_SUCCESS_WITH_INFO
IF @ERRORCODE <> 0 OR @ROWCOUNT <> 1
	BEGIN
		SET @RETVALUE = 1		-- 등록실패 :알수 없는 오류
		ROLLBACK TRAN
	END
ELSE
	BEGIN
		COMMIT TRAN
		SET @RETVALUE = 0		-- 성공
	END
' 
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[GP_NOTE_SELECT]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'

/**********************************************************************
 *<
	FILE: GP_NOTE_SELECT.SQL

	DESCRIPTION:

	CREATED BY:

	HISTORY:

 *>	Copyright (c) 2007, All Rights Reserved.
 **********************************************************************/

CREATE PROCEDURE [dbo].[GP_NOTE_SELECT]
	(@CHARACTER_IDX	[int]) --캐릭터 고유번호

AS

SET NOCOUNT ON

UPDATE [dbo].[TB_NOTE]
   SET [APPLY]=1
 WHERE [VALID_THRU] < GETDATE()
   AND [CHARACTER_IDX2]=@CHARACTER_IDX
   AND [APPLY]=0

SELECT [IDX]
	  ,[REGISTER_DATE]
	  ,(SELECT [NAME] FROM [dbo].[TB_CHARACTER] WHERE [IDX]=[CHARACTER_IDX1]) AS ''CHARACTER_NAME''
	  ,[MESSAGE]
	  ,DATEDIFF(MS, GETDATE(), [VALID_THRU]) AS ''REMAIN_DAY'' --DATEDIFF(DAY, GETDATE(), [VALID_THRU]) AS ''REMAIN_DAY''
  FROM [dbo].[TB_NOTE]
 WHERE [CHARACTER_IDX2]=@CHARACTER_IDX
   AND [APPLY]=0
 ORDER BY [IDX] DESC

' 
END
GO
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[GP_NOTE_DELETE]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'
/**********************************************************************
 *<
	FILE: GP_NOTE_DELETE.SQL

	DESCRIPTION:

	CREATED BY:

	HISTORY:

 *>	Copyright (c) 2007, All Rights Reserved.
 **********************************************************************/

CREATE PROCEDURE [dbo].[GP_NOTE_DELETE]
	(@CHARACTER_IDX		[int]	--캐릭터 고유번호
	,@IDX				[int])	--고유번호

AS

SET NOCOUNT ON

UPDATE [dbo].[TB_NOTE]
   SET [APPLY]=1
 WHERE [IDX]=@IDX
   AND [CHARACTER_IDX2]=@CHARACTER_IDX

' 
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[GP_NOTE_INSERT]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'







/**********************************************************************
 *<
	FILE: GP_NOTE_INSERT.SQL

	DESCRIPTION:

	CREATED BY:

	HISTORY:

 *>	Copyright (c) 2007, All Rights Reserved.
 **********************************************************************/

CREATE PROCEDURE [dbo].[GP_NOTE_INSERT]
	(@CHARACTER_IDX1	[int]			--보낸 캐릭터(고유번호)
	,@CHARACTER_IDX2	[int]OUTPUT		--받는 캐릭터(고유번호)
	,@CHARACTER_NAME2	[nvarchar](16)	--받는 캐릭터(이름)
	,@MESSAGE			[nvarchar](200)	--메시지
	,@RETVALUE			[int]OUTPUT)	--반환값

AS

SET NOCOUNT ON

DECLARE @ERRORCODE			[int]
DECLARE @ROWCOUNT			[int]
DECLARE @IDX				[int]
DECLARE @OPTION1			[int]

SELECT @CHARACTER_IDX2=ISNULL((SELECT [IDX] FROM [dbo].[TB_CHARACTER] WHERE [NAME]=@CHARACTER_NAME2 AND [APPLY]=0),0)

IF @CHARACTER_IDX2=0
	BEGIN
		SET @RETVALUE = 1				--실패 - 존재하지 않는 캐릭터
		RETURN
	END

-- 보관갯수 검사
IF ((SELECT COUNT(IDX) FROM [dbo].[TB_NOTE] WHERE [CHARACTER_IDX2]=@CHARACTER_IDX2 AND [APPLY]=0) >= 50)
			BEGIN
				SET @RETVALUE = 2	--실패 - 보관갯수 초과
				RETURN
			END

-- 쪽지 거부 검사
SELECT @OPTION1=(SELECT [OPTION1] FROM [dbo].[TB_CHARACTER] WHERE [IDX]=@CHARACTER_IDX2)
IF ( @OPTION1 & 32768 = 32768)
	BEGIN
		SET @RETVALUE = 3			-- 실패 - 쪽지 거부
		RETURN
	END

BEGIN TRAN

-- 쪽지 삽입
INSERT [dbo].[TB_NOTE]
	   ([CHARACTER_IDX1]
      ,[CHARACTER_IDX2]
      ,[MESSAGE]
	  ,[VALID_THRU])
VALUES (@CHARACTER_IDX1
      ,@CHARACTER_IDX2
      ,@MESSAGE
	  ,DATEADD(DAY, 13, GETDATE()))

IF @@ERROR <> 0 OR @@ROWCOUNT <> 1
	GOTO ROLLBACK_TRAN

SELECT @IDX=MAX(IDX)
  FROM [dbo].[TB_NOTE]

SELECT @IDX
	  ,[REGISTER_DATE]
	  ,(SELECT [NAME] FROM [dbo].[TB_CHARACTER] WHERE [IDX]=[CHARACTER_IDX1]) AS ''CHARACTER_NAME''
	  ,[MESSAGE]
	  ,DATEDIFF(MS, GETDATE(), [VALID_THRU]) AS ''REMAIN_TIME''
  FROM [dbo].[TB_NOTE]
 WHERE [IDX]=@IDX

IF @@ERROR <> 0 OR @@ROWCOUNT <> 1
	GOTO ROLLBACK_TRAN

COMMIT TRAN
SET @RETVALUE = 0						-- 성공
RETURN
--
ROLLBACK_TRAN:
	ROLLBACK TRAN
	SET @RETVALUE = 4					-- 등록실패 :알수 없는 오류
RETURN

' 
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[GP_GUILDNOTE_INSERT]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'






/**********************************************************************
 *<
	FILE: GP_GUILDNOTE_INSERT.SQL

	DESCRIPTION:

	CREATED BY:

	HISTORY:

 *>	Copyright (c) 2007, All Rights Reserved.
 **********************************************************************/

CREATE PROCEDURE [dbo].[GP_GUILDNOTE_INSERT]
	(@CHARACTER_IDX1	[int]			--보낸 캐릭터(고유번호)
	,@CHARACTER_IDX2	[int]			--받는 캐릭터(고유번호)
	,@MESSAGE			[nvarchar](200)	--메시지
	,@IDX				[int]OUTPUT		--고유번호
	,@RETVALUE			[int]OUTPUT)	--반환값

AS

SET NOCOUNT ON

DECLARE @ERRORCODE			[int]
DECLARE @ROWCOUNT			[int]

-- 보관갯수 검사
IF ((SELECT COUNT(IDX) FROM [dbo].[TB_NOTE] WHERE [CHARACTER_IDX2]=@CHARACTER_IDX2 AND [APPLY]=0) >= 50)
			BEGIN
				SET @RETVALUE = 2	--실패 - 보관갯수 초과
				RETURN
			END

BEGIN TRAN

-- 쪽지 삽입
INSERT [dbo].[TB_NOTE]
	   ([CHARACTER_IDX1]
      ,[CHARACTER_IDX2]
      ,[MESSAGE]
	  ,[VALID_THRU])
VALUES (@CHARACTER_IDX1
      ,@CHARACTER_IDX2
      ,@MESSAGE
	  ,DATEADD(DAY, 13, GETDATE()))

IF @@ERROR <> 0 OR @@ROWCOUNT <> 1
	GOTO ROLLBACK_TRAN

SELECT @IDX=MAX(IDX)
  FROM [dbo].[TB_NOTE]

SELECT @IDX
	  ,[REGISTER_DATE]
	  ,(SELECT [NAME] FROM [dbo].[TB_CHARACTER] WHERE [IDX]=[CHARACTER_IDX1]) AS ''CHARACTER_NAME''
	  ,[MESSAGE]
	  ,DATEDIFF(MS, GETDATE(), [VALID_THRU]) AS ''REMAIN_TIME''
  FROM [dbo].[TB_NOTE]
 WHERE [IDX]=@IDX

IF @@ERROR <> 0 OR @@ROWCOUNT <> 1
	GOTO ROLLBACK_TRAN

COMMIT TRAN
SET @RETVALUE = 0						-- 성공
RETURN
--
ROLLBACK_TRAN:
	ROLLBACK TRAN
	SET @RETVALUE = 3					-- 등록실패 :알수 없는 오류
RETURN


' 
END
GO
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[GP_DEFAULT_ITEMS_INSERT]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'
/**********************************************************************
 *<
	FILE: GP_DEFAULT_ITEMS_INSERT.SQL

	DESCRIPTION:

	CREATED BY:

	HISTORY:

 *>	Copyright (c) 2007, All Rights Reserved.
 **********************************************************************/

CREATE PROCEDURE [dbo].[GP_DEFAULT_ITEMS_INSERT]
	(@CHARACTER_JOB		[int]
    ,@ITEM_DEFINE_INDEX	[int]
    ,@INVENTORY_NUMBER	[smallint]
    ,@INVENTORY_COUNT	[smallint]
    ,@RETVALUE			[int]OUTPUT)

AS

SET NOCOUNT ON

DECLARE @ERRORCODE		[int]
DECLARE @ROWCOUNT		[int]

INSERT [dbo].[TB_DEFAULT_ITEMS]
	   ([CHARACTER_JOB]
       ,[ITEM_DEFINE_INDEX]
       ,[INVENTORY_NUMBER]
       ,[INVENTORY_COUNT])
VALUES (@CHARACTER_JOB
       ,@ITEM_DEFINE_INDEX
       ,@INVENTORY_NUMBER
       ,@INVENTORY_COUNT)

SELECT @ERRORCODE=@@ERROR, @ROWCOUNT=@@ROWCOUNT

IF @ERRORCODE <> 0 OR @ROWCOUNT <> 1
	BEGIN
		SET @RETVALUE = -1	--등록실패
	END
ELSE
	BEGIN
		SET @RETVALUE = 0	--등록성공
	END
' 
END
GO
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[GP_DEFAULT_ITEMS]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'
/**********************************************************************
 *<
	FILE: GP_DEFAULT_ITEMS.SQL

	DESCRIPTION:

	CREATED BY:	곽철중

	HISTORY:	2008-03-17 테이블 필드 삭제(TYPE)및 수정(SEAL).

 *>	Copyright (c) 2006, All Rights Reserved.
 **********************************************************************/

CREATE PROCEDURE [dbo].[GP_DEFAULT_ITEMS]
	(@CHARACTER_IDX [int]
	,@CHARACTER_JOB	[int]
	,@RETVALUE		[int]OUTPUT)

AS

SET NOCOUNT ON

DECLARE @ERRORCODE			[int]
DECLARE @ROWCOUNT			[int]

--인벤토리에 기본 아이템 지급.
INSERT INTO TB_INVENTORY
      ([CHARACTER_IDX]
      ,[ITEM_DEFINE_INDEX]
      ,[NUMBER]
      ,[COUNT])
SELECT @CHARACTER_IDX
      ,[ITEM_DEFINE_INDEX]
	  ,[INVENTORY_NUMBER]
      ,[INVENTORY_COUNT]
  FROM [dbo].[TB_DEFAULT_ITEMS]
 WHERE [CHARACTER_JOB]=@CHARACTER_JOB
   AND [APPLY]=0

--기본 아이템 수량 확인.
SELECT @ERRORCODE = @@ERROR, @ROWCOUNT = @@ROWCOUNT
IF @ERRORCODE <> 0 OR @ROWCOUNT <> (SELECT COUNT(*) FROM [dbo].[TB_DEFAULT_ITEMS] WHERE [CHARACTER_JOB]=@CHARACTER_JOB AND [APPLY]=0)
	BEGIN
		SET @RETVALUE = 1
		RETURN
	END

--캐릭터 착용정보 수정.
UPDATE [dbo].[TB_CHARACTER]
   SET HAT       =ISNULL((SELECT [ITEM_DEFINE_INDEX] FROM [dbo].[TB_INVENTORY] WHERE [CHARACTER_IDX]=@CHARACTER_IDX AND [NUMBER]=0  AND [APPLY]=0), 0) --머리
	  ,BODY1     =ISNULL((SELECT [ITEM_DEFINE_INDEX] FROM [dbo].[TB_INVENTORY] WHERE [CHARACTER_IDX]=@CHARACTER_IDX AND [NUMBER]=1  AND [APPLY]=0), 0) --상의
	  ,BODY2     =ISNULL((SELECT [ITEM_DEFINE_INDEX] FROM [dbo].[TB_INVENTORY] WHERE [CHARACTER_IDX]=@CHARACTER_IDX AND [NUMBER]=2  AND [APPLY]=0), 0) --하의
	  ,HAND      =ISNULL((SELECT [ITEM_DEFINE_INDEX] FROM [dbo].[TB_INVENTORY] WHERE [CHARACTER_IDX]=@CHARACTER_IDX AND [NUMBER]=3  AND [APPLY]=0), 0) --장갑
	  ,FOOT      =ISNULL((SELECT [ITEM_DEFINE_INDEX] FROM [dbo].[TB_INVENTORY] WHERE [CHARACTER_IDX]=@CHARACTER_IDX AND [NUMBER]=4  AND [APPLY]=0), 0) --신발
	  ,LEFT_HAND =ISNULL((SELECT [ITEM_DEFINE_INDEX] FROM [dbo].[TB_INVENTORY] WHERE [CHARACTER_IDX]=@CHARACTER_IDX AND [NUMBER]=15 AND [APPLY]=0), 0) --왼손
	  ,RIGHT_HAND=ISNULL((SELECT [ITEM_DEFINE_INDEX] FROM [dbo].[TB_INVENTORY] WHERE [CHARACTER_IDX]=@CHARACTER_IDX AND [NUMBER]=16 AND [APPLY]=0), 0) --오른손
 WHERE IDX=@CHARACTER_IDX

--캐릭터 착용정보 갱신 확인.
SELECT @ERRORCODE = @@ERROR, @ROWCOUNT = @@ROWCOUNT
IF @ERRORCODE <> 0 OR @ROWCOUNT <> 1
	BEGIN
		SET @RETVALUE = 2
		RETURN
	END

SET @RETVALUE = 0

--인벤토리 기본 아이템 지급 목록.
SELECT [IDX]
	  ,(SELECT [IDX] FROM [dbo].[TB_ITEM_DEFINE] WHERE [INDEX]=[ITEM_DEFINE_INDEX]) AS ''ITEM_DEFINE_IDX''
	  ,[ITEM_DEFINE_INDEX]
	  ,[NUMBER]
	  ,[COUNT]
	  ,[ENHANCED]
	  ,[CARD_SLOT1]
	  ,[CARD_SLOT2]
	  ,[CARD_SLOT3]
	  ,[CARD_SLOT4]
	  ,[CARD_SLOT5]
	  ,[SEAL]
	  ,[APPLY]
  FROM TB_INVENTORY
 WHERE [CHARACTER_IDX]=@CHARACTER_IDX
   AND [APPLY]=0
' 
END
GO
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[GP_VERIFY_DEFAULT_ITEMS]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'
/**********************************************************************
 *<
	FILE: GP_VERIFY_DEFAULT_ITEMS.SQL

	DESCRIPTION:

	CREATED BY:

	HISTORY:

 *>	Copyright (c) 2008, All Rights Reserved.
 **********************************************************************/

CREATE PROCEDURE [dbo].[GP_VERIFY_DEFAULT_ITEMS]
	(@ROWCOUNT  [int]OUTPUT
	,@ERRORCODE [int]OUTPUT)

AS

SET NOCOUNT ON

--아이템 인덱스 오류일 경우, 사용불가 처리.
UPDATE [dbo].[TB_DEFAULT_ITEMS]
   SET [APPLY]=1
 WHERE NOT EXISTS (SELECT [IDX] FROM [dbo].[TB_ITEM_DEFINE] WHERE [INDEX]=[ITEM_DEFINE_INDEX])
   AND [APPLY]=0

SELECT @ERRORCODE=@@ERROR, @ROWCOUNT=@@ROWCOUNT
' 
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[GP_QUEST_DEFINE_INSERT]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'

/**********************************************************************
 *<
	FILE: GP_QUEST_DEFINE_INSERT.SQL

	DESCRIPTION:

	CREATED BY:

	HISTORY:

 *>	Copyright (c) 2007, All Rights Reserved.
 **********************************************************************/
 
 CREATE PROCEDURE [dbo].[GP_QUEST_DEFINE_INSERT]
	(@INDEX				[int]			--퀘스트 인덱스
    ,@TITLE_IDX			[int]			--타이틀 인덱스
    ,@TYPE				[tinyint]		--퀘스트 종류
    ,@GROUPNUM			[smallint]		--그룹번호
    ,@GIVENPC_IDX		[int]			--제공npc
    ,@TAKENPC_IDX		[int]			--보상npc
    ,@REPEAT_TYPE		[tinyint]		--반복타입
    ,@SELECT_COUNT		[smallint]		--선택 보상개수
    ,@COMPLETE			[bigint])		--완료시 비트

AS

-- 적용행 출력 금지
SET NOCOUNT ON

DECLARE @RETVALUE		[int]

INSERT [dbo].[TB_QUEST_DEFINE]
	   ([INDEX]
	   ,[TITLE_IDX]
	   ,[TYPE]
	   ,[GROUPNUM]
	   ,[GIVENPC_IDX]
	   ,[TAKENPC_IDX]
	   ,[REPEAT_TYPE]
	   ,[SELECT_COUNT]
	   ,[COMPLETE])
	   
VALUES (@INDEX
       ,@TITLE_IDX
	   ,@TYPE	
       ,@GROUPNUM
       ,@GIVENPC_IDX
       ,@TAKENPC_IDX
       ,@REPEAT_TYPE
       ,@SELECT_COUNT
       ,@COMPLETE)

-- SQL_SUCCESS OR SQL_SUCCESS_WITH_INFO
IF @@ERROR <> 0 OR @@ROWCOUNT <> 1
	BEGIN
		SET @RETVALUE = -1		-- 실패
	END
ELSE
	BEGIN
		SET @RETVALUE = 0		-- 성공
	END
' 
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[GP_QUEST_INSERT]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'

 /**********************************************************************
 *<
	FILE: GP_QUEST_INSERT.SQL

	DESCRIPTION:

	CREATED BY:

	HISTORY:

 *>	Copyright (c) 2007, All Rights Reserved.
 **********************************************************************/
 
 CREATE PROCEDURE [dbo].[GP_QUEST_INSERT]
 	(@CHARACTER_IDX		[int]			--캐릭터 인덱스
    ,@QUEST_IDX			[int]			--퀘스트 인덱스
	,@CHECK				[bigint]		--진행정보
    ,@TIME_TYPE			[tinyint]		--시간 타입
    ,@REST_TIME			[int]			--남은시간
    ,@RETVALUE			[int]OUTPUT)		
        
AS

--적용행 출력 금지
SET NOCOUNT ON

DECLARE @REPEAT_TYPE [tinyint]

--반복타입 가져오기
SELECT @REPEAT_TYPE=[REPEAT_TYPE] 
  FROM [dbo].[TB_QUEST_DEFINE] 
 WHERE [IDX]=@QUEST_IDX	-- 퀘스트 인덱스로 찾기
--반복용 퀘스트일경우
IF EXISTS (SELECT * FROM [dbo].[TB_QUEST_PROGRESS]
				   WHERE [CHARACTER_IDX]=@CHARACTER_IDX
					 AND [QUEST_IDX]=@QUEST_IDX
					 AND @REPEAT_TYPE=2			-- 반복용 퀘스트
					 AND [APPLY]<>1 
					 AND [APPLY]<>3 )			-- 완료했거나, 포기상태가 아니라면 신규삽입 불가
	BEGIN
		SET @RETVALUE = 3						-- 소유중인퀘스트
		RETURN
	END
--아닌경우
ELSE IF EXISTS (SELECT * FROM [dbo].[TB_QUEST_PROGRESS] 
				   WHERE [CHARACTER_IDX]=@CHARACTER_IDX 
					 AND [QUEST_IDX]=@QUEST_IDX 
					 AND @REPEAT_TYPE<>2		-- 일반용 퀘스트
					 AND [APPLY]<>3 )			-- 포기상태가 아니라면 신규삽입 불가
	BEGIN
		SET @RETVALUE = 4						--이미 완료한 퀘스트
		RETURN
	END

--퀘스트 추가
INSERT [dbo].[TB_QUEST_PROGRESS]
	   ([CHARACTER_IDX]
	   ,[QUEST_IDX]
	   ,[CHECK]
	   ,[TIME_TYPE]
	   ,[REST_TIME])
VALUES (@CHARACTER_IDX
       ,@QUEST_IDX
	   ,@CHECK
       ,@TIME_TYPE
       ,@REST_TIME )

IF @@ERROR <> 0 OR @@ROWCOUNT <> 1
	BEGIN
		SET @RETVALUE = 1						-- 등록실패 :알수 없는 오류
		RETURN
	END

--
SELECT [IDX]
	  ,[QUEST_IDX]
	  ,[CHECK]
	  ,[REST_TIME]
  FROM [dbo].[TB_QUEST_PROGRESS]
 WHERE [IDX]=(SELECT MAX(IDX) FROM [dbo].[TB_QUEST_PROGRESS] WHERE CHARACTER_IDX=@CHARACTER_IDX)
' 
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[GP_QUEST_INSERT_BY_ITEM]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'

/**********************************************************************
 *<
	FILE: GP_QUEST_INSERT_BY_ITEM.SQL

	DESCRIPTION:

	CREATED BY:

	HISTORY:

 *>	Copyright (c) 2007, All Rights Reserved.
 **********************************************************************/
 
 CREATE PROCEDURE [dbo].[GP_QUEST_INSERT_BY_ITEM]
 	(@CHARACTER_IDX		[int]			--캐릭터 인덱스
    ,@QUEST_IDX			[int]			--퀘스트 인덱스
    ,@CHECK				[bigint]		--진행정보
    ,@TIME_TYPE			[tinyint]		--시간 타입
    ,@REST_TIME			[int]			--남은시간
    ,@RETVALUE			[int]OUTPUT)		
        
AS

--적용행 출력 금지
SET NOCOUNT ON

DECLARE @REPEAT_TYPE [tinyint]

--반복타입 가져오기
SELECT @REPEAT_TYPE=[REPEAT_TYPE] 
  FROM [dbo].[TB_QUEST_DEFINE] 
 WHERE [INDEX]=@QUEST_IDX	-- 퀘스트 인덱스로 찾기

-- 퀘스트 중복 검사
IF @REPEAT_TYPE = 1 
	BEGIN
		-- 반복 퀘스트인경우
		IF EXISTS (SELECT * FROM [dbo].[TB_QUEST_PROGRESS]
				   WHERE [CHARACTER_IDX]=@CHARACTER_IDX
					 AND [QUEST_IDX]=@QUEST_IDX
					 AND [APPLY]<>1 
					 AND [APPLY]<>3 )			-- 완료했거나, 포기상태가 아니라면 신규삽입 불가
		BEGIN
			SET @RETVALUE = 3						-- 소유중인퀘스트
			RETURN
		END
	END
ELSE
	BEGIN
		-- 아닌경우
		IF EXISTS (SELECT * FROM [dbo].[TB_QUEST_PROGRESS] 
				   WHERE [CHARACTER_IDX]=@CHARACTER_IDX 
					 AND [QUEST_IDX]=@QUEST_IDX 
					 AND [APPLY]<>3 )			-- 포기상태가 아니라면 신규삽입 불가
		BEGIN
			SET @RETVALUE = 4					-- 이미 완료한 퀘스트
			RETURN
		END
	END

--퀘스트 추가
INSERT [dbo].[TB_QUEST_PROGRESS]
	   ([CHARACTER_IDX]
	   ,[QUEST_IDX]
	   ,[CHECK]
	   ,[TIME_TYPE]
	   ,[REST_TIME])
VALUES (@CHARACTER_IDX
       ,@QUEST_IDX
	   ,@CHECK
       ,@TIME_TYPE
       ,@REST_TIME )

IF @@ERROR <> 0 OR @@ROWCOUNT <> 1
	BEGIN
		SET @RETVALUE = 1						-- 등록실패 :알수 없는 오류
		RETURN
	END

SELECT [IDX]
	  ,[QUEST_IDX]
	  ,[CHECK]
	  ,[REST_TIME]
  FROM [dbo].[TB_QUEST_PROGRESS]
 WHERE [IDX]=(SELECT MAX(IDX) FROM [dbo].[TB_QUEST_PROGRESS] WHERE CHARACTER_IDX=@CHARACTER_IDX)
' 
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[GP_ITEM_ABILITY_SELECT]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'



/**********************************************************************
 *<
	FILE: GP_ITEM_ABILITY_SELECT.SQL

	DESCRIPTION: TB_ITEM_ABILITY를 분할 로딩.

	CREATED BY: 곽철중

	HISTORY: 08/03/26 GP_ITEM_ABILITY_TABLE.SQL를 수정하여 새로 코딩.

 *>	Copyright (c) 2008, All Rights Reserved.
 **********************************************************************/

CREATE PROCEDURE [dbo].[GP_ITEM_ABILITY_SELECT]
	(@IDX	[int])		--고유번호

AS

SET NOCOUNT ON

SELECT [IDX]
      ,[INDEX]
	  ,[DEFENSE_TYPE]
	  ,[RANGE_TYPE]
	  ,[TARGET_TYPE]
	  ,[USE_RANGE]
      ,[DEFENSE_P]
      ,[DEFENSE_M]
      ,[ATTACK_RANGE]
      ,[ATTACK_SPEED]
      ,[COOL_TIME1]
      ,[COOL_TIME2]
      ,[ATTACK_P_MIN]
      ,[ATTACK_P_MAX]
      ,[ATTACK_M_MIN]
      ,[ATTACK_M_MAX]
	  ,[OPT01_INDEX]
	  ,[OPT01_VALUE]
	  ,[OPT02_INDEX]
	  ,[OPT02_VALUE]
	  ,[OPT03_INDEX]
	  ,[OPT03_VALUE]
	  ,[OPT04_INDEX]
	  ,[OPT04_VALUE]
	  ,[OPT05_INDEX]
	  ,[OPT05_VALUE]
	  ,[OPT06_INDEX]
	  ,[OPT06_VALUE]
	  ,[OPT07_INDEX]
	  ,[OPT07_VALUE]
	  ,[OPT08_INDEX]
	  ,[OPT08_VALUE]
	  ,[OPT09_INDEX]
	  ,[OPT09_VALUE]
	  ,[OPT10_INDEX]
	  ,[OPT10_VALUE]
      ,[INFLUENCE_IDX]
  FROM [dbo].[TB_ITEM_ABILITY]
 WHERE [IDX]=@IDX



' 
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[GP_ITEM_ABILITY_INSERT]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'



/**********************************************************************
 *<
	FILE: GP_ITEM_ABILITY_INSERT.SQL

	DESCRIPTION:

	CREATED BY:

	HISTORY:

 *>	Copyright (c) 2007, All Rights Reserved.
 **********************************************************************/

CREATE PROCEDURE [dbo].[GP_ITEM_ABILITY_INSERT]
	(@INDEX					[int]
	,@DEFENSE_TYPE			[smallint]
	,@RANGE_TYPE			[tinyint]
	,@TARGET_TYPE			[tinyint]
	,@USE_RANGE				[smallint]
    ,@DEFENSE_P				[smallint]
    ,@DEFENSE_M				[smallint]
    ,@ATTACK_RANGE			[smallint]
    ,@ATTACK_SPEED			[smallint]
    ,@COOL_TIME1			[int]
    ,@COOL_TIME2			[int]
    ,@ATTACK_P_MIN			[smallint]
    ,@ATTACK_P_MAX			[smallint]
    ,@ATTACK_M_MIN			[smallint]
    ,@ATTACK_M_MAX			[smallint]
    ,@OPT01_INDEX			[smallint]
    ,@OPT01_VALUE			[smallint]
    ,@OPT02_INDEX			[smallint]
    ,@OPT02_VALUE			[smallint]
    ,@OPT03_INDEX			[smallint]
    ,@OPT03_VALUE			[smallint]
    ,@OPT04_INDEX			[smallint]
    ,@OPT04_VALUE			[smallint]
    ,@OPT05_INDEX			[smallint]
    ,@OPT05_VALUE			[smallint]
    ,@OPT06_INDEX			[smallint]
    ,@OPT06_VALUE			[smallint]
    ,@OPT07_INDEX			[smallint]
    ,@OPT07_VALUE			[smallint]
    ,@OPT08_INDEX			[smallint]
    ,@OPT08_VALUE			[smallint]
    ,@OPT09_INDEX			[smallint]
    ,@OPT09_VALUE			[smallint]
    ,@OPT10_INDEX			[smallint]
    ,@OPT10_VALUE			[smallint]
    ,@INFLUENCE_IDX			[int]
	,@RETVALUE				[int]OUTPUT)
AS

SET NOCOUNT ON

DECLARE @ERRORCODE		[int]
DECLARE @ROWCOUNT		[int]

INSERT [dbo].[TB_ITEM_ABILITY]
       ([INDEX]
       ,[DEFENSE_TYPE]
       ,[RANGE_TYPE]
       ,[TARGET_TYPE]
       ,[USE_RANGE]
       ,[DEFENSE_P]
       ,[DEFENSE_M]
       ,[ATTACK_RANGE]
       ,[ATTACK_SPEED]
       ,[COOL_TIME1]
       ,[COOL_TIME2]
       ,[ATTACK_P_MIN]
       ,[ATTACK_P_MAX]
       ,[ATTACK_M_MIN]
       ,[ATTACK_M_MAX]
	   ,[OPT01_INDEX]
	   ,[OPT01_VALUE]
	   ,[OPT02_INDEX]
	   ,[OPT02_VALUE]
	   ,[OPT03_INDEX]
	   ,[OPT03_VALUE]
	   ,[OPT04_INDEX]
	   ,[OPT04_VALUE]
	   ,[OPT05_INDEX]
	   ,[OPT05_VALUE]
	   ,[OPT06_INDEX]
	   ,[OPT06_VALUE]
	   ,[OPT07_INDEX]
	   ,[OPT07_VALUE]
	   ,[OPT08_INDEX]
	   ,[OPT08_VALUE]
	   ,[OPT09_INDEX]
	   ,[OPT09_VALUE]
	   ,[OPT10_INDEX]
	   ,[OPT10_VALUE]
       ,[INFLUENCE_IDX])
VALUES (@INDEX
       ,@DEFENSE_TYPE
       ,@RANGE_TYPE
       ,@TARGET_TYPE
       ,@USE_RANGE
       ,@DEFENSE_P
       ,@DEFENSE_M
       ,@ATTACK_RANGE
       ,@ATTACK_SPEED
       ,@COOL_TIME1
       ,@COOL_TIME2
       ,@ATTACK_P_MIN
       ,@ATTACK_P_MAX
       ,@ATTACK_M_MIN
       ,@ATTACK_M_MAX
	   ,@OPT01_INDEX
	   ,@OPT01_VALUE
	   ,@OPT02_INDEX
	   ,@OPT02_VALUE
	   ,@OPT03_INDEX
	   ,@OPT03_VALUE
	   ,@OPT04_INDEX
	   ,@OPT04_VALUE
	   ,@OPT05_INDEX
	   ,@OPT05_VALUE
	   ,@OPT06_INDEX
	   ,@OPT06_VALUE
	   ,@OPT07_INDEX
	   ,@OPT07_VALUE
	   ,@OPT08_INDEX
	   ,@OPT08_VALUE
	   ,@OPT09_INDEX
	   ,@OPT09_VALUE
	   ,@OPT10_INDEX
	   ,@OPT10_VALUE
       ,@INFLUENCE_IDX)

SELECT @ERRORCODE=@@ERROR, @ROWCOUNT=@@ROWCOUNT

IF @ERRORCODE <> 0 OR @ROWCOUNT <> 1
	BEGIN
		SET @RETVALUE = -1	--등록실패
	END
ELSE
	BEGIN
		SET @RETVALUE = 0	--등록성공
	END



' 
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[GP_CHARACTER_UPDATE]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'

/**********************************************************************
 *<
	FILE: GP_CHARACTER_UPDATE.SQL

	DESCRIPTION: 캐릭터 정보 업데이트

	CREATED BY: 곽철중

	HISTORY: Created	04/17/07	SQLServer2005

 *>	Copyright (c) 2007, All Rights Reserved.
 **********************************************************************/

CREATE PROCEDURE [dbo].[GP_CHARACTER_UPDATE]
	(@IDX					[int]
	,@MAP_NUMBER			[smallint]
	,@XPOS					[float]
	,@YPOS					[float]
	,@EXP					[int]
	,@SKILL_EXP				[int]
	,@HP					[int]
	,@MP					[int]
	,@TAROT_POINT			[int]
	,@TITLE_INDEX			[int]
	,@GUILD_INDEX			[int]
	,@GUILD_POSITON			[tinyint]
	,@RETVALUE				[int]OUTPUT)

AS

DECLARE @ERRORCODE	[int]
DECLARE @ROWCOUNT	[int]

SET NOCOUNT ON

UPDATE [dbo].[TB_CHARACTER]
   SET [MAP_NUM]		= @MAP_NUMBER
	  ,[XPOS]			= @XPOS
	  ,[YPOS]			= @YPOS
	  ,[EXP]			= @EXP
	  ,[SKILL_EXP]		= @SKILL_EXP
	  ,[HP]				= @HP
	  ,[MP]				= @MP
	  ,[TAROT_POINT]	= @TAROT_POINT
	  ,[TITLE_INDEX]	= @TITLE_INDEX
	  ,[GUILD_INDEX]	= @GUILD_INDEX
	  ,[GUILD_POSITION]	= @GUILD_POSITON
 WHERE [IDX] = @IDX

SELECT @ERRORCODE = @@ERROR, @ROWCOUNT = @@ROWCOUNT

IF @ERRORCODE <> 0 OR @ROWCOUNT <> 1
	BEGIN
		SET @RETVALUE = 1	--업데이트 실패
	END
ELSE
	BEGIN
		SET @RETVALUE = 0	--업데이트 성공
	END
' 
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[GP_CHARACTER_SELECT]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'

/**********************************************************************
 *<
	FILE: GP_CHARACTER_SELECT.SQL

	DESCRIPTION: 캐릭터 선택

	CREATED BY: 곽철중

	HISTORY:

 *>	Copyright (c) 2007, All Rights Reserved.
 **********************************************************************/

CREATE PROCEDURE [dbo].[GP_CHARACTER_SELECT]
	(@CHARACTER_IDX	[int]
	,@USER_IDX		[int])

AS

SET NOCOUNT ON

SELECT [IDX]
      ,[NAME]
      ,[LEVEL]
      ,[RACE]
      ,[GENDER]
      ,[JOB]
      ,[HAIR]
      ,[FACE]
      ,[HAT]
      ,[BODY1]
      ,[BODY2]
      ,[HAND]
      ,[FOOT]
      ,[EARRING]
      ,[NECKLACE]
      ,[BROOCH]
      ,[BRACELET]
      ,[RING]
      ,[LEFT_HAND]
      ,[LEFT_HAND_ENHANCED]
      ,[RIGHT_HAND]
      ,[RIGHT_HAND_ENHANCED]
	  ,[ACTIVE_WEAPON]
      ,[MAP_NUM]
      ,[XPOS]
      ,[YPOS]
      ,[EXP]
      ,[HP]
      ,[MP]
      ,[SKILL_LEVEL]
      ,[SKILL_POINT_REMAIN]
	  ,[SKILL_POINT_TOTAL]
      ,[SKILL_EXP]
      ,[TAROT_POINT]
      ,[MONEY]
      ,[DEPOSIT]
      ,[OPTION1]
      ,[FORCE_TYPE]
      ,[PVP_POINT]
      ,[FIRE_POINT]
      ,[FIRE_FRIENDLY]
      ,[WATER_POINT]
      ,[WATER_FRIENDLY]
      ,[WIND_POINT]
      ,[WIND_FRIENDLY]
      ,[EARTH_POINT]
      ,[EARTH_FRIENDLY]
	  ,[TITLE_INDEX]
	  ,[GUILD_INDEX]
	  ,[GUILD_POSITION]
      ,[MAKE_SKILL1]
      ,[MAKE_SKILL2]
  FROM [dbo].[TB_CHARACTER]
 WHERE [IDX]=@CHARACTER_IDX
   AND [USER_IDX]=@USER_IDX
   AND [APPLY]=0

--접속일 기록
IF @@ROWCOUNT = 1
	BEGIN
		UPDATE [dbo].[TB_CHARACTER]
		   SET [LAST_DATE]=GETDATE()
		 WHERE [IDX]=@CHARACTER_IDX
	END
' 
END
GO
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[GP_VERIFY_ITEM_CARD_SLOT]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'
/**********************************************************************
 *<
	FILE: GP_VERIFY_ITEM_CARD_SLOT.SQL

	DESCRIPTION:

	CREATED BY:

	HISTORY:

 *>	Copyright (c) 2008, All Rights Reserved.
 **********************************************************************/

CREATE PROCEDURE [dbo].[GP_VERIFY_ITEM_CARD_SLOT]
	(@COUNT    [int]OUTPUT
	,@RETVALUE [int]OUTPUT)

AS

SET NOCOUNT ON

DECLARE @MAX [int]

SELECT @COUNT=COUNT(IDX)
      ,@MAX  =MAX(IDX)
  FROM [dbo].[TB_ITEM_CARD_SLOT]
  
SET @RETVALUE = @COUNT - @MAX
' 
END
GO
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[GP_ITEM_CARD_SLOT_INSERT]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'
/**********************************************************************
 *<
	FILE: GP_ITEM_CARD_SLOT_INSERT.SQL

	DESCRIPTION:

	CREATED BY:

	HISTORY:

 *>	Copyright (c) 2008, All Rights Reserved.
 **********************************************************************/

CREATE PROCEDURE [dbo].[GP_ITEM_CARD_SLOT_INSERT]
	(@INDEX		[int]			--기획:분류번호
    ,@SLOT1		[tinyint]		--카드슬롯1(0없음/1A형/2B형/3AB형/4O형)
    ,@SLOT2		[tinyint]		--카드슬롯2(0없음/1A형/2B형/3AB형/4O형)
    ,@SLOT3		[tinyint]		--카드슬롯3(0없음/1A형/2B형/3AB형/4O형)
    ,@SLOT4		[tinyint]		--카드슬롯4(0없음/1A형/2B형/3AB형/4O형)
    ,@SLOT5		[tinyint]		--카드슬롯5(0없음/1A형/2B형/3AB형/4O형)
    ,@RETVALUE	[int]OUTPUT)	--반환값

AS

SET NOCOUNT ON

DECLARE @ERRORCODE		[int]
DECLARE @ROWCOUNT		[int]

INSERT [dbo].[TB_ITEM_CARD_SLOT]
	   ([INDEX]
       ,[SLOT1]
       ,[SLOT2]
       ,[SLOT3]
       ,[SLOT4]
       ,[SLOT5])
VALUES (@INDEX
       ,@SLOT1
       ,@SLOT2
       ,@SLOT3
       ,@SLOT4
       ,@SLOT5)

SELECT @ERRORCODE=@@ERROR, @ROWCOUNT=@@ROWCOUNT

IF @ERRORCODE <> 0 OR @ROWCOUNT <> 1
	BEGIN
		SET @RETVALUE = -1	--등록실패
	END
ELSE
	BEGIN
		SET @RETVALUE = 0	--등록성공
	END
' 
END
GO
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[GP_ITEM_CARD_SLOT_SELECT]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'
/**********************************************************************
 *<
	FILE: GP_ITEM_CARD_SLOT_SELECT.SQL

	DESCRIPTION: TB_ITEM_CARD_SLOT를 분할 로딩.

	CREATED BY: 곽철중

	HISTORY:

 *>	Copyright (c) 2008, All Rights Reserved.
 **********************************************************************/

CREATE PROCEDURE [dbo].[GP_ITEM_CARD_SLOT_SELECT]
	(@IDX	[int])		--고유번호

AS

SET NOCOUNT ON

SELECT [IDX] 
      ,[INDEX]
      ,[SLOT1]
      ,[SLOT2]
      ,[SLOT3]
      ,[SLOT4]
      ,[SLOT5]
  FROM [dbo].[TB_ITEM_CARD_SLOT]
 WHERE [IDX]=@IDX
' 
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[GP_ITEM_LIMIT_INSERT]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'

/**********************************************************************
 *<
	FILE: GP_ITEM_LIMIT_INSERT.SQL

	DESCRIPTION:

	CREATED BY:

	HISTORY:

 *>	Copyright (c) 2007, All Rights Reserved.
 **********************************************************************/

CREATE PROCEDURE [dbo].[GP_ITEM_LIMIT_INSERT]
	(@INDEX			[int]
    ,@CHAR_RACE		[tinyint]
    ,@CHAR_GENDER	[tinyint]
    ,@CHAR_JOB		[int]
    ,@CHAR_LEVEL	[tinyint]
	,@PVP_ONLY		[tinyint]
    ,@RETVALUE		[int]OUTPUT)

AS

SET NOCOUNT ON

DECLARE @ERRORCODE		[int]
DECLARE @ROWCOUNT		[int]

INSERT [dbo].[TB_ITEM_LIMIT]
	   ([INDEX]
       ,[CHAR_RACE]
       ,[CHAR_GENDER]
       ,[CHAR_JOB]
       ,[CHAR_LEVEL]
	   ,[PVP_ONLY])

VALUES (@INDEX
       ,@CHAR_RACE
       ,@CHAR_GENDER
       ,@CHAR_JOB
       ,@CHAR_LEVEL
	   ,@PVP_ONLY)

SELECT @ERRORCODE=@@ERROR, @ROWCOUNT=@@ROWCOUNT

IF @ERRORCODE <> 0 OR @ROWCOUNT <> 1
	BEGIN
		SET @RETVALUE = -1	--등록실패
	END
ELSE
	BEGIN
		SET @RETVALUE = 0	--등록성공
	END

' 
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[GP_ITEM_LIMIT_SELECT]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'

/**********************************************************************
 *<
	FILE: GP_ITEM_LIMIT_SELECT.SQL

	DESCRIPTION: TB_ITEM_LIMIT를 분할 로딩.

	CREATED BY: 곽철중

	HISTORY: 08/03/26 GP_ITEM_LIMIT_TABLE를 수정하여 새로 코딩.

 *>	Copyright (c) 2008, All Rights Reserved.
 **********************************************************************/

CREATE PROCEDURE [dbo].[GP_ITEM_LIMIT_SELECT]
	(@IDX	[int])		--고유번호

AS

SET NOCOUNT ON

SELECT [IDX]
      ,[INDEX]
      ,[CHAR_RACE]
      ,[CHAR_GENDER]
      ,[CHAR_JOB]
      ,[CHAR_LEVEL]
	  ,[PVP_ONLY]
  FROM [dbo].[TB_ITEM_LIMIT]
 WHERE [IDX]=@IDX

' 
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[GP_ITEM_CHANGE_INSERT]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'

/**********************************************************************
 *<
	FILE: GP_ITEM_CHANGE_INSERT.SQL

	DESCRIPTION:

	CREATED BY: 곽철중

	HISTORY: 08/04/28 생성

 *>	Copyright (c) 2008, All Rights Reserved.
 **********************************************************************/

CREATE PROCEDURE [dbo].[GP_ITEM_CHANGE_INSERT]
	(@INDEX					[int]			--기획:분류번호
    ,@MIN_MONEY				[int]			--최소금액
    ,@MAX_MONEY				[int]			--최대금액
	,@RATE					[varchar](MAX)	--아이템추가확률[ANY]
    ,@ITEM_DEFINE_INDEXS	[varchar](MAX)	--TB_ITEM_DEFINE::INDEX[ANY]
    ,@INVENTORY_COUNTS		[varchar](MAX)	--TB_INVENTORY::COUNTX[ANY]
    ,@RETVALUE				[int]OUTPUT)	--반환값

AS

SET NOCOUNT ON

DECLARE @ERRORCODE		[int]
DECLARE @ROWCOUNT		[int]

INSERT [dbo].[TB_ITEM_CHANGE]
       ([INDEX]
       ,[MIN_MONEY]
       ,[MAX_MONEY]
       ,[RATE]
       ,[ITEM_DEFINE_INDEXS]
       ,[INVENTORY_COUNTS])
VALUES
       (@INDEX
       ,@MIN_MONEY
       ,@MAX_MONEY
       ,@RATE
       ,@ITEM_DEFINE_INDEXS
       ,@INVENTORY_COUNTS)

SELECT @ERRORCODE=@@ERROR, @ROWCOUNT=@@ROWCOUNT

IF @ERRORCODE <> 0 OR @ROWCOUNT <> 1
	BEGIN
		SET @RETVALUE = -1	--등록실패
	END
ELSE
	BEGIN
		SET @RETVALUE = 0	--등록성공
	END
' 
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[GP_ITEM_CHANGE_SELECT]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'

/**********************************************************************
 *<
	FILE: GP_ITEM_CHANGE_SELECT.SQL

	DESCRIPTION: TB_ITEM_CHANGE를 분할 로딩.

	CREATED BY: 곽철중

	HISTORY:

 *>	Copyright (c) 2008, All Rights Reserved.
 **********************************************************************/

CREATE PROCEDURE [dbo].[GP_ITEM_CHANGE_SELECT]
	(@IDX	[int])	--고유번호

AS

SET NOCOUNT ON

SELECT [IDX]
      ,[INDEX]
      ,[MIN_MONEY]
      ,[MAX_MONEY]
      ,[RATE]
      ,[ITEM_DEFINE_INDEXS]
      ,[INVENTORY_COUNTS]
  FROM [dbo].[TB_ITEM_CHANGE]
 WHERE [IDX]=@IDX

' 
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[GP_CHARACTER_MAKESKILL_INSERT]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'




/**********************************************************************
 *<
	FILE: GP_CHARACTER_MAKESKILL_INSERT.SQL

	DESCRIPTION:

	CREATED BY: PKH

	HISTORY:

 *>	Copyright (c) 2009, All Rights Reserved.
 **********************************************************************/

CREATE PROCEDURE [dbo].[GP_CHARACTER_MAKESKILL_INSERT]
(
	@CHARACTER_IDX	[int],			-- 캐릭터 고유번호
	@ISFIRSTSKILL	[tinyint],		-- 직업 위치 1번,2번구분
	@MAKESKILL		[tinyint],		-- 전문기술
	@INVENTORY_IDX	[int],			--사용아이템
	@RETVALUE		[int]OUTPUT
)

AS

SET @RETVALUE = 0

DECLARE @ERRORCODE			[int]
DECLARE @ROWCOUNT			[int]

SET NOCOUNT ON

BEGIN TRAN

--사용 아이템
IF @INVENTORY_IDX > 0
BEGIN
	-- 아이템 수량 감소
	UPDATE [DBO].[TB_INVENTORY]
	   SET [COUNT]=[COUNT]-1
	 WHERE [IDX]=@INVENTORY_IDX

	IF @@ERROR <> 0 OR @@ROWCOUNT <> 1
		BEGIN
			SET @RETVALUE = 1
			ROLLBACK TRAN
			RETURN
		END

	-- 갯수가 0이면 사용 안함 플레그 설정
	UPDATE [dbo].[TB_INVENTORY]
	   SET [APPLY]=1
	 WHERE [IDX]=@INVENTORY_IDX
	   AND [COUNT]=0

	IF @@ERROR <> 0 OR @@ROWCOUNT <> 1
		BEGIN
			SET @RETVALUE = 2
			ROLLBACK TRAN
			RETURN
		END
END

-- 전문 기술 정보 갱신
IF @ISFIRSTSKILL = 1
	BEGIN
		UPDATE		[DBO].[TB_CHARACTER]
		SET			[MAKE_SKILL1] = @MAKESKILL
		WHERE		[IDX] = @CHARACTER_IDX
	END
ELSE
	BEGIN
		UPDATE		[DBO].[TB_CHARACTER]
		SET			[MAKE_SKILL2] = @MAKESKILL
		WHERE		[IDX] = @CHARACTER_IDX
	END

SELECT		@ERRORCODE=@@ERROR, @ROWCOUNT=@@ROWCOUNT

IF @ERRORCODE <> 0 OR @ROWCOUNT <> 1
	BEGIN
		SET @RETVALUE = 3
		ROLLBACK TRAN
		RETURN
	END
ELSE
	BEGIN
		SELECT		[IDX],
					(SELECT [IDX] FROM [dbo].[TB_ITEM_DEFINE] WHERE [INDEX]=[ITEM_DEFINE_INDEX]) AS ''ITEM_DEFINE_IDX'',
					[ITEM_DEFINE_INDEX],
					[NUMBER],
					[COUNT],
					[ENHANCED],
					[CARD_SLOT1],
					[CARD_SLOT2],
					[CARD_SLOT3],
					[CARD_SLOT4],
					[CARD_SLOT5],
					[SEAL],
					[APPLY]
		FROM		[dbo].[TB_INVENTORY]
		WHERE		[IDX]=@INVENTORY_IDX

		SELECT @ROWCOUNT=@@ROWCOUNT
		
		IF @ERRORCODE <> 0 OR @ROWCOUNT > 1
		BEGIN
			SET @RETVALUE = 4
			ROLLBACK TRAN
			RETURN
		END

		SET @RETVALUE = 0
		COMMIT TRAN
	END









' 
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[GP_ITEM_SELL]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'


/**********************************************************************
 *<
	FILE: GP_ITEM_SELL.SQL

	DESCRIPTION:

	CREATED BY:	곽철중

	HISTORY:	2008-03-17 테이블 필드 삭제(TYPE)및 수정(SEAL).

 *>	Copyright (c) 2007, All Rights Reserved.
 **********************************************************************/

CREATE PROCEDURE [dbo].[GP_ITEM_SELL]
	(@CHARACTER_IDX		[int]		--캐 릭 터 고유번호
	,@INVENTORY_IDX		[int]		--인벤토리 고유번호
	,@ITEM_DEFINE_INDEX	[int]		--아 이 템 인 덱 스
	,@COUNT				[smallint]  --적용수량 (+-)
	,@NUMBER			[smallint]) --인벤토리 번호(슬롯)

AS

SET NOCOUNT ON

DECLARE @ERRORCODE	  [int]
DECLARE @ROWCOUNT	  [int]

IF @INVENTORY_IDX > 0
	BEGIN
		IF @COUNT < 0
			BEGIN
				UPDATE [dbo].[TB_INVENTORY]
				   SET [COUNT]=[COUNT]+@COUNT
				 WHERE [IDX]=@INVENTORY_IDX
				   AND [COUNT]>=@COUNT

				UPDATE [dbo].[TB_INVENTORY]
				   SET [APPLY]=1
				 WHERE [IDX]=@INVENTORY_IDX
				   AND [COUNT]<=0
			END
		ELSE
			BEGIN
				UPDATE [dbo].[TB_INVENTORY]
				   SET [COUNT]=[COUNT]+@COUNT
				 WHERE [IDX]=@INVENTORY_IDX
			END
	END
ELSE
	BEGIN
		INSERT [dbo].[TB_INVENTORY]
			   ([CHARACTER_IDX]
			   ,[ITEM_DEFINE_INDEX]
			   ,[NUMBER]
			   ,[COUNT])
		VALUES (@CHARACTER_IDX
			   ,@ITEM_DEFINE_INDEX
			   ,@NUMBER
			   ,@COUNT)

		SELECT @ERRORCODE = @@ERROR, @ROWCOUNT = @@ROWCOUNT

		IF @ERRORCODE <> 0 OR @ROWCOUNT <> 1
			BEGIN
				RETURN 99
			END

		SELECT @INVENTORY_IDX=MAX(IDX)
          FROM [dbo].[TB_INVENTORY]
         WHERE [CHARACTER_IDX]=@CHARACTER_IDX
	END

SELECT [IDX]
	  ,(SELECT [IDX] FROM [dbo].[TB_ITEM_DEFINE] WHERE [INDEX]=[ITEM_DEFINE_INDEX]) AS ''ITEM_DEFINE_IDX''
      ,[ITEM_DEFINE_INDEX]
      ,[NUMBER]
      ,[COUNT]
	  ,[ENHANCED]
	  ,[CARD_SLOT1]
	  ,[CARD_SLOT2]
	  ,[CARD_SLOT3]
	  ,[CARD_SLOT4]
	  ,[CARD_SLOT5]
      ,[SEAL]
	  ,[APPLY]
  FROM [dbo].[TB_INVENTORY]
 WHERE [IDX]=@INVENTORY_IDX

' 
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[GP_INVENTORY_INSERT]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'



/**********************************************************************
 *<
	FILE: GP_INVENTORY_INSERT.SQL

	DESCRIPTION: 아이템 생성

	CREATED BY:

	HISTORY:

 *>	Copyright (c) 2008, All Rights Reserved.
 **********************************************************************/

CREATE PROCEDURE [dbo].[GP_INVENTORY_INSERT]
	(@CHARACTER_IDX			[int]			--캐릭터 고유번호
	,@ITEM_DEFINE_INDEX		[int]			--아이템 인덱스
	,@INVENTORY_NUMBER		[smallint]		--인벤토리 번호
	,@INVENTORY_COUNT		[smallint]		--수량
	,@INVENTORY_ENHANCED	[tinyint]		--강화
	,@INVENTORY_CARDSLOT1	[int]			--카드슬롯1
	,@INVENTORY_CARDSLOT2	[int]			--카드슬롯2
	,@INVENTORY_CARDSLOT3	[int]			--카드슬롯3
	,@INVENTORY_CARDSLOT4	[int]			--카드슬롯4
	,@INVENTORY_CARDSLOT5	[int]			--카드슬롯5
	,@INVENTORY_SEAL		[tinyint])		--봉인

AS

SET NOCOUNT ON

DECLARE @ERRORCODE	[int]
DECLARE @ROWCOUNT	[int]
DECLARE @IDX		[int]


INSERT [dbo].[TB_INVENTORY]
	   ([CHARACTER_IDX]
	   ,[ITEM_DEFINE_INDEX]
	   ,[NUMBER]
	   ,[COUNT]
	   ,[ENHANCED]
	   ,[CARD_SLOT1]
	   ,[CARD_SLOT2]
	   ,[CARD_SLOT3]
	   ,[CARD_SLOT4]
	   ,[CARD_SLOT5]
	   ,[SEAL])
VALUES (@CHARACTER_IDX
	   ,@ITEM_DEFINE_INDEX
	   ,@INVENTORY_NUMBER
	   ,@INVENTORY_COUNT
	   ,@INVENTORY_ENHANCED
	   ,@INVENTORY_CARDSLOT1
	   ,@INVENTORY_CARDSLOT2
	   ,@INVENTORY_CARDSLOT3
	   ,@INVENTORY_CARDSLOT4
	   ,@INVENTORY_CARDSLOT5
	   ,@INVENTORY_SEAL)

IF @@ERROR <> 0 OR @@ROWCOUNT <> 1
	BEGIN
		RETURN 99
	END

SELECT @IDX=MAX(IDX)
  FROM [dbo].[TB_INVENTORY]
 WHERE [CHARACTER_IDX]=@CHARACTER_IDX

SELECT [IDX]
	  ,(SELECT [IDX] FROM [dbo].[TB_ITEM_DEFINE] WHERE [INDEX]=[ITEM_DEFINE_INDEX]) AS ''ITEM_DEFINE_IDX''
	  ,[ITEM_DEFINE_INDEX]
	  ,[NUMBER]
	  ,[COUNT]
	  ,[ENHANCED]
	  ,[CARD_SLOT1]
	  ,[CARD_SLOT2]
	  ,[CARD_SLOT3]
	  ,[CARD_SLOT4]
	  ,[CARD_SLOT5]
	  ,[SEAL]
	  ,[APPLY]
  FROM TB_INVENTORY
 WHERE [IDX]=@IDX



' 
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[GP_ITEM_DEFINE_INSERT]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'



/**********************************************************************
 *<
	FILE: GP_ITEM_DEFINE_INSERT.SQL

	DESCRIPTION:

	CREATED BY:

	HISTORY:

 *>	Copyright (c) 2007, All Rights Reserved.
 **********************************************************************/

CREATE PROCEDURE [dbo].[GP_ITEM_DEFINE_INSERT]
	(@INDEX					[int]			--기획:분류번호
    ,@NAME					[nvarchar](50)	--이름
    ,@TYPE					[tinyint]		--종류(기획참조)
    ,@SUB_TYPE				[tinyint]		--종류(기획참조)
    ,@WEIGHT				[smallint]		--무게
    ,@CAPACITY				[smallint]		--제한수량
	,@SELL_TYPE				[int]			--판매방법
    ,@SELL_PRICE			[int]			--판매가격
	,@BUY_TYPE 				[int]			--구입방법
    ,@BUY_PRICE				[int]			--구입가격
    ,@MAX_PRESENT			[int]			--출현수
	,@EXCHANGE              [tinyint]       --사용자거래여부
	,@MAX_INVENTORY			[int]			--보유가능개수
    ,@ABILITY_INDEX			[int]			--기획:분류번호
    ,@LIMIT_INDEX			[int]			--기획:분류번호
    ,@CARD_INDEX			[int]			--기획:분류번호
    ,@CARD_SLOT_INDEX		[int]			--기획:분류번호
	,@TAROT_INDEX			[int]			--기획:분류번호
    ,@SPREAD_INDEX			[int]			--기획:분류번호
    ,@ENHANCED_INDEX		[int]			--기획:분류번호
    ,@ENHANCED_RATE_INDEX	[int]			--기획:분류번호
    ,@DISJOINT_INDEX		[int]			--기획:분류번호
    ,@CHANGE_INDEX			[int]			--기획:분류번호
	,@TITLE_INDEX			[int]			--기획:분류번호
    ,@RETVALUE				[int]OUTPUT)	--반환값

AS

SET NOCOUNT ON

DECLARE @ERRORCODE		[int]
DECLARE @ROWCOUNT		[int]

INSERT [dbo].[TB_ITEM_DEFINE]
	   ([INDEX]
	   ,[NAME]
	   ,[TYPE]
	   ,[SUB_TYPE]
	   ,[WEIGHT]
	   ,[CAPACITY]
	   ,[SELL_TYPE]
	   ,[SELL_PRICE]
	   ,[BUY_TYPE]
	   ,[BUY_PRICE]
	   ,[MAX_PRESENT]
	   ,[EXCHANGE]
	   ,[MAX_INVENTORY]
	   ,[ABILITY_INDEX]
	   ,[LIMIT_INDEX]
	   ,[CARD_INDEX]
	   ,[CARD_SLOT_INDEX]
	   ,[TAROT_INDEX]
	   ,[SPREAD_INDEX]
	   ,[ENHANCED_INDEX]
	   ,[ENHANCED_RATE_INDEX]
	   ,[DISJOINT_INDEX]
	   ,[CHANGE_INDEX]
	   ,[TITLE_INDEX])

VALUES (@INDEX
	   ,@NAME
	   ,@TYPE
	   ,@SUB_TYPE
	   ,@WEIGHT
	   ,@CAPACITY
	   ,@SELL_TYPE
	   ,@SELL_PRICE
	   ,@BUY_TYPE
	   ,@BUY_PRICE
	   ,@MAX_PRESENT
	   ,@EXCHANGE
	   ,@MAX_INVENTORY
	   ,@ABILITY_INDEX
	   ,@LIMIT_INDEX
	   ,@CARD_INDEX
	   ,@CARD_SLOT_INDEX
	   ,@TAROT_INDEX
	   ,@SPREAD_INDEX
	   ,@ENHANCED_INDEX
	   ,@ENHANCED_RATE_INDEX
	   ,@DISJOINT_INDEX
	   ,@CHANGE_INDEX
	   ,@TITLE_INDEX)

SELECT @ERRORCODE=@@ERROR, @ROWCOUNT=@@ROWCOUNT

IF @ERRORCODE <> 0 OR @ROWCOUNT <> 1
	BEGIN
		SET @RETVALUE = -1	--등록실패
	END
ELSE
	BEGIN
		SET @RETVALUE = 0	--등록성공
	END



' 
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[GP_INVENTORY_ENHANCED]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'



/**********************************************************************
 *<
	FILE: GP_INVENTORY_ENHANCED.SQL

	DESCRIPTION:

	CREATED BY:	곽철중

	HISTORY:	2008-03-19 생성

 *>	Copyright (c) 2008, All Rights Reserved.
 **********************************************************************/

CREATE PROCEDURE [dbo].[GP_INVENTORY_ENHANCED]
	(@IDX1		[int]			--고유번호(강화장비)
	,@IDX2      [int]			--고유번호(강화카드)
	,@RESULT    [tinyint]		--결과값
	,@RETVALUE	[int]OUTPUT)	--반환값
AS

SET NOCOUNT ON

DECLARE @ERRORCODE    [int]
       ,@ROWCOUNT     [int]

BEGIN TRAN

--강화카드 삭제
UPDATE [dbo].[TB_INVENTORY]
   SET [COUNT]=[COUNT]-1
      ,[APPLY]=1
 WHERE [IDX]=@IDX2

IF @@ERROR <> 0 OR @@ROWCOUNT <> 1
	BEGIN
		ROLLBACK
		GOTO INVENTORY_SELECT
	END

IF @RESULT = 0
	BEGIN
	--성공
		UPDATE [dbo].[TB_INVENTORY]
		   SET [ENHANCED]=[ENHANCED]+1
			  ,[CARD_SLOT1]=0
			  ,[CARD_SLOT2]=0
			  ,[CARD_SLOT3]=0
			  ,[CARD_SLOT4]=0
			  ,[CARD_SLOT5]=0
		 WHERE [IDX]=@IDX1

		IF @@ERROR <> 0 OR @@ROWCOUNT <> 1
			BEGIN
				ROLLBACK
				GOTO INVENTORY_SELECT
			END
	END
ELSE IF @RESULT = 1
	BEGIN
	--감소
		UPDATE [dbo].[TB_INVENTORY]
		   SET [ENHANCED]=[ENHANCED]-1
			  ,[CARD_SLOT1]=0
			  ,[CARD_SLOT2]=0
			  ,[CARD_SLOT3]=0
			  ,[CARD_SLOT4]=0
			  ,[CARD_SLOT5]=0
		 WHERE [IDX]=@IDX1

		IF @@ERROR <> 0 OR @@ROWCOUNT <> 1
			BEGIN
				ROLLBACK
				GOTO INVENTORY_SELECT
			END
	END
ELSE IF @RESULT = 2
	BEGIN
	--파괴
		UPDATE [dbo].[TB_INVENTORY]
		   SET [COUNT]=[COUNT]-1
			  ,[APPLY]=1
		 WHERE [IDX]=@IDX1

		IF @@ERROR <> 0 OR @@ROWCOUNT <> 1
			BEGIN
				ROLLBACK
				GOTO INVENTORY_SELECT
			END
	END
--ELSE
--	BEGIN
--	--변화없음
--	END

COMMIT

INVENTORY_SELECT:

--강화장비
SELECT [IDX]
	  ,(SELECT [IDX] FROM [dbo].[TB_ITEM_DEFINE] WHERE [INDEX]=[ITEM_DEFINE_INDEX]) AS ''ITEM_DEFINE_IDX''
	  ,[ITEM_DEFINE_INDEX]
      ,[NUMBER]
      ,[COUNT]
	  ,[ENHANCED]
	  ,[CARD_SLOT1]
	  ,[CARD_SLOT2]
	  ,[CARD_SLOT3]
	  ,[CARD_SLOT4]
	  ,[CARD_SLOT5]
      ,[SEAL]
      ,[APPLY]
  FROM TB_INVENTORY
 WHERE [IDX]=@IDX1

--강화카드
SELECT [IDX]
	  ,(SELECT [IDX] FROM [dbo].[TB_ITEM_DEFINE] WHERE [INDEX]=[ITEM_DEFINE_INDEX]) AS ''ITEM_DEFINE_IDX''
	  ,[ITEM_DEFINE_INDEX]
      ,[NUMBER]
      ,[COUNT]
	  ,[ENHANCED]
	  ,[CARD_SLOT1]
	  ,[CARD_SLOT2]
	  ,[CARD_SLOT3]
	  ,[CARD_SLOT4]
	  ,[CARD_SLOT5]
      ,[SEAL]
      ,[APPLY]
  FROM TB_INVENTORY
 WHERE [IDX]=@IDX2



' 
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[GP_ITEM_USE]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'

/**********************************************************************
 *<
	FILE: GP_ITEM_USE.SQL

	DESCRIPTION:

	CREATED BY:	곽철중

	HISTORY:	2008-03-17 테이블 필드 삭제(TYPE)및 수정(SEAL).

 *>	Copyright (c) 2008, All Rights Reserved.
 **********************************************************************/

CREATE PROCEDURE [dbo].[GP_ITEM_USE]
	(@INVENTORY_IDX	[int]			--인벤토리 고유번호
	,@COUNT			[smallint]		--사용갯수
	,@RETVALUE		[int]OUTPUT)	--반환값

AS

SET NOCOUNT ON

DECLARE @ERRORCODE	[int]
DECLARE @ROWCOUNT	[int]

UPDATE [dbo].[TB_INVENTORY]
   SET [COUNT]=[COUNT]-@COUNT
 WHERE [IDX]=@INVENTORY_IDX
   AND [COUNT]>=@COUNT

SELECT @ERRORCODE=@@ERROR, @ROWCOUNT=@@ROWCOUNT

IF @ERRORCODE <> 0 OR @ROWCOUNT <> 1
	BEGIN
		SET @RETVALUE = 1
	END
ELSE
	BEGIN
		UPDATE [dbo].[TB_INVENTORY]
		   SET [APPLY]=1
		 WHERE [IDX]=@INVENTORY_IDX
		   AND [COUNT]<=0

		SELECT [IDX]
			  ,(SELECT [IDX] FROM [dbo].[TB_ITEM_DEFINE] WHERE [INDEX]=[ITEM_DEFINE_INDEX]) AS ''ITEM_DEFINE_IDX''
			  ,[ITEM_DEFINE_INDEX]
			  ,[NUMBER]
			  ,[COUNT]
			  ,[ENHANCED]
			  ,[CARD_SLOT1]
			  ,[CARD_SLOT2]
			  ,[CARD_SLOT3]
			  ,[CARD_SLOT4]
			  ,[CARD_SLOT5]
			  ,[SEAL]
			  ,[APPLY]
		  FROM [dbo].[TB_INVENTORY]
		 WHERE [IDX]=@INVENTORY_IDX
		
		SET @RETVALUE = 0
	END

' 
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[GP_INVENTORY_DISJOINT]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'



/**********************************************************************
 *<
	FILE: GP_INVENTORY_DISJOINT.SQL

	DESCRIPTION: 인벤토리 분해(아이템)

	CREATED BY:	곽철중

	HISTORY:	2008-10-08 수정

 *>	Copyright (c) 2008, All Rights Reserved.
 **********************************************************************/

CREATE PROCEDURE [dbo].[GP_INVENTORY_DISJOINT]
	(@CHARACTER_IDX		int				--캐릭터   고유번호
	,@INVENTORY_IDX		int				--인벤토리 고유번호
	,@ITEM_DEFINE_INDEX	int				--아이템 정의 인덱스
	,@INVENTORY_NUMBER	smallint		--인벤토리 번호(슬롯)
	,@INVENTORY_COUNT	smallint		--인벤토리 수량
	,@RETVALUE          int output)		--반환값
AS

SET NOCOUNT ON

BEGIN TRAN

IF @INVENTORY_IDX > 0
	BEGIN
		UPDATE [dbo].[TB_INVENTORY]
		   SET [COUNT]=[COUNT]+@INVENTORY_COUNT
		 WHERE [IDX]=@INVENTORY_IDX

		IF @@ERROR <> 0 OR @@ROWCOUNT <> 1
			GOTO ROLLBACK_TRAN

		UPDATE [dbo].[TB_INVENTORY]
		   SET [APPLY]=1
		 WHERE [IDX]=@INVENTORY_IDX
		   AND [COUNT]<=0

		IF @@ERROR <> 0
			GOTO ROLLBACK_TRAN
	END
ELSE
	BEGIN
		INSERT [dbo].[TB_INVENTORY]
			   ([CHARACTER_IDX]
			   ,[ITEM_DEFINE_INDEX]
			   ,[NUMBER]
			   ,[COUNT])
		VALUES (@CHARACTER_IDX
			   ,@ITEM_DEFINE_INDEX
			   ,@INVENTORY_NUMBER
			   ,@INVENTORY_COUNT)

		IF @@ERROR <> 0 OR @@ROWCOUNT <> 1
			GOTO ROLLBACK_TRAN

		SELECT @INVENTORY_IDX=MAX(IDX)
          FROM [dbo].[TB_INVENTORY]
         WHERE [CHARACTER_IDX]=@CHARACTER_IDX
	END

COMMIT TRAN
SELECT [IDX]
	  ,(SELECT [IDX] FROM [dbo].[TB_ITEM_DEFINE] WHERE [INDEX]=[ITEM_DEFINE_INDEX]) AS ''ITEM_DEFINE_IDX''
	  ,[ITEM_DEFINE_INDEX]
      ,[NUMBER]
      ,[COUNT]
	  ,[ENHANCED]
	  ,[CARD_SLOT1]
	  ,[CARD_SLOT2]
	  ,[CARD_SLOT3]
	  ,[CARD_SLOT4]
	  ,[CARD_SLOT5]
      ,[SEAL]
      ,[APPLY]
  FROM [dbo].[TB_INVENTORY]
 WHERE [IDX]=@INVENTORY_IDX
RETURN 0

ROLLBACK_TRAN:
ROLLBACK TRAN
RETURN 99


' 
END
GO
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[GP_ITEM_CARD_INSERT]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'
/**********************************************************************
 *<
	FILE: GP_ITEM_CARD_INSERT.SQL

	DESCRIPTION:

	CREATED BY:

	HISTORY:

 *>	Copyright (c) 2007, All Rights Reserved.
 **********************************************************************/

CREATE PROCEDURE [dbo].[GP_ITEM_CARD_INSERT]
	(@INDEX			[int]
	,@EPISODE		[int]
	,@NUMBER		[int]
	,@LEVEL			[tinyint]
	,@TYPE			[tinyint]
	,@SUBTYPE		[tinyint]
	,@RETVALUE		[int]OUTPUT)

AS

SET NOCOUNT ON

DECLARE @ERRORCODE		[int]
DECLARE @ROWCOUNT		[int]

INSERT [dbo].[TB_ITEM_CARD]
	   ([INDEX]
       ,[EPISODE]
       ,[NUMBER]
       ,[LEVEL]
       ,[TYPE]
       ,[SUBTYPE])
VALUES (@INDEX
       ,@EPISODE
       ,@NUMBER
       ,@LEVEL
       ,@TYPE
       ,@SUBTYPE)

SELECT @ERRORCODE=@@ERROR, @ROWCOUNT=@@ROWCOUNT

IF @ERRORCODE <> 0 OR @ROWCOUNT <> 1
	BEGIN
		SET @RETVALUE = -1	--등록실패
	END
ELSE
	BEGIN
		SET @RETVALUE = 0	--등록성공
	END
' 
END
GO
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[GP_VERIFY_ITEM_CARD]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'
/**********************************************************************
 *<
	FILE: GP_VERIFY_ITEM_CARD.SQL

	DESCRIPTION:

	CREATED BY:

	HISTORY:

 *>	Copyright (c) 2006, All Rights Reserved.
 **********************************************************************/

CREATE PROCEDURE [dbo].[GP_VERIFY_ITEM_CARD]
	(@COUNT    [int]OUTPUT
	,@RETVALUE [int]OUTPUT)

AS

SET NOCOUNT ON

DECLARE @MAX [int]

SELECT @COUNT=COUNT(IDX)
      ,@MAX  =MAX(IDX)
  FROM [dbo].[TB_ITEM_CARD]
  
SET @RETVALUE = @COUNT - @MAX
' 
END
GO
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[GP_ITEM_CARD_SELECT]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'
/**********************************************************************
 *<
	FILE: GP_ITEM_CARD_SELECT.SQL

	DESCRIPTION: TB_ITEM_CARD를 분할 로딩.

	CREATED BY: 곽철중

	HISTORY: 08/03/26 GP_ITEM_CARD_TABLE를 수정하여 새로 코딩.

 *>	Copyright (c) 2008, All Rights Reserved.
 **********************************************************************/

CREATE PROCEDURE [dbo].[GP_ITEM_CARD_SELECT]
	(@IDX	[int])		--고유번호

AS

SET NOCOUNT ON

SELECT [IDX]
      ,[INDEX]
  FROM [dbo].[TB_ITEM_CARD]
 WHERE [IDX]=@IDX' 
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[GP_ITEM_GET]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'

/**********************************************************************
 *<
	FILE: GP_ITEM_GET.SQL

	DESCRIPTION: 아이템 습득(생성 및 업데이트)

	CREATED BY:	곽철중

	HISTORY:	2008-03-17 테이블 필드 삭제(TYPE)및 수정(SEAL).

 *>	Copyright (c) 2007, All Rights Reserved.
 **********************************************************************/

CREATE PROCEDURE [dbo].[GP_ITEM_GET]
	(@CHARACTER_IDX		[int]			--캐릭터 고유번호
	,@ITEM_DEFINE_INDEX	[int]			--아이템 인덱스
	,@INVENTORY_NUMBER	[smallint]		--인벤토리 번호
	,@COUNT				[smallint]		--수량
	,@RETVALUE			[int]OUTPUT)	--반환값

AS

SET NOCOUNT ON

DECLARE @ERRORCODE	  [int]
DECLARE @ROWCOUNT	  [int]
DECLARE @IDX	      [int]

SELECT @IDX=ISNULL([IDX], 0)
  FROM [dbo].[TB_INVENTORY]
 WHERE [CHARACTER_IDX] = @CHARACTER_IDX
   AND [NUMBER]        = @INVENTORY_NUMBER
   AND [APPLY]         = 0

IF @IDX > 0
	BEGIN
		UPDATE [dbo].[TB_INVENTORY]
           SET [COUNT]=[COUNT]+@COUNT
         WHERE [IDX]=@IDX
	END
ELSE
	BEGIN
		INSERT [dbo].[TB_INVENTORY]
			   ([CHARACTER_IDX]
			   ,[ITEM_DEFINE_INDEX]
			   ,[NUMBER]
			   ,[COUNT])
		VALUES (@CHARACTER_IDX
			   ,@ITEM_DEFINE_INDEX
			   ,@INVENTORY_NUMBER
			   ,@COUNT)

		SELECT @ERRORCODE = @@ERROR, @ROWCOUNT = @@ROWCOUNT

		IF @ERRORCODE <> 0 OR @ROWCOUNT <> 1
			BEGIN
				SET @RETVALUE = -1	--등록실패 - 알수없는 오류
				RETURN
			END

		SELECT @IDX=MAX(IDX)
          FROM [dbo].[TB_INVENTORY]
         WHERE [CHARACTER_IDX]=@CHARACTER_IDX
	END

SET @RETVALUE = 0	--등록성공
SELECT [IDX]
	  ,(SELECT [IDX] FROM [dbo].[TB_ITEM_DEFINE] WHERE [INDEX]=[ITEM_DEFINE_INDEX]) AS ''ITEM_DEFINE_IDX''
	  ,[ITEM_DEFINE_INDEX]
	  ,[NUMBER]
	  ,[COUNT]
	  ,[ENHANCED]
	  ,[CARD_SLOT1]
	  ,[CARD_SLOT2]
	  ,[CARD_SLOT3]
	  ,[CARD_SLOT4]
	  ,[CARD_SLOT5]
	  ,[SEAL]
	  ,[APPLY]
  FROM TB_INVENTORY
 WHERE [IDX]=@IDX

' 
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[GP_ITEM_BUY]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'


/**********************************************************************
 *<
	FILE: GP_ITEM_BUY.SQL

	DESCRIPTION: 아이템 구입

	CREATED BY:	곽철중

	HISTORY:

 *>	Copyright (c) 2007, All Rights Reserved.
 **********************************************************************/

CREATE PROCEDURE [dbo].[GP_ITEM_BUY]
	(@CHARACTER_IDX		[int]		--캐 릭 터 고유번호
	,@INVENTORY_IDX		[int]		--인벤토리 고유번호
	,@ITEM_DEFINE_INDEX	[int]		--아 이 템 인 덱 스
	,@COUNT				[smallint]  --적용수량 (+-)
	,@NUMBER			[smallint]) --인벤토리 번호(슬롯)

AS

SET NOCOUNT ON

DECLARE @ERRORCODE	  [int]
DECLARE @ROWCOUNT	  [int]

IF @INVENTORY_IDX > 0
	BEGIN
		IF @COUNT < 0
			BEGIN
				UPDATE [dbo].[TB_INVENTORY]
				   SET [COUNT]=[COUNT]+@COUNT
				 WHERE [IDX]=@INVENTORY_IDX
				   AND [COUNT]>=@COUNT

				UPDATE [dbo].[TB_INVENTORY]
				   SET [APPLY]=1
				 WHERE [IDX]=@INVENTORY_IDX
				   AND [COUNT]=0
			END
		ELSE
			BEGIN
				UPDATE [dbo].[TB_INVENTORY]
				   SET [COUNT]=[COUNT]+@COUNT
				 WHERE [IDX]=@INVENTORY_IDX
			END
	END
ELSE
	BEGIN
		INSERT [dbo].[TB_INVENTORY]
			   ([CHARACTER_IDX]
			   ,[ITEM_DEFINE_INDEX]
			   ,[NUMBER]
			   ,[COUNT])
		VALUES (@CHARACTER_IDX
			   ,@ITEM_DEFINE_INDEX
			   ,@NUMBER
			   ,@COUNT)

		SELECT @ERRORCODE = @@ERROR, @ROWCOUNT = @@ROWCOUNT

		IF @ERRORCODE <> 0 OR @ROWCOUNT <> 1
			BEGIN
				RETURN 99
			END

		SELECT @INVENTORY_IDX=MAX(IDX)
          FROM [dbo].[TB_INVENTORY]
         WHERE [CHARACTER_IDX]=@CHARACTER_IDX
	END

SELECT [IDX]
	  ,(SELECT [IDX] FROM [dbo].[TB_ITEM_DEFINE] WHERE [INDEX]=[ITEM_DEFINE_INDEX]) AS ''ITEM_DEFINE_IDX''
      ,[ITEM_DEFINE_INDEX]
      ,[NUMBER]
      ,[COUNT]
	  ,[ENHANCED]
	  ,[CARD_SLOT1]
	  ,[CARD_SLOT2]
	  ,[CARD_SLOT3]
	  ,[CARD_SLOT4]
	  ,[CARD_SLOT5]
      ,[SEAL]
	  ,[APPLY]
  FROM [dbo].[TB_INVENTORY]
 WHERE [IDX]=@INVENTORY_IDX

' 
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[GP_INVENTORY_MERGE]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'

/**********************************************************************
 *<
	FILE: GP_INVENTORY_MERGE.SQL

	DESCRIPTION:

	CREATED BY:	곽철중

	HISTORY:	2008-03-17 테이블 필드 삭제(TYPE)및 수정(SEAL).

 *>	Copyright (c) 2007, All Rights Reserved.
 **********************************************************************/

CREATE PROCEDURE [dbo].[GP_INVENTORY_MERGE]
	(@IDX1	[int]	--고유번호1
	,@IDX2	[int])	--고유번호2

AS

DECLARE @ERRORCODE	[int]
DECLARE @ROWCOUNT	[int]

DECLARE @COUNT		[smallint]
DECLARE @CAPACITY	[smallint]

SET NOCOUNT ON

SELECT @CAPACITY=[CAPACITY]
  FROM TB_ITEM_DEFINE
 WHERE [INDEX]=(SELECT [ITEM_DEFINE_INDEX] FROM TB_INVENTORY WHERE [IDX]=@IDX1)

SELECT @COUNT=SUM([COUNT])
  FROM TB_INVENTORY
 WHERE [IDX] IN (@IDX1, @IDX2)

BEGIN TRAN

IF @COUNT > @CAPACITY
	BEGIN
		UPDATE TB_INVENTORY
		   SET [COUNT]=@CAPACITY
		 WHERE [IDX]=@IDX2

		IF @@ERROR <> 0 OR @@ROWCOUNT <> 1
			GOTO ROLLBACK_TRAN

		SET @COUNT=(@COUNT-@CAPACITY)

		UPDATE TB_INVENTORY
		   SET [COUNT]=@COUNT
		 WHERE [IDX]=@IDX1

		IF @@ERROR <> 0 OR @@ROWCOUNT <> 1
			GOTO ROLLBACK_TRAN

		COMMIT TRAN
	END
ELSE
	BEGIN
		UPDATE TB_INVENTORY
		   SET [COUNT]=@COUNT
		 WHERE [IDX]=@IDX2

		IF @@ERROR <> 0 OR @@ROWCOUNT <> 1
			GOTO ROLLBACK_TRAN

		UPDATE TB_INVENTORY
		   SET [COUNT]=0, [APPLY]=1
		 WHERE [IDX]=@IDX1

		IF @@ERROR <> 0 OR @@ROWCOUNT <> 1
			GOTO ROLLBACK_TRAN

		COMMIT TRAN
	END

SELECT_TABLE:
SELECT [IDX]
--SKIP,(SELECT [IDX] FROM [dbo].[TB_ITEM_DEFINE] WHERE [INDEX]=[ITEM_DEFINE_INDEX]) AS ''ITEM_DEFINE_IDX''
	  ,[ITEM_DEFINE_INDEX]
      ,[NUMBER]
      ,[COUNT]
	  ,[ENHANCED]
--SKIP,[CARD_SLOT1]
--SKIP,[CARD_SLOT2]
--SKIP,[CARD_SLOT3]
--SKIP,[CARD_SLOT4]
--SKIP,[CARD_SLOT5]
      ,[SEAL]
	  ,[APPLY]
  FROM TB_INVENTORY
 WHERE [IDX] IN (@IDX1, @IDX2)
RETURN

ROLLBACK_TRAN:
ROLLBACK TRAN
RETURN 99
' 
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[GP_INVENTORY_MOVE2]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'


/**********************************************************************
 *<
	FILE: GP_INVENTORY_MOVE2.SQL

	DESCRIPTION:

	CREATED BY:	곽철중

	HISTORY:	2008-03-17 테이블 필드 삭제(TYPE)및 수정(SEAL).

 *>	Copyright (c) 2007, All Rights Reserved.
 **********************************************************************/

CREATE PROCEDURE [dbo].[GP_INVENTORY_MOVE2]
	(@CHARACTER_IDX		[int]		--캐 릭 터 고유번호
	,@INVENTORY_IDX		[int]		--인벤토리 고유번호
	,@ITEM_DEFINE_INDEX	[int]		--아 이 템 인 덱 스
	,@COUNT				[smallint]  --적용수량 (+-)
	,@NUMBER			[smallint]) --인벤토리 번호(슬롯)

AS

SET NOCOUNT ON

DECLARE @ERRORCODE	  [int]
DECLARE @ROWCOUNT	  [int]

IF @INVENTORY_IDX > 0
	BEGIN
		UPDATE [dbo].[TB_INVENTORY]
		   SET [COUNT]=@COUNT
              ,[NUMBER]=@NUMBER
		 WHERE [IDX]=@INVENTORY_IDX
	END
ELSE
	BEGIN
		INSERT [dbo].[TB_INVENTORY]
			   ([CHARACTER_IDX]
			   ,[ITEM_DEFINE_INDEX]
			   ,[NUMBER]
			   ,[COUNT])
		VALUES (@CHARACTER_IDX
			   ,@ITEM_DEFINE_INDEX
			   ,@NUMBER
			   ,@COUNT)

		SELECT @ERRORCODE = @@ERROR, @ROWCOUNT = @@ROWCOUNT

		IF @ERRORCODE <> 0 OR @ROWCOUNT <> 1
			BEGIN
				RETURN 99
			END

		SELECT @INVENTORY_IDX=MAX(IDX)
          FROM [dbo].[TB_INVENTORY]
         WHERE [CHARACTER_IDX]=@CHARACTER_IDX
	END

SELECT [IDX]
--SKIP,(SELECT [IDX] FROM [dbo].[TB_ITEM_DEFINE] WHERE [INDEX]=[ITEM_DEFINE_INDEX]) AS ''ITEM_DEFINE_IDX''
	  ,[ITEM_DEFINE_INDEX]
      ,[NUMBER]
      ,[COUNT]
	  ,[ENHANCED]
--SKIP,[CARD_SLOT1]
--SKIP,[CARD_SLOT2]
--SKIP,[CARD_SLOT3]
--SKIP,[CARD_SLOT4]
--SKIP,[CARD_SLOT5]
      ,[SEAL]
      ,[APPLY]
  FROM [dbo].[TB_INVENTORY]
 WHERE [IDX]=@INVENTORY_IDX
' 
END
GO
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[GP_ITEM_EXCHANGE]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'
/**********************************************************************
 *<
	FILE: GP_ITEM_EXCHANGE.SQL

	DESCRIPTION: 아이템 거래

	CREATED BY:

	HISTORY:

 *>	Copyright (c) 2008, All Rights Reserved.
 **********************************************************************/

CREATE PROCEDURE [dbo].[GP_ITEM_EXCHANGE]
	(@CHARACTER_IDX		[int]			--캐릭터 고유번호
	,@INVENTORY_IDX		[int]			--인벤토리 고유번호
	,@INVENTORY_NUMBER	[smallint]		--인벤토리 번호
	,@RETVALUE			[int]OUTPUT)	--반환값

AS

SET NOCOUNT ON

DECLARE @ERRORCODE    [int]
       ,@ROWCOUNT     [int]

UPDATE [dbo].[TB_INVENTORY]
   SET [CHARACTER_IDX]=@CHARACTER_IDX
      ,[NUMBER]=@INVENTORY_NUMBER
 WHERE [IDX]=@INVENTORY_IDX

SELECT @ERRORCODE = @@ERROR, @ROWCOUNT = @@ROWCOUNT

IF @ERRORCODE <> 0 OR @ROWCOUNT <> 1
	BEGIN
		SET @RETVALUE = 1	--실패
	END
ELSE
	BEGIN
		SET @RETVALUE = 0	--성공
	END

SELECT [IDX]
	  ,(SELECT [IDX] FROM [dbo].[TB_ITEM_DEFINE] WHERE [INDEX]=[ITEM_DEFINE_INDEX]) AS ''ITEM_DEFINE_IDX''
	  ,[ITEM_DEFINE_INDEX]
      ,[NUMBER]
      ,[COUNT]
	  ,[ENHANCED]
	  ,[CARD_SLOT1]
	  ,[CARD_SLOT2]
	  ,[CARD_SLOT3]
	  ,[CARD_SLOT4]
	  ,[CARD_SLOT5]
      ,[SEAL]
      ,[APPLY]
  FROM TB_INVENTORY
 WHERE [IDX]=@INVENTORY_IDX
' 
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[GP_INVENTORY_SWAP]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'

/**********************************************************************
 *<
	FILE: GP_INVENTORY_SWAP.SQL

	DESCRIPTION:

	CREATED BY:	곽철중

	HISTORY:	2008-03-17 테이블 필드 삭제(TYPE)및 수정(SEAL).

 *>	Copyright (c) 2007, All Rights Reserved.
 **********************************************************************/

CREATE PROCEDURE [dbo].[GP_INVENTORY_SWAP]
	(@IDX1		int			--고유번호1
	,@NUMBER1	smallint	--위치번호1
	,@IDX2		int			--고유번호2
	,@NUMBER2	smallint	--위치번호2
	,@RETVALUE	int output)	--반환값

AS

DECLARE @ERRORCODE	[int]
DECLARE @ROWCOUNT	[int]

SET NOCOUNT ON

BEGIN TRAN

UPDATE TB_INVENTORY
   SET [NUMBER]=@NUMBER2
 WHERE [IDX]=@IDX1

IF @@ERROR <> 0 OR @@ROWCOUNT <> 1
	BEGIN
		GOTO ROLLBACK_TRAN
	END

UPDATE TB_INVENTORY
   SET [NUMBER]=@NUMBER1
 WHERE [IDX]=@IDX2

IF @@ERROR <> 0 OR @@ROWCOUNT <> 1
	BEGIN
		GOTO ROLLBACK_TRAN
	END

COMMIT TRAN

SELECT [IDX]
--SKIP,(SELECT [IDX] FROM [dbo].[TB_ITEM_DEFINE] WHERE [INDEX]=[ITEM_DEFINE_INDEX]) AS ''ITEM_DEFINE_IDX''
	  ,[ITEM_DEFINE_INDEX]
      ,[NUMBER]
      ,[COUNT]
	  ,[ENHANCED]
--SKIP,[CARD_SLOT1]
--SKIP,[CARD_SLOT2]
--SKIP,[CARD_SLOT3]
--SKIP,[CARD_SLOT4]
--SKIP,[CARD_SLOT5]
      ,[SEAL]
      ,[APPLY]
  FROM TB_INVENTORY
 WHERE [IDX]=@IDX2

SELECT [IDX]
--SKIP,(SELECT [IDX] FROM [dbo].[TB_ITEM_DEFINE] WHERE [INDEX]=[ITEM_DEFINE_INDEX]) AS ''ITEM_DEFINE_IDX''
	  ,[ITEM_DEFINE_INDEX]
      ,[NUMBER]
      ,[COUNT]
	  ,[ENHANCED]
--SKIP,[CARD_SLOT1]
--SKIP,[CARD_SLOT2]
--SKIP,[CARD_SLOT3]
--SKIP,[CARD_SLOT4]
--SKIP,[CARD_SLOT5]
      ,[SEAL]
      ,[APPLY]
  FROM TB_INVENTORY
 WHERE [IDX]=@IDX1
RETURN

ROLLBACK_TRAN:
ROLLBACK TRAN
SET @RETVALUE = 1
' 
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[GP_STALL_SELL_GET]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'

/**********************************************************************
 *<
	FILE: GP_STALL_SELL_GET.SQL

	DESCRIPTION:

	CREATED BY:

	HISTORY:

 *>	Copyright (c) 2008, All Rights Reserved.
 **********************************************************************/

CREATE PROCEDURE [dbo].[GP_STALL_SELL_GET]
	(@F_INVENTORY_IDX		[int]
	,@T_CHARACTER_IDX		[int]
	,@T_INVENTORY_NUMBER	[smallint]
	,@T_INVENTORY_COUNT		[smallint]
	,@RETVALUE				[int]OUTPUT)

AS

SET NOCOUNT ON

INSERT INTO [dbo].[TB_INVENTORY]
      ([CHARACTER_IDX]
      ,[ITEM_DEFINE_INDEX]
      ,[NUMBER]
      ,[COUNT]
      ,[ENHANCED]
      ,[CARD_SLOT1]
      ,[CARD_SLOT2]
      ,[CARD_SLOT3]
      ,[CARD_SLOT4]
      ,[CARD_SLOT5]
      ,[SEAL]
      ,[APPLY])
SELECT @T_CHARACTER_IDX
      ,[ITEM_DEFINE_INDEX]
      ,@T_INVENTORY_NUMBER
      ,@T_INVENTORY_COUNT
      ,[ENHANCED]
      ,[CARD_SLOT1]
      ,[CARD_SLOT2]
      ,[CARD_SLOT3]
      ,[CARD_SLOT4]
      ,[CARD_SLOT5]
      ,[SEAL]
      ,[APPLY]
  FROM [dbo].[TB_INVENTORY]
 WHERE [IDX]=@F_INVENTORY_IDX

IF @@ERROR <> 0 OR @@ROWCOUNT <> 1
	BEGIN
		SET @RETVALUE=-1
		RETURN
	END

UPDATE [dbo].[TB_INVENTORY]
   SET [COUNT]=[COUNT]-@T_INVENTORY_COUNT
 WHERE [IDX]=@F_INVENTORY_IDX

IF @@ERROR <> 0 OR @@ROWCOUNT <> 1
	BEGIN
		SET @RETVALUE=-2
		RETURN
	END

UPDATE [dbo].[TB_INVENTORY]
   SET [APPLY]=1
 WHERE [IDX]=@F_INVENTORY_IDX
   AND [COUNT]<1

IF @@ERROR <> 0
	BEGIN
		SET @RETVALUE=-3
		RETURN
	END

SELECT [IDX]
	  ,(SELECT [IDX] FROM [dbo].[TB_ITEM_DEFINE] WHERE [INDEX]=[ITEM_DEFINE_INDEX]) AS ''ITEM_DEFINE_IDX''
      ,[ITEM_DEFINE_INDEX]
      ,[NUMBER]
      ,[COUNT]
	  ,[ENHANCED]
	  ,[CARD_SLOT1]
	  ,[CARD_SLOT2]
	  ,[CARD_SLOT3]
	  ,[CARD_SLOT4]
	  ,[CARD_SLOT5]
      ,[SEAL]
	  ,[APPLY]
  FROM [dbo].[TB_INVENTORY]
 WHERE [IDX]=@F_INVENTORY_IDX

SELECT [IDX]
	  ,(SELECT [IDX] FROM [dbo].[TB_ITEM_DEFINE] WHERE [INDEX]=[ITEM_DEFINE_INDEX]) AS ''ITEM_DEFINE_IDX''
      ,[ITEM_DEFINE_INDEX]
      ,[NUMBER]
      ,[COUNT]
	  ,[ENHANCED]
	  ,[CARD_SLOT1]
	  ,[CARD_SLOT2]
	  ,[CARD_SLOT3]
	  ,[CARD_SLOT4]
	  ,[CARD_SLOT5]
      ,[SEAL]
	  ,[APPLY]
  FROM [dbo].[TB_INVENTORY]
 WHERE [IDX]=(SELECT MAX(IDX) FROM [dbo].[TB_INVENTORY] WHERE [CHARACTER_IDX]=@T_CHARACTER_IDX)

' 
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[GP_ITEM_COLLECT]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'
/**********************************************************************
 *<
	FILE: GP_ITEM_COLLECT.SQL

	DESCRIPTION: ITEM COLLECT(컬렉션북 시스템)

	CREATED BY:	곽철중

	HISTORY:

 *>	Copyright (c) 2008, All Rights Reserved.
 **********************************************************************/

CREATE PROCEDURE [dbo].[GP_ITEM_COLLECT]
	(@UPDATE_INVENTORY_IDX		[int]			--인벤토리 고유번호
	,@UPDATE_INVENTORY_NUMBER	[smallint]		--인벤토리 번호
	,@REMOVE_INVENTORY_IDX		[int]			--인벤토리 고유번호
	,@RETVALUE					[int]OUTPUT)	--반환값

AS

SET NOCOUNT ON

BEGIN TRAN

UPDATE [dbo].[TB_INVENTORY]
   SET [NUMBER]=@UPDATE_INVENTORY_NUMBER
 WHERE [IDX]=@UPDATE_INVENTORY_IDX

IF @@ERROR <> 0 OR @@ROWCOUNT <> 1
	BEGIN
		SET @RETVALUE = -1			--등록실패 - 알수없는 오류.
		ROLLBACK TRAN
		RETURN
	END
ELSE
	BEGIN
		SELECT [IDX]
			  ,(SELECT [IDX] FROM [dbo].[TB_ITEM_DEFINE] WHERE [INDEX]=[ITEM_DEFINE_INDEX]) AS ''ITEM_DEFINE_IDX''
			  ,[ITEM_DEFINE_INDEX]
			  ,[NUMBER]
			  ,[COUNT]
			  ,[ENHANCED]
			  ,[CARD_SLOT1]
			  ,[CARD_SLOT2]
			  ,[CARD_SLOT3]
			  ,[CARD_SLOT4]
			  ,[CARD_SLOT5]
			  ,[SEAL]
			  ,[APPLY]
		  FROM TB_INVENTORY
		 WHERE [IDX]=@UPDATE_INVENTORY_IDX
	END

IF @REMOVE_INVENTORY_IDX > 0
	BEGIN
		UPDATE [dbo].[TB_INVENTORY]
		   SET [APPLY]=1
		 WHERE [IDX]=@REMOVE_INVENTORY_IDX

		IF @@ERROR <> 0 OR @@ROWCOUNT <> 1
			BEGIN
				SET @RETVALUE = -1			--등록실패 - 알수없는 오류.
				ROLLBACK TRAN
				RETURN
			END
		ELSE
			BEGIN
				SELECT [IDX]
					  ,(SELECT [IDX] FROM [dbo].[TB_ITEM_DEFINE] WHERE [INDEX]=[ITEM_DEFINE_INDEX]) AS ''ITEM_DEFINE_IDX''
					  ,[ITEM_DEFINE_INDEX]
					  ,[NUMBER]
					  ,[COUNT]
					  ,[ENHANCED]
					  ,[CARD_SLOT1]
					  ,[CARD_SLOT2]
					  ,[CARD_SLOT3]
					  ,[CARD_SLOT4]
					  ,[CARD_SLOT5]
					  ,[SEAL]
					  ,[APPLY]
				  FROM TB_INVENTORY
				 WHERE [IDX]=@REMOVE_INVENTORY_IDX
			END
	END

SET @RETVALUE = 0	--등록성공
COMMIT TRAN
' 
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[GP_INVENTORY_UPDATE]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'



/**********************************************************************
 *<
	FILE: GP_INVENTORY_UPDATE.SQL

	DESCRIPTION:

	CREATED BY:

	HISTORY:

 *>	Copyright (c) 2009, All Rights Reserved.
 **********************************************************************/

CREATE PROCEDURE [dbo].[GP_INVENTORY_UPDATE]
	(@CHARACTER_IDX		[int]		--캐 릭 터 고유번호
	,@INVENTORY_IDX		[int]		--인벤토리 고유번호
	,@ITEM_DEFINE_INDEX	[int]		--아 이 템 인 덱 스
	,@COUNT				[smallint]  --적용수량 (+-)
	,@NUMBER			[smallint]) --인벤토리 번호(슬롯)

AS

SET NOCOUNT ON

IF @INVENTORY_IDX <> 0
	BEGIN
		IF @COUNT < 0
			BEGIN
				UPDATE [dbo].[TB_INVENTORY]
				   SET [COUNT]=[COUNT]+@COUNT
				 WHERE [IDX]=@INVENTORY_IDX

				UPDATE [dbo].[TB_INVENTORY]
				   SET [APPLY]=1
				 WHERE [IDX]=@INVENTORY_IDX AND [COUNT]<=0
			END
		ELSE
			BEGIN
				UPDATE [dbo].[TB_INVENTORY]
				   SET [COUNT]=[COUNT]+@COUNT
				 WHERE [IDX]=@INVENTORY_IDX
			END
	END
ELSE
	BEGIN
		INSERT [dbo].[TB_INVENTORY]
			   ([CHARACTER_IDX]
			   ,[ITEM_DEFINE_INDEX]
			   ,[NUMBER]
			   ,[COUNT])
		VALUES (@CHARACTER_IDX
			   ,@ITEM_DEFINE_INDEX
			   ,@NUMBER
			   ,@COUNT)

		IF @@ERROR <> 0 OR @@ROWCOUNT <> 1
			BEGIN
				RETURN 99
			END

		SELECT @INVENTORY_IDX=MAX(IDX)
          FROM [dbo].[TB_INVENTORY]
         WHERE [CHARACTER_IDX]=@CHARACTER_IDX
	END

SELECT [IDX]
--SKIP,(SELECT [IDX] FROM [dbo].[TB_ITEM_DEFINE] WHERE [INDEX]=[ITEM_DEFINE_INDEX]) AS ''ITEM_DEFINE_IDX''
	  ,[ITEM_DEFINE_INDEX]
      ,[NUMBER]
      ,[COUNT]
	  ,[ENHANCED]
--SKIP,[CARD_SLOT1]
--SKIP,[CARD_SLOT2]
--SKIP,[CARD_SLOT3]
--SKIP,[CARD_SLOT4]
--SKIP,[CARD_SLOT5]
      ,[SEAL]
	  ,[APPLY]
  FROM [dbo].[TB_INVENTORY]
 WHERE [IDX]=@INVENTORY_IDX
' 
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[GP_ITEM_MIX]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'


/**********************************************************************
 *<
	FILE: GP_ITEM_MIX.SQL

	DESCRIPTION:

	CREATED BY:	곽철중

	HISTORY:	2008-03-17 테이블 필드 삭제(TYPE)및 수정(SEAL).

 *>	Copyright (c) 2007, All Rights Reserved.
 **********************************************************************/

CREATE PROCEDURE [dbo].[GP_ITEM_MIX]
	(@CHARACTER_IDX		[int]		--캐 릭 터 고유번호
	,@INVENTORY_IDX		[int]		--인벤토리 고유번호
	,@ITEM_DEFINE_INDEX	[int]		--아 이 템 인 덱 스
	,@COUNT				[smallint]  --적용수량 (+-)
	,@NUMBER			[smallint]) --인벤토리 번호(슬롯)

AS

SET NOCOUNT ON

DECLARE @ERRORCODE	  [int]
DECLARE @ROWCOUNT	  [int]

IF @INVENTORY_IDX > 0
	BEGIN
		IF @COUNT < 0
			BEGIN
				UPDATE [dbo].[TB_INVENTORY]
				   SET [COUNT]=[COUNT]+@COUNT
				 WHERE [IDX]=@INVENTORY_IDX
				   AND [COUNT]>=@COUNT

				UPDATE [dbo].[TB_INVENTORY]
				   SET [APPLY]=1
				 WHERE [IDX]=@INVENTORY_IDX
				   AND [COUNT]<=0
			END
		ELSE
			BEGIN
				UPDATE [dbo].[TB_INVENTORY]
				   SET [COUNT]=[COUNT]+@COUNT
				 WHERE [IDX]=@INVENTORY_IDX
			END
	END
ELSE
	BEGIN
		INSERT [dbo].[TB_INVENTORY]
			   ([CHARACTER_IDX]
			   ,[ITEM_DEFINE_INDEX]
			   ,[NUMBER]
			   ,[COUNT])
		VALUES (@CHARACTER_IDX
			   ,@ITEM_DEFINE_INDEX
			   ,@NUMBER
			   ,@COUNT)

		SELECT @ERRORCODE = @@ERROR, @ROWCOUNT = @@ROWCOUNT

		IF @ERRORCODE <> 0 OR @ROWCOUNT <> 1
			BEGIN
				RETURN 99
			END

		SELECT @INVENTORY_IDX=MAX(IDX)
          FROM [dbo].[TB_INVENTORY]
         WHERE [CHARACTER_IDX]=@CHARACTER_IDX
	END

SELECT [IDX]
--SKIP,(SELECT [IDX] FROM [dbo].[TB_ITEM_DEFINE] WHERE [INDEX]=[ITEM_DEFINE_INDEX]) AS ''ITEM_DEFINE_IDX''
	  ,[ITEM_DEFINE_INDEX]
      ,[NUMBER]
      ,[COUNT]
	  ,[ENHANCED]
--SKIP,[CARD_SLOT1]
--SKIP,[CARD_SLOT2]
--SKIP,[CARD_SLOT3]
--SKIP,[CARD_SLOT4]
--SKIP,[CARD_SLOT5]
      ,[SEAL]
      ,[APPLY]
  FROM [dbo].[TB_INVENTORY]
 WHERE [IDX]=@INVENTORY_IDX

' 
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[GP_INVENTORY_CHANGE]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'

/**********************************************************************
 *<
	FILE: GP_INVENTORY_CHANGE.SQL

	DESCRIPTION: 인벤토리 체인지(아이템)

	CREATED BY:	곽철중

	HISTORY:	2008-10-08 수정

 *>	Copyright (c) 2008, All Rights Reserved.
 **********************************************************************/

CREATE PROCEDURE [dbo].[GP_INVENTORY_CHANGE]
	(@CHARACTER_IDX		int				--캐릭터   고유번호
	,@INVENTORY_IDX		int				--인벤토리 고유번호
	,@ITEM_DEFINE_INDEX	int				--아이템 정의 인덱스
	,@INVENTORY_NUMBER	smallint		--인벤토리 번호(슬롯)
	,@INVENTORY_COUNT	smallint)		--인벤토리 수량
AS

SET NOCOUNT ON

BEGIN TRAN

IF @INVENTORY_IDX > 0
	BEGIN
		UPDATE [dbo].[TB_INVENTORY]
		   SET [COUNT]=[COUNT]+@INVENTORY_COUNT
		 WHERE [IDX]=@INVENTORY_IDX

		IF @@ERROR <> 0 OR @@ROWCOUNT <> 1
			GOTO ROLLBACK_TRAN

		UPDATE [dbo].[TB_INVENTORY]
		   SET [APPLY]=1
		 WHERE [IDX]=@INVENTORY_IDX
		   AND [COUNT]<=0

		IF @@ERROR <> 0
			GOTO ROLLBACK_TRAN
	END
ELSE
	BEGIN
		INSERT [dbo].[TB_INVENTORY]
			   ([CHARACTER_IDX]
			   ,[ITEM_DEFINE_INDEX]
			   ,[NUMBER]
			   ,[COUNT])
		VALUES (@CHARACTER_IDX
			   ,@ITEM_DEFINE_INDEX
			   ,@INVENTORY_NUMBER
			   ,@INVENTORY_COUNT)

		IF @@ERROR <> 0 OR @@ROWCOUNT <> 1
			GOTO ROLLBACK_TRAN

		SELECT @INVENTORY_IDX=MAX(IDX)
          FROM [dbo].[TB_INVENTORY]
         WHERE [CHARACTER_IDX]=@CHARACTER_IDX
	END

COMMIT TRAN

SELECT [IDX]
--SKIP,(SELECT [IDX] FROM [dbo].[TB_ITEM_DEFINE] WHERE [INDEX]=[ITEM_DEFINE_INDEX]) AS ''ITEM_DEFINE_IDX''
	  ,[ITEM_DEFINE_INDEX]
      ,[NUMBER]
      ,[COUNT]
	  ,[ENHANCED]
--SKIP,[CARD_SLOT1]
--SKIP,[CARD_SLOT2]
--SKIP,[CARD_SLOT3]
--SKIP,[CARD_SLOT4]
--SKIP,[CARD_SLOT5]
      ,[SEAL]
	  ,[APPLY]
  FROM [dbo].[TB_INVENTORY]
 WHERE [IDX]=@INVENTORY_IDX

RETURN 0

ROLLBACK_TRAN:
ROLLBACK TRAN
RETURN 99
' 
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[GP_INVENTORY_MOVE]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'


/**********************************************************************
 *<
	FILE: GP_INVENTORY_MOVE.SQL

	DESCRIPTION:

	CREATED BY:	곽철중

	HISTORY:	2008-03-17 테이블 필드 삭제(TYPE)및 수정(SEAL).

 *>	Copyright (c) 2007, All Rights Reserved.
 **********************************************************************/

CREATE PROCEDURE [dbo].[GP_INVENTORY_MOVE]
	(@CHARACTER_IDX	[int]		--캐릭터 고유번호
	,@IDX			[int]		--고유번호
	,@NUMBER		[smallint])	--번호

AS

SET NOCOUNT ON

UPDATE [dbo].[TB_INVENTORY]
   SET [NUMBER]=@NUMBER
 WHERE [IDX]=@IDX

SELECT [IDX]
--SKIP,(SELECT [IDX] FROM [dbo].[TB_ITEM_DEFINE] WHERE [INDEX]=[ITEM_DEFINE_INDEX]) AS ''ITEM_DEFINE_IDX''
	  ,[ITEM_DEFINE_INDEX]
      ,[NUMBER]
      ,[COUNT]
	  ,[ENHANCED]
--SKIP,[CARD_SLOT1]
--SKIP,[CARD_SLOT2]
--SKIP,[CARD_SLOT3]
--SKIP,[CARD_SLOT4]
--SKIP,[CARD_SLOT5]
      ,[SEAL]
      ,[APPLY]
  FROM [dbo].[TB_INVENTORY]
 WHERE [IDX]=@IDX


' 
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[GP_INVENTORY_REMOVE]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'

/**********************************************************************
 *<
	FILE: GP_INVENTORY_REMOVE.SQL

	DESCRIPTION:

	CREATED BY:	곽철중

	HISTORY:	2008-03-17 테이블 필드 삭제(TYPE)및 수정(SEAL).

 *>	Copyright (c) 2007, All Rights Reserved.
 **********************************************************************/

CREATE PROCEDURE [dbo].[GP_INVENTORY_REMOVE]
	(@IDX		[int]			--고유번호
	,@RETVALUE	[int]OUTPUT)	--반환값

AS

DECLARE @ERRORCODE	[int]
DECLARE @ROWCOUNT	[int]

SET NOCOUNT ON

UPDATE [dbo].[TB_INVENTORY]
   SET [APPLY]=1				--사용안함(1)
 WHERE [IDX]=@IDX

SELECT @ERRORCODE = @@ERROR, @ROWCOUNT = @@ROWCOUNT

IF @ERRORCODE <> 0 OR @ROWCOUNT <> 1
	BEGIN
		SET @RETVALUE = 1		--삭제실패
	END
ELSE
	BEGIN
		SET @RETVALUE = 0		--삭제성공

		SELECT [IDX]
--SKIP		  ,(SELECT [IDX] FROM [dbo].[TB_ITEM_DEFINE] WHERE [INDEX]=[ITEM_DEFINE_INDEX]) AS ''ITEM_DEFINE_IDX''
              ,[ITEM_DEFINE_INDEX]
              ,[NUMBER]
              ,[COUNT]
              ,[ENHANCED]
--SKIP		  ,[CARD_SLOT1]
--SKIP		  ,[CARD_SLOT2]
--SKIP		  ,[CARD_SLOT3]
--SKIP		  ,[CARD_SLOT4]
--SKIP		  ,[CARD_SLOT5]
              ,[SEAL]
              ,[APPLY]
		  FROM [dbo].[TB_INVENTORY]
		 WHERE [IDX]=@IDX
	END

' 
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[GP_INVENTORY_DELETE]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'

/**********************************************************************
 *<
	FILE: GP_INVENTORY_DELETE.SQL

	DESCRIPTION:

	CREATED BY:	곽철중

	HISTORY:	2008-03-17 테이블 필드 삭제(TYPE)및 수정(SEAL).

 *>	Copyright (c) 2007, All Rights Reserved.
 **********************************************************************/

CREATE PROCEDURE [dbo].[GP_INVENTORY_DELETE]
	(@IDX			[int]			--고유번호
	,@RETVALUE		[int]OUTPUT)	--반환값

AS

DECLARE @ERRORCODE	[int]
DECLARE @ROWCOUNT	[int]

SET NOCOUNT ON

UPDATE [dbo].[TB_INVENTORY]
   SET [APPLY]=1				--사용안함(1)
 WHERE [IDX]=@IDX

SELECT @ERRORCODE = @@ERROR, @ROWCOUNT = @@ROWCOUNT

IF @ERRORCODE <> 0 OR @ROWCOUNT <> 1
	BEGIN
		SET @RETVALUE = 1		--삭제실패
	END
ELSE
	BEGIN
		SELECT [IDX]
--생략		  ,(SELECT [IDX] FROM [dbo].[TB_ITEM_DEFINE] WHERE [INDEX]=[ITEM_DEFINE_INDEX]) AS ''ITEM_DEFINE_IDX''
			  ,[ITEM_DEFINE_INDEX]
			  ,[NUMBER]
			  ,[COUNT]
			  ,[ENHANCED]
--생략		  ,[CARD_SLOT1]
--생략		  ,[CARD_SLOT2]
--생략		  ,[CARD_SLOT3]
--생략		  ,[CARD_SLOT4]
--생략		  ,[CARD_SLOT5]
			  ,[SEAL]
			  ,[APPLY]
		  FROM [dbo].[TB_INVENTORY]
		 WHERE [IDX]=@IDX

		SET @RETVALUE = 0		--삭제성공
	END

RETURN @ERRORCODE
' 
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[GP_INVENTORY_USE]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'



/**********************************************************************
 *<
	FILE: GP_INVENTORY_USE.SQL

	DESCRIPTION:

	CREATED BY:	곽철중

	HISTORY:

 *>	Copyright (c) 2007, All Rights Reserved.
 **********************************************************************/

CREATE PROCEDURE [dbo].[GP_INVENTORY_USE]
	(@IDX [int])			--고유번호
AS

SET NOCOUNT ON

UPDATE [dbo].[TB_INVENTORY]
   SET [COUNT]=[COUNT]-1
 WHERE [IDX]=@IDX

UPDATE [dbo].[TB_INVENTORY]
   SET [APPLY]=1
 WHERE [IDX]=@IDX
   AND [COUNT]<=0

SELECT [IDX]
--SKIP,(SELECT [IDX] FROM [dbo].[TB_ITEM_DEFINE] WHERE [INDEX]=[ITEM_DEFINE_INDEX]) AS ''ITEM_DEFINE_IDX''
	  ,[ITEM_DEFINE_INDEX]
      ,[NUMBER]
      ,[COUNT]
	  ,[ENHANCED]
--SKIP,[CARD_SLOT1]
--SKIP,[CARD_SLOT2]
--SKIP,[CARD_SLOT3]
--SKIP,[CARD_SLOT4]
--SKIP,[CARD_SLOT5]
      ,[SEAL]
	  ,[APPLY]
  FROM [dbo].[TB_INVENTORY]
 WHERE [IDX]=@IDX



' 
END
GO
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[GP_INVENTORY_PUT_CARD]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'
/**********************************************************************
 *<
	FILE: GP_INVENTORY_PUT_CARD.SQL

	DESCRIPTION: 인벤토리 카드장착

	CREATED BY:	곽철중

	HISTORY:	2008-04-04 생성

 *>	Copyright (c) 2008, All Rights Reserved.
 **********************************************************************/

CREATE PROCEDURE [dbo].[GP_INVENTORY_PUT_CARD]
	(@IDX1		[int]			--고유번호
	,@CARD_SLOT	[int]			--카드슬롯 번호(1~5)
	,@IDX2		[int]			--고유번호
	,@INDEX		[int]			--기획:분류번호
	,@RETVALUE	[int]OUTPUT)	--반환값
AS

SET NOCOUNT ON

DECLARE @ERRORCODE    [int]
       ,@ROWCOUNT     [int]

BEGIN TRAN

IF @CARD_SLOT = 1
	BEGIN
		UPDATE [dbo].[TB_INVENTORY]
		   SET [CARD_SLOT1]=@INDEX
		 WHERE [IDX]=@IDX1
	END
ELSE IF @CARD_SLOT = 2
	BEGIN
		UPDATE [dbo].[TB_INVENTORY]
		   SET [CARD_SLOT2]=@INDEX
		 WHERE [IDX]=@IDX1
	END
ELSE IF @CARD_SLOT = 3
	BEGIN
		UPDATE [dbo].[TB_INVENTORY]
		   SET [CARD_SLOT3]=@INDEX
		 WHERE [IDX]=@IDX1
	END
ELSE IF @CARD_SLOT = 4
	BEGIN
		UPDATE [dbo].[TB_INVENTORY]
		   SET [CARD_SLOT4]=@INDEX
		 WHERE [IDX]=@IDX1
	END
ELSE IF @CARD_SLOT = 5
	BEGIN
		UPDATE [dbo].[TB_INVENTORY]
		   SET [CARD_SLOT5]=@INDEX
		 WHERE [IDX]=@IDX1
	END
ELSE
	BEGIN
		SET @RETVALUE = 1	--실패
		GOTO ROLLBACK_TRAN
	END

SELECT @ERRORCODE = @@ERROR, @ROWCOUNT = @@ROWCOUNT

IF @ERRORCODE <> 0 OR @ROWCOUNT <> 1
	BEGIN
		SET @RETVALUE = 1	--실패
		GOTO ROLLBACK_TRAN
	END

UPDATE [dbo].[TB_INVENTORY]
   SET [APPLY]=1
 WHERE [IDX]=@IDX2

SELECT @ERRORCODE = @@ERROR, @ROWCOUNT = @@ROWCOUNT

IF @ERRORCODE <> 0 OR @ROWCOUNT <> 1
	BEGIN
		SET @RETVALUE = 1	--실패
		GOTO ROLLBACK_TRAN
	END

SET @RETVALUE = 0	--성공
COMMIT TRAN

SELECT [IDX]
	  ,(SELECT [IDX] FROM [dbo].[TB_ITEM_DEFINE] WHERE [INDEX]=[ITEM_DEFINE_INDEX]) AS ''ITEM_DEFINE_IDX''
	  ,[ITEM_DEFINE_INDEX]
      ,[NUMBER]
      ,[COUNT]
	  ,[ENHANCED]
	  ,[CARD_SLOT1]
	  ,[CARD_SLOT2]
	  ,[CARD_SLOT3]
	  ,[CARD_SLOT4]
	  ,[CARD_SLOT5]
      ,[SEAL]
      ,[APPLY]
  FROM TB_INVENTORY
 WHERE [IDX]=@IDX1

SELECT [IDX]
	  ,(SELECT [IDX] FROM [dbo].[TB_ITEM_DEFINE] WHERE [INDEX]=[ITEM_DEFINE_INDEX]) AS ''ITEM_DEFINE_IDX''
	  ,[ITEM_DEFINE_INDEX]
      ,[NUMBER]
      ,[COUNT]
	  ,[ENHANCED]
	  ,[CARD_SLOT1]
	  ,[CARD_SLOT2]
	  ,[CARD_SLOT3]
	  ,[CARD_SLOT4]
	  ,[CARD_SLOT5]
      ,[SEAL]
      ,[APPLY]
  FROM TB_INVENTORY
 WHERE [IDX]=@IDX2

RETURN

ROLLBACK_TRAN:
ROLLBACK TRAN
' 
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[GP_INVENTORY_DIVIDE]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'


/**********************************************************************
 *<
	FILE: GP_INVENTORY_DIVIDE.SQL

	DESCRIPTION:

	CREATED BY:	곽철중

	HISTORY:	2008-03-17 테이블 필드 삭제(TYPE)및 수정(SEAL).

 *>	Copyright (c) 2007, All Rights Reserved.
 **********************************************************************/

CREATE PROCEDURE [dbo].[GP_INVENTORY_DIVIDE]
	(@CHARACTER_IDX		[int]		--캐 릭 터 고유번호
	,@INVENTORY_IDX		[int]		--인벤토리 고유번호
	,@ITEM_DEFINE_INDEX	[int]		--아 이 템 인 덱 스
	,@COUNT				[smallint]  --적용수량 (+-)
	,@NUMBER			[smallint]) --인벤토리 번호(슬롯)

AS

SET NOCOUNT ON

DECLARE @ERRORCODE	  [int]
DECLARE @ROWCOUNT	  [int]

IF @INVENTORY_IDX > 0
	BEGIN
		UPDATE [dbo].[TB_INVENTORY]
		   SET [COUNT]=@COUNT
		 WHERE [IDX]=@INVENTORY_IDX
	END
ELSE
	BEGIN
		INSERT [dbo].[TB_INVENTORY]
			   ([CHARACTER_IDX]
			   ,[ITEM_DEFINE_INDEX]
			   ,[NUMBER]
			   ,[COUNT])
		VALUES (@CHARACTER_IDX
			   ,@ITEM_DEFINE_INDEX
			   ,@NUMBER
			   ,@COUNT)

		SELECT @ERRORCODE = @@ERROR, @ROWCOUNT = @@ROWCOUNT

		IF @ERRORCODE <> 0 OR @ROWCOUNT <> 1
			BEGIN
				RETURN 99
			END

		SELECT @INVENTORY_IDX=MAX(IDX)
          FROM [dbo].[TB_INVENTORY]
         WHERE [CHARACTER_IDX]=@CHARACTER_IDX
	END

SELECT [IDX]
--SKIP,(SELECT [IDX] FROM [dbo].[TB_ITEM_DEFINE] WHERE [INDEX]=[ITEM_DEFINE_INDEX]) AS ''ITEM_DEFINE_IDX''
	  ,[ITEM_DEFINE_INDEX]
      ,[NUMBER]
      ,[COUNT]
	  ,[ENHANCED]
--SKIP,[CARD_SLOT1]
--SKIP,[CARD_SLOT2]
--SKIP,[CARD_SLOT3]
--SKIP,[CARD_SLOT4]
--SKIP,[CARD_SLOT5]
      ,[SEAL]
      ,[APPLY]
  FROM [dbo].[TB_INVENTORY]
 WHERE [IDX]=@INVENTORY_IDX

' 
END
GO
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[GP_STALL_SELL_INSERT]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'
/**********************************************************************
 *<
	FILE: GP_STALL_SELL_INSERT.SQL

	DESCRIPTION:

	CREATED BY:

	HISTORY:

 *>	Copyright (c) 2007, All Rights Reserved.
 **********************************************************************/

CREATE PROCEDURE [dbo].[GP_STALL_SELL_INSERT]
	(@CHANNEL_NUM		[int]			--채널번호
	,@INVENTORY_IDX		[int]			--인벤토리 고유번호
	,@CHARACTER_IDX		[int]			--캐 릭 터 고유번호
	,@ITEM_DEFINE_INDEX	[int]			--검색조건-아이템 정의 인덱스
	,@ENHANCED          [int]           --검색조건-강화단계
	,@PRICE				[int]			--정렬조건-가격
	,@RETVALUE			[int]OUTPUT)	--반환값

AS

SET NOCOUNT ON

DECLARE @ERRORCODE			[int]
DECLARE @ROWCOUNT			[int]

--중복등록 검사 / 중복일경우 가격만 업데이트 한다.
IF EXISTS (SELECT * FROM [dbo].[TB_STALL_SELL] WHERE [CHARACTER_IDX]=@CHARACTER_IDX AND [INVENTORY_IDX]=@INVENTORY_IDX AND [APPLY]=0)
	BEGIN
		UPDATE [dbo].[TB_STALL_SELL]
           SET [PRICE]=@PRICE
         WHERE [CHARACTER_IDX]=@CHARACTER_IDX
           AND [INVENTORY_IDX]=@INVENTORY_IDX
           AND [APPLY]=0

		SELECT @ERRORCODE = @@ERROR, @ROWCOUNT = @@ROWCOUNT
		IF @ERRORCODE <> 0 OR @ROWCOUNT <> 1
			BEGIN
				SET @RETVALUE = -1		--실패 - 알수없는 오류
			END
		ELSE
			BEGIN
				SET @RETVALUE = 0		--성공
			END
	END
ELSE
	BEGIN
		--등록갯수 검사 / 최대 8개를 초과 할 수 없다.
		IF (SELECT COUNT(*) FROM [dbo].[TB_STALL_SELL] WHERE [CHARACTER_IDX]=@CHARACTER_IDX AND [APPLY]=0) > 8
			BEGIN
				SET @RETVALUE = 1		--실패 - 등록갯수 초과
				RETURN
			END

		--등록
		INSERT [dbo].[TB_STALL_SELL]
			   ([CHANNEL_NUM]
			   ,[INVENTORY_IDX]
			   ,[CHARACTER_IDX]
			   ,[ITEM_DEFINE_INDEX]
			   ,[ENHANCED]
			   ,[PRICE])
		VALUES (@CHANNEL_NUM
			   ,@INVENTORY_IDX
			   ,@CHARACTER_IDX
			   ,@ITEM_DEFINE_INDEX
			   ,@ENHANCED
			   ,@PRICE)

		SELECT @ERRORCODE = @@ERROR, @ROWCOUNT = @@ROWCOUNT
		IF @ERRORCODE <> 0 OR @ROWCOUNT <> 1
			BEGIN
				SET @RETVALUE = -1		--실패 - 알수없는 오류
			END
		ELSE
			BEGIN
				SET @RETVALUE = 0		--성공
			END
	END
' 
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[GP_STALL_SELL_SELECT]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'

/**********************************************************************
 *<
	FILE: GP_STALL_SELL_SELECT.SQL

	DESCRIPTION:

	CREATED BY:

	HISTORY:

 *>	Copyright (c) 2007, All Rights Reserved.
 **********************************************************************/

CREATE PROCEDURE [dbo].[GP_STALL_SELL_SELECT]
	(@CHANNEL_NUM		[int]		--채널번호
	,@ITEM_DEFINE_INDEX	[int]		--아이템 정의 인덱스
	,@ENHANCED			[tinyint])	--강화단계

AS

SET NOCOUNT ON

SELECT TOP (10)
	   [IDX]
	  ,[CHARACTER_IDX]
	  ,[PRICE]
  FROM [dbo].[TB_STALL_SELL]
 WHERE [CHANNEL_NUM]=@CHANNEL_NUM
   AND [ITEM_DEFINE_INDEX]=@ITEM_DEFINE_INDEX
   AND [ENHANCED]=@ENHANCED
   AND [APPLY]=0
 ORDER BY [PRICE] ASC
' 
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[GP_QUEST_REMOVE]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'
    
/**********************************************************************
 *<
	FILE: GP_QUEST_REMOVE.SQL

	DESCRIPTION:

	CREATED BY:

	HISTORY:

 *>	Copyright (c) 2007, All Rights Reserved.
 **********************************************************************/
CREATE PROCEDURE [dbo].[GP_QUEST_REMOVE]
	(@IDX [int])		--고유번호

AS

SET NOCOUNT ON

UPDATE [dbo].[TB_QUEST_PROGRESS]
   SET [APPLY]=5				--퀘스트강제삭제(5)
 WHERE [IDX]=@IDX

IF @@ERROR <> 0 OR @@ROWCOUNT <> 1
	BEGIN
		RETURN 99
	END
ELSE
	BEGIN
		RETURN 0
	END
' 
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[GP_QUEST_ENDLISTSELECT]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'

/**********************************************************************
 *<
	FILE: QUEST_ENDLISTSELECT.SQL

	DESCRIPTION:

	CREATED BY:

	HISTORY:

 *>	Copyright (c) 2007, All Rights Reserved.
 **********************************************************************/
 
 CREATE PROCEDURE [dbo].[GP_QUEST_ENDLISTSELECT]
	(@CHARACTER_IDX		[int] )				--캐릭터 인덱스
        
AS

-- 적용행 출력 금지
SET NOCOUNT ON

-- 완료된 퀘스트 리스트를 받아온다
SELECT [QUEST_IDX]
  FROM [dbo].[TB_QUEST_PROGRESS]
 WHERE [CHARACTER_IDX]=@CHARACTER_IDX
   AND [APPLY]=1
' 
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[GP_QUEST_DELETE]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'

/**********************************************************************
 *<
	FILE: GP_QUEST_DELETE.SQL

	DESCRIPTION:

	CREATED BY:

	HISTORY:

 *>	Copyright (c) 2008, All Rights Reserved.
 **********************************************************************/

CREATE PROCEDURE [dbo].[GP_QUEST_DELETE]
	(@QUEST_PROGRESS_IDX	[int]			--고유번호
	,@CHARACTER_IDX			[int]			--캐릭터인덱스
	,@RETVALUE				[int]OUTPUT)	--반환값

AS

SET NOCOUNT ON

--퀘스트포기
UPDATE [dbo].[TB_QUEST_PROGRESS]
   SET [APPLY]=3				--퀘스트포기(3)
 WHERE [IDX]=@QUEST_PROGRESS_IDX
   AND [CHARACTER_IDX]=@CHARACTER_IDX

IF @@ERROR <> 0 OR @@ROWCOUNT <> 1
	BEGIN
		SET @RETVALUE = 1						-- 삭제실패 :알수 없는 오류
		RETURN
	END
' 
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[GP_QUEST_COMPLETE]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'
/**********************************************************************
 *<
	FILE: GP_QUEST_COMPLETE.SQL

	DESCRIPTION:

	CREATED BY: 김가람

	HISTORY:	[곽철중] 2008-03-18 보상금액 & 보상아이템 추가.

 *>	Copyright (c) 2007, All Rights Reserved.
 **********************************************************************/

CREATE PROCEDURE [dbo].[GP_QUEST_COMPLETE]
	(@QUEST_PROGRESS_IDX	[int]				--고유번호
	,@CHARACTER_IDX			[int]				--캐릭터인덱스
	,@REPEATE_TYPE			[tinyint]			--반복타입( 0:한번만 도전 1:성공할떄까지 2:반복)
	,@RETVALUE				[int]OUTPUT)		--반환값

AS

DECLARE @TIMETYPE		[int]		-- 시간타입 (0:제한없음,1:실시간,2:게임시간)
DECLARE @LASTTIME		[datetime]	-- 마지막 갱신시간
DECLARE @REGISTERTIME	[datetime]	-- 등록 시간
DECLARE @RESTTIME		[int]		-- 남은시간
DECLARE @DIFFTIME		[int]

SET NOCOUNT ON

-- 시간제한이 있는 퀘스트일경우, 시간을 오버하지 않았는지 검사
SELECT @TIMETYPE=[TIME_TYPE]
	  ,@LASTTIME=[VALID_THRU]
	  ,@REGISTERTIME=[REGISTER_DATE]
      ,@RESTTIME=[REST_TIME]
  FROM [dbo].[TB_QUEST_PROGRESS]
 WHERE [IDX]=@QUEST_PROGRESS_IDX

-- 1. 적용검사
IF @@ERROR <> 0 OR @@ROWCOUNT <> 1
	BEGIN
		SET @RETVALUE = 1			-- 등록실패 :알수 없는 오류
		RETURN
	END

-- 시간제한 & 실시간 타입검사
IF @TIMETYPE <> 0
	BEGIN
		-- 실시간 타입
		IF @TIMETYPE = 1 
			BEGIN
				SET @DIFFTIME = DATEDIFF( MS, @REGISTERTIME, GETDATE())
			END
		-- 게임시간 타입	
		--ELSE
		--	BEGIN
		--		SET @DIFFTIME = DATEDIFF( MS, @LASTTIME, GETDATE())
		--	END
		-- 결과 검사!!!
		IF @RESTTIME<=@DIFFTIME
			BEGIN
				SET @RETVALUE = 6	-- 시간제한 오버
				RETURN
			END
	END

--위의검사를 모두 통과하면 퀘스트 완료설정
UPDATE [dbo].[TB_QUEST_PROGRESS]
   SET [APPLY]=2					--진행 완료(2)
 WHERE [IDX]=@QUEST_PROGRESS_IDX
   AND [CHARACTER_IDX]=@CHARACTER_IDX

IF @@ERROR <> 0 OR @@ROWCOUNT <> 1
	BEGIN
		SET @RETVALUE = 1						--진행완료 실패
		RETURN
	END

--갱신된 상태값 받아오기
SELECT [IDX]
	  ,[APPLY]
  FROM [dbo].[TB_QUEST_PROGRESS]
 WHERE [IDX]=@QUEST_PROGRESS_IDX
' 
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[GP_QUEST_SELECT]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'

/**********************************************************************
 *<
	FILE: GP_QUEST_SELECT.SQL

	DESCRIPTION:

	CREATED BY:

	HISTORY:

 *>	Copyright (c) 2007, All Rights Reserved.
 **********************************************************************/
 
 CREATE PROCEDURE [dbo].[GP_QUEST_SELECT]
	(@CHARACTER_IDX		[int] )				--캐릭터 인덱스
        
AS

-- 적용행 출력 금지
SET NOCOUNT ON

SELECT [IDX]
	  ,[QUEST_IDX]
	  ,[CHECK]
	  ,CASE [TIME_TYPE]
		WHEN 1 THEN			-- 실시간퀘스트의 남은시간 출력
			CASE 
				WHEN [REST_TIME] > DATEDIFF( MS, [REGISTER_DATE], GETDATE()) THEN [REST_TIME] - DATEDIFF( MS, [REGISTER_DATE], GETDATE()) 	
				ELSE 0
			END
		ELSE [REST_TIME]	-- 게임시간 0R 일반퀘스트의 남은시간 출력
		END AS ''REST_TIME''	
	  ,[APPLY]				-- 퀘스트 상태값 받아오기
FROM [dbo].[TB_QUEST_PROGRESS]
WHERE [CHARACTER_IDX]=@CHARACTER_IDX AND ([APPLY]=0 OR [APPLY]=2)
' 
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[GP_QUEST_UPDATE]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'

 /**********************************************************************
 *<
	FILE: GP_QUEST_UPDATE.SQL

	DESCRIPTION:

	CREATED BY:

	HISTORY:

 *>	Copyright (c) 2007, All Rights Reserved.
 **********************************************************************/
 
 CREATE PROCEDURE [dbo].[GP_QUEST_UPDATE]
 	(@IDX				[int]			--고유인덱스
    ,@CHECK				[bigint]		--진행정보
	,@TIME_TYPE			[tinyint]		--시간 타입
    ,@REST_TIME			[int]			--남은시간
    ,@RETVALUE			[int]OUTPUT)		
        
AS

-- 적용행 출력 금지
SET NOCOUNT ON

-- 해당 퀘스트가 apply가 0이 아니면 에러
IF EXISTS (SELECT * FROM [dbo].[TB_QUEST_PROGRESS] WHERE [IDX]=@IDX AND [APPLY]<>0)
	BEGIN
		SET @RETVALUE = 1
		RETURN
	END

-- 시간타입이 게임시간이면 저장
IF @TIME_TYPE = 2
	BEGIN
		UPDATE [dbo].[TB_QUEST_PROGRESS]
		   SET [CHECK]=@CHECK
			  ,[REST_TIME]=@REST_TIME
		 WHERE [IDX]=@IDX
		   AND [APPLY]=0  		
	END
ELSE
	BEGIN
		UPDATE [dbo].[TB_QUEST_PROGRESS]
		   SET [CHECK]=@CHECK
		 WHERE [IDX]=@IDX
		   AND [APPLY]=0  	
	END


-- 2. 적용검사   
IF @@ERROR <> 0 OR @@ROWCOUNT <> 1
	BEGIN
		SET @RETVALUE = 2		-- 등록실패 :알수 없는 오류
	END
ELSE
	BEGIN
		SET @RETVALUE = 0		-- 성공
	END
' 
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[GP_QUEST_REWARD]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'

/**********************************************************************
 *<
	FILE: GP_QUEST_REWARD.SQL

	DESCRIPTION:

	CREATED BY: 김가람

	HISTORY:	[곽철중] 2008-03-18 보상금액 & 보상아이템 추가.
			    [곽철중] 2008-10-08 게임서버 & StoreProcedure 수정.

 *>	Copyright (c) 2008, All Rights Reserved.
 **********************************************************************/

CREATE PROCEDURE [dbo].[GP_QUEST_REWARD]
	(@QUEST_PROGRESS_IDX	int				--퀘스트 고유번호
	,@CHARACTER_IDX			int				--캐릭터 인덱스
	,@CHARACTER_MONEY		int				--캐릭터 보상금액
	,@JOB					int				--전직 인덱스
	,@RACE_TYPE				char			--종족
	,@FORCE_TYPE			tinyint			--세력 타입
	,@TITLE_IDX				int				--호칭 인덱스
	,@SKILL_POINT			int)			--스킬 포인트

AS

SET NOCOUNT ON

DECLARE @JOB_STEP	int
	   ,@ERRORCODE	int

BEGIN TRAN

--퀘스트완료(1)
UPDATE [dbo].[TB_QUEST_PROGRESS]
   SET [APPLY]=1
 WHERE [IDX]=@QUEST_PROGRESS_IDX
   AND [CHARACTER_IDX]=@CHARACTER_IDX

IF @@ERROR <> 0 OR @@ROWCOUNT <> 1
	GOTO ROLLBACK_TRAN

--1. 캐릭터 보상금액
IF @CHARACTER_MONEY <> 0
	BEGIN
		UPDATE [dbo].[TB_CHARACTER]
		   SET [MONEY]=[MONEY]+@CHARACTER_MONEY
		 WHERE [IDX]=@CHARACTER_IDX

		IF @@ERROR <> 0 OR @@ROWCOUNT <> 1
			GOTO ROLLBACK_TRAN
	END

--2. 전직 보상
IF @JOB <> 0
	BEGIN
		SET @JOB_STEP = 1;

		UPDATE [dbo].[TB_CHARACTER]
		   SET [JOB]=@JOB
		 WHERE [IDX]=@CHARACTER_IDX

		IF @@ERROR <> 0 OR @@ROWCOUNT <> 1
			GOTO ROLLBACK_TRAN

		EXEC GP_CHARACTER_DEFALUTSKILL_INSERT @CHARACTER_IDX, @JOB_STEP, @RACE_TYPE, @ERRORCODE OUTPUT
		IF @ERRORCODE <> 0
			GOTO ROLLBACK_TRAN
	END


--3. 세력 보상
IF @FORCE_TYPE <> 0
	BEGIN
		UPDATE [dbo].[TB_CHARACTER]
		   SET [FORCE_TYPE]=@FORCE_TYPE
		 WHERE [IDX]=@CHARACTER_IDX

		IF @@ERROR <> 0 OR @@ROWCOUNT <> 1
			GOTO ROLLBACK_TRAN
	END

--4. 호칭 보상
IF @TITLE_IDX <> 0
	BEGIN
		INSERT [dbo].[TB_TITLE]
			   ([CHARACTER_IDX]
			   ,[TITLE_IDX])
		VALUES (@CHARACTER_IDX
			   ,@TITLE_IDX )

		IF @@ERROR <> 0 OR @@ROWCOUNT <> 1
			GOTO ROLLBACK_TRAN
	END

--5. 스킬포인트 보상
IF @SKILL_POINT <> 0
	BEGIN
		UPDATE [dbo].[TB_CHARACTER]
		   SET [SKILL_POINT_REMAIN] = [SKILL_POINT_REMAIN] + @SKILL_POINT
			   ,[SKILL_POINT_TOTAL] = [SKILL_POINT_TOTAL] + @SKILL_POINT
		 WHERE [IDX]=@CHARACTER_IDX
	END

COMMIT TRAN

IF( @JOB_STEP <> 0 )
	BEGIN
		SELECT [SKILL_IDX]
		  FROM [dbo].[TB_DEFAULT_SKILL]
		 WHERE [JOB_STEP]=@JOB_STEP
		   AND [RACE_TYPE]=@RACE_TYPE
	END

RETURN 0

ROLLBACK_TRAN:
ROLLBACK TRAN
RETURN 99
' 
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[GP_CHARACTER_INSERT]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'



/**********************************************************************
 *<
	FILE: GP_CHARACTER_INSERT.SQL

	DESCRIPTION:

	CREATED BY:

	HISTORY:

 *>	Copyright (c) 2006, All Rights Reserved.
 **********************************************************************/

CREATE PROCEDURE [dbo].[GP_CHARACTER_INSERT]
	(@IDX			[int]OUTPUT
	,@NAME			[nvarchar](16)
	,@RACE			[tinyint]
	,@GENDER		[tinyint]
	,@JOB			[int]
	,@HAIR			[int]
	,@FACE			[int]
	,@XPOS			[float]
	,@YPOS			[float]
	,@HP			[int]
	,@MP			[int]
	,@STAND_IDX		[tinyint]
	,@USER_IDX		[int]
	,@RETVALUE		[int]OUTPUT)

AS

DECLARE @ERRORCODE			[int]
DECLARE @ROWCOUNT			[int]

SET NOCOUNT ON

BEGIN TRAN

IF EXISTS (SELECT * FROM [dbo].[TB_CHARACTER_NAME] WHERE @NAME LIKE ''%''+[NAME]+''%'' AND [APPLY]=0)
	BEGIN
		SET @RETVALUE = 6			--이미 정의된 이름.
		GOTO ROLLBACK_TRAN
	END

IF EXISTS (SELECT * FROM [dbo].[TB_CHARACTER_NAME] WHERE [NAME]=@NAME AND [APPLY]=1)
	BEGIN
		SET @RETVALUE = 6			--이미 정의된 이름.
		GOTO ROLLBACK_TRAN
	END

IF ( (SELECT count(*) FROM [dbo].[TB_CHARACTER] WHERE [USER_IDX]=@USER_IDX AND [APPLY]=0) > 4 )
	BEGIN
		SET @RETVALUE = 2			--캐릭터가 꽉찼음.
		GOTO ROLLBACK_TRAN
	END
	
IF EXISTS (SELECT * FROM [dbo].[TB_CHARACTER] WHERE [STAND_IDX]=@STAND_IDX AND [USER_IDX]=@USER_IDX AND [APPLY]=0)
	BEGIN
		SET @RETVALUE = 3			--스텐드 인덱스 중복됨.
		GOTO ROLLBACK_TRAN
	END

IF EXISTS (SELECT * FROM [dbo].[TB_CHARACTER] WHERE [NAME]=@NAME AND [APPLY]=0)
	BEGIN
		SET @RETVALUE = 1			--캐릭이름 중복됨.
		GOTO ROLLBACK_TRAN
	END

INSERT [dbo].[TB_CHARACTER]
        ([NAME]
        ,[RACE]
        ,[GENDER]
        ,[JOB]
        ,[HAIR]
        ,[FACE]
        ,[XPOS]
        ,[YPOS]
		,[HP]
		,[MP]
        ,[STAND_IDX]
        ,[USER_IDX])
VALUES (@NAME
        ,@RACE
        ,@GENDER
        ,@JOB
        ,@HAIR
        ,@FACE
        ,@XPOS
        ,@YPOS
		,@HP
		,@MP
        ,@STAND_IDX
        ,@USER_IDX)

SELECT @ERRORCODE=@@ERROR, @ROWCOUNT=@@ROWCOUNT

IF @ERRORCODE <> 0 OR @ROWCOUNT <> 1
	BEGIN
		SET @RETVALUE = -1			--등록실패 - 알수없는 오류.
		GOTO ROLLBACK_TRAN
	END
ELSE
	BEGIN
		SELECT @IDX=MAX(IDX)
		  FROM [dbo].[TB_CHARACTER]
         WHERE [USER_IDX]=@USER_IDX

		EXEC GP_DEFAULT_ITEMS @IDX, @JOB, @ERRORCODE OUTPUT

		IF @ERRORCODE <> 0
			BEGIN
				SET @RETVALUE = 4	--등록실패 - 아이템 지급 실패.
				GOTO ROLLBACK_TRAN
			END

		EXEC GP_CHARACTER_DEFALUTSKILL_INSERT @IDX, 0, @RACE, @ERRORCODE OUTPUT
		IF @ERRORCODE <> 0
			BEGIN
				SET @RETVALUE = 5	--등록실패 - 스킬 지급 실패.
				GOTO ROLLBACK_TRAN
			END

		COMMIT TRAN
		SET @RETVALUE = 0	--등록성공.
	END
RETURN

ROLLBACK_TRAN:
ROLLBACK TRAN
RETURN

' 
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[GP_ITEM_REWARD]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'

/**********************************************************************
 *<
	FILE: GP_ITEM_REWARD.SQL

	DESCRIPTION: 아이템 보상

	CREATED BY:	곽철중

	HISTORY:

 *>	Copyright (c) 2008, All Rights Reserved.
 **********************************************************************/

CREATE PROCEDURE [dbo].[GP_ITEM_REWARD]
	(@CHARACTER_IDX		[int]			--캐릭터 고유번호
	,@ITEM_DEFINE_INDEX	[int]			--아이템 인덱스
	,@INVENTORY_NUMBER	[smallint]		--인벤토리 번호
	,@COUNT				[smallint]		--수량
	,@RETVALUE			[int]OUTPUT)	--반환값

AS

SET NOCOUNT ON

EXEC GP_ITEM_GET @CHARACTER_IDX
                ,@ITEM_DEFINE_INDEX
                ,@INVENTORY_NUMBER
                ,@COUNT
                ,@RETVALUE OUTPUT

' 
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[GP_ITEM_GET_QUEST]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'

/**********************************************************************
 *<
	FILE: GP_ITEM_GET_QUEST.SQL

	DESCRIPTION: 아이템 습득(퀘스트)

	CREATED BY:	곽철중

	HISTORY:

 *>	Copyright (c) 2008, All Rights Reserved.
 **********************************************************************/

CREATE PROCEDURE [dbo].[GP_ITEM_GET_QUEST]
	(@CHARACTER_IDX		[int]			--캐릭터 고유번호
	,@ITEM_DEFINE_INDEX	[int]			--아이템 인덱스
	,@INVENTORY_NUMBER	[smallint]		--인벤토리 번호
	,@COUNT				[smallint]		--수량
	,@RETVALUE			[int]OUTPUT)	--반환값

AS

SET NOCOUNT ON

EXEC GP_ITEM_GET @CHARACTER_IDX
                ,@ITEM_DEFINE_INDEX
                ,@INVENTORY_NUMBER
                ,@COUNT
                ,@RETVALUE OUTPUT

' 
END
GO
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[GP_INVENTORY_EXCEPT]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'
/**********************************************************************
 *<
	FILE: GP_INVENTORY_EXCEPT.SQL

	DESCRIPTION:

	CREATED BY:

	HISTORY:

 *>	Copyright (c) 2007, All Rights Reserved.
 **********************************************************************/

CREATE PROCEDURE [dbo].[GP_INVENTORY_EXCEPT]
	(@CHARACTER_IDX	[int]		--캐릭터 고유번호
	,@IDX			[int]		--고유번호
	,@NUMBER		[smallint])	--번호

AS

SET NOCOUNT ON

EXEC GP_INVENTORY_MOVE @CHARACTER_IDX, @IDX, @NUMBER' 
END
