CREATE PROCEDURE [dbo].[Local_CreateMCUTable] @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( 'MCU_Log_'+ @year+'_'+@month ) IS NULL begin declare @br varchar(1500) set @br='CREATE TABLE MCU_Log_'+ @year+'_'+@month+ '( [log_id] [bigint] IDENTITY(1,1) NOT NULL, [log_type] [smallint] NOT NULL, [world_id] [int] NOT NULL, [user_num] [int] NOT NULL DEFAULT (0), [date] [datetime] NOT NULL DEFAULT (getdate()), )' exec(@br) ----- set @br='ALTER TABLE [dbo].[MCU_Log_'+ @year+'_'+ @month+'] WITH NOCHECK ADD CONSTRAINT [PK_log_id_MCU_Log_'+ @year+'_'+ @month+'] PRIMARY KEY CLUSTERED ( [log_id] ASC ) ON [PRIMARY]' exec(@br) ----- set @br='CREATE NONCLUSTERED INDEX [IX_world_id_MCU_Log_'+ @year+'_'+ @month+'] ON [dbo].[MCU_Log_'+ @year+'_'+ @month+'] ( [world_id] ASC )WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]' exec(@br) ----- set @br='CREATE NONCLUSTERED INDEX [IX_date_MCU_Log_'+ @year+'_'+ @month+'] ON [dbo].[MCU_Log_'+ @year+'_'+ @month+'] ( [date] ASC )WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]' exec(@br) ----- set @br='CREATE NONCLUSTERED INDEX [IX_logtype_tem_Log_'+ @year+'_'+ @month+'] ON [dbo].[MCU_Log_'+ @year+'_'+ @month+'] ( [log_type] ASC )WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]' exec(@br) end