CREATE PROCEDURE [dbo].[Local_CreateMonitorCommandTable] @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( 'MonitorCommand_Log_'+ @year+'_'+@month ) IS NULL begin declare @br varchar(1500) set @br='CREATE TABLE MonitorCommand_Log_'+ @year+'_'+@month+ '( [log_id] [int] IDENTITY(1,1) NOT NULL, [log_type] [int] NOT NULL, [world_ID] [int] NOT NULL, [channel_ID] [int] NOT NULL, [executer_ID] [nvarchar] (16) NOT NULL, [command] [int] NOT NULL, [target] [int] NOT NULL, [date] [datetime] NOT NULL CONSTRAINT [DF_MonitorCommand_Log_'+ @year+'_'+ @month+'_entry_date] DEFAULT (getdate()), )' exec(@br) ----- set @br='ALTER TABLE [dbo].[MonitorCommand_Log_'+ @year+'_'+ @month+'] WITH NOCHECK ADD CONSTRAINT [PK_log_id_MonitorCommand_Log_'+ @year+'_'+ @month+'] PRIMARY KEY CLUSTERED ( [log_id] ASC ) ON [PRIMARY]' exec(@br) ----- set @br='CREATE NONCLUSTERED INDEX [IX_log_type_MonitorCommand_Log_'+ @year+'_'+ @month+'] ON [dbo].[MonitorCommand_Log_'+ @year+'_'+ @month+'] ( [log_type] ASC )WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]' exec(@br) ----- set @br='CREATE NONCLUSTERED INDEX [IX_world_id_MonitorCommand_Log_'+ @year+'_'+ @month+'] ON [dbo].[MonitorCommand_Log_'+ @year+'_'+ @month+'] ( [world_id] ASC )WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]' exec(@br) ----- set @br='CREATE NONCLUSTERED INDEX [IX_date_MonitorCommand_Log_'+ @year+'_'+ @month+'] ON [dbo].[MonitorCommand_Log_'+ @year+'_'+ @month+'] ( [date] ASC )WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]' exec(@br) end