CREATE PROCEDURE [dbo].[Local_CreateLoginOutTable] @createtime datetime as set nocount on declare @year varchar(50) declare @month varchar(50) set @year = convert(varchar, datepart(yy,@createtime)) set @month = convert(varchar, datepart(mm,@createtime)) if OBJECT_ID( 'LoginOut_Log_'+ @year+'_'+@month ) IS NULL begin declare @br varchar(2000) set @br='CREATE TABLE LoginOut_Log_'+ @year+'_'+@month+ '( [log_id] [bigint] IDENTITY(1,1) NOT NULL, [date] [datetime] NOT NULL CONSTRAINT [DF_LoginOut_Log_'+ @year+'_'+ @month+'_entry_date] DEFAULT (getdate()), [log_type] [smallint] NOT NULL, [world_id] [int] NOT NULL, [auth_id] [uniqueidentifier] NOT NULL, [channel_group] [tinyint] NOT NULL, [channel_num] [int] NOT NULL, [bcust_id] [nvarchar](16) NOT NULL, [character_id] [uniqueidentifier] NOT NULL, [character_name] [nvarchar](16) NOT NULL, [inven_gold] [int] NOT NULL, [storage_gold] [int] NOT NULL, [character_level] [tinyint] NOT NULL, [character_exp] [int] NOT NULL, [targetmap] [int] NOT NULL, [playpoint] [int] NOT NULL, [skillpoint] [int] NOT NULL, [guildpoint] [int] NOT NULL, [coin] [int] NOT NULL, )' exec(@br) ----- set @br='ALTER TABLE [dbo].[LoginOut_Log_'+ @year+'_'+ @month+'] WITH NOCHECK ADD CONSTRAINT [PK_log_id_LoginOut_Log_'+ @year+'_'+ @month+'] PRIMARY KEY CLUSTERED ( [log_id] ASC ) ON [PRIMARY]' exec(@br) set @br='CREATE NONCLUSTERED INDEX [IX_date_LoginOut_Log_'+ @year+'_'+ @month+'] ON [dbo].[LoginOut_Log_'+ @year+'_'+ @month+'] ( [date] ASC )WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]' exec(@br) end