server-re/decomp/schema/RustyHearts_Log/procs/Local_CreateDungeonTable.sql

60 lines
1.9 KiB
Transact-SQL

CREATE PROCEDURE [dbo].[Local_CreateDungeonTable]
@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( 'Dungeon_Log_'+ @year+'_'+@month ) IS NULL
begin
declare @br varchar(2000)
set @br='CREATE TABLE Dungeon_Log_'+ @year+'_'+@month+
'(
[log_id] [int] IDENTITY(1,1) NOT NULL,
[date] [datetime] NOT NULL CONSTRAINT [DF_Dungeon_Log_'+ @year+'_'+ @month+'_entry_date] DEFAULT (getdate()),
[log_type] [int] NOT NULL,
[instance_id] [uniqueidentifier] NOT NULL,
[world_id] [int] NOT NULL,
[dungeon_id] [int] NOT NULL ,
[difficulty] [tinyint] NOT NULL,
[membercountstart] [tinyint] NOT NULL,
[death] [tinyint] NOT NULL ,
[rebirth] [tinyint] NOT NULL,
)'
exec(@br)
-----
set @br='ALTER TABLE [dbo].[Dungeon_Log_'+ @year+'_'+ @month+'] WITH NOCHECK ADD
CONSTRAINT [PK_log_id_Dungeon_Log_'+ @year+'_'+ @month+'] PRIMARY KEY CLUSTERED
(
[log_id] ASC
) ON [PRIMARY]'
exec(@br)
-----
set @br='CREATE NONCLUSTERED INDEX [IX_world_id_Dungeon_Log_'+ @year+'_'+ @month+'] ON [dbo].[Dungeon_Log_'+ @year+'_'+ @month+']
(
[world_id] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]'
exec(@br)
-----
set @br='CREATE NONCLUSTERED INDEX [IX_DungeonID_Dungeon_Log_'+ @year+'_'+ @month+'] ON [dbo].[Dungeon_Log_'+ @year+'_'+ @month+']
(
[dungeon_id] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]'
exec(@br)
-----
set @br='CREATE NONCLUSTERED INDEX [IX_logtype_Dungeon_Log_'+ @year+'_'+ @month+'] ON [dbo].[Dungeon_Log_'+ @year+'_'+ @month+']
(
[log_type] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]'
exec(@br)
-----
set @br='CREATE NONCLUSTERED INDEX [IX_date_Dungeon_Log_'+ @year+'_'+ @month+'] ON [dbo].[Dungeon_Log_'+ @year+'_'+ @month+']
(
[date] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]'
exec(@br)
end