CREATE TABLE [dbo].[bayes_expire] (
        [id] [int] NOT NULL ,
        [runtime] [int] NOT NULL 
) ON [PRIMARY]
GO

CREATE TABLE [dbo].[bayes_global_vars] (
        [variable] [varchar] (30) NOT NULL ,
        [value] [varchar] (200) NOT NULL 
) ON [PRIMARY]
GO

INSERT INTO bayes_global_vars VALUES ('VERSION','3');

GO
CREATE TABLE [dbo].[bayes_seen] (
        [id] [int] NOT NULL ,
        [msgid] [varchar] (200) NOT NULL ,
        [flag] [char] (1) NOT NULL 
) ON [PRIMARY]
GO

CREATE TABLE [dbo].[bayes_token] (
        [id] [int] NOT NULL ,
        [token] [char] (5) NOT NULL ,
        [spam_count] [int] NOT NULL ,
        [ham_count] [int] NOT NULL ,
        [atime] [int] NOT NULL 
) ON [PRIMARY]
GO

CREATE TABLE [dbo].[bayes_vars] (
        [id] [int] IDENTITY (1, 1) NOT NULL ,
        [username] [varchar] (200) NOT NULL ,
        [spam_count] [int] NOT NULL ,
        [ham_count] [int] NOT NULL ,
        [token_count] [int] NOT NULL ,
        [last_expire] [int] NOT NULL ,
        [last_atime_delta] [int] NOT NULL ,
        [last_expire_reduce] [int] NOT NULL ,
        [oldest_token_age] [int] NOT NULL ,
        [newest_token_age] [int] NOT NULL 
) ON [PRIMARY]
GO

ALTER TABLE [dbo].[bayes_expire] WITH NOCHECK ADD 
        CONSTRAINT [bayes_expire_idx1] PRIMARY KEY  CLUSTERED 
        (
                [id]
        )  ON [PRIMARY] 
GO

ALTER TABLE [dbo].[bayes_global_vars] WITH NOCHECK ADD 
        CONSTRAINT [PK_bayes_global_vars_variable] PRIMARY KEY  CLUSTERED 
        (
                [variable]
        )  ON [PRIMARY] 
GO

ALTER TABLE [dbo].[bayes_seen] WITH NOCHECK ADD 
        CONSTRAINT [PK_bayes_seen_id_msgid] PRIMARY KEY  CLUSTERED 
        (
                [id],
                [msgid]
        )  ON [PRIMARY] 
GO

ALTER TABLE [dbo].[bayes_token] WITH NOCHECK ADD 
        CONSTRAINT [PK_bayes_token_id_token] PRIMARY KEY  CLUSTERED 
        (
                [id],
                [token]
        )  ON [PRIMARY] 
GO

ALTER TABLE [dbo].[bayes_vars] WITH NOCHECK ADD 
        CONSTRAINT [PK_bayes_vars_id] PRIMARY KEY  CLUSTERED 
        (
                [id]
        )  ON [PRIMARY] 
GO

ALTER TABLE [dbo].[bayes_expire] ADD 
        CONSTRAINT [DF__bayes_expire__id__07F6335A] DEFAULT ('0') FOR [id],
        CONSTRAINT [DF__bayes_exp__runti__08EA5793] DEFAULT ('0') FOR [runtime]
GO

ALTER TABLE [dbo].[bayes_global_vars] ADD 
        CONSTRAINT [DF__bayes_glo__varia__0BC6C43E] DEFAULT ('') FOR [variable],
        CONSTRAINT [DF__bayes_glo__value__0CBAE877] DEFAULT ('') FOR [value]
GO

ALTER TABLE [dbo].[bayes_seen] ADD 
        CONSTRAINT [DF__bayes_seen__id__0F975522] DEFAULT ('0') FOR [id],
        CONSTRAINT [DF__bayes_see__msgid__108B795B] DEFAULT ('') FOR [msgid],
        CONSTRAINT [DF__bayes_seen__flag__117F9D94] DEFAULT ('') FOR [flag]
GO

ALTER TABLE [dbo].[bayes_token] ADD 
        CONSTRAINT [DF__bayes_token__id__145C0A3F] DEFAULT ('0') FOR [id],
        CONSTRAINT [DF__bayes_tok__token__15502E78] DEFAULT ('') FOR [token],
        CONSTRAINT [DF__bayes_tok__spam___164452B1] DEFAULT ('0') FOR [spam_count],
        CONSTRAINT [DF__bayes_tok__ham_c__173876EA] DEFAULT ('0') FOR [ham_count],
        CONSTRAINT [DF__bayes_tok__atime__182C9B23] DEFAULT ('0') FOR [atime]
GO

ALTER TABLE [dbo].[bayes_vars] ADD 
        CONSTRAINT [DF__bayes_var__usern__3A81B327] DEFAULT ('') FOR [username],
        CONSTRAINT [DF__bayes_var__spam___3B75D760] DEFAULT ('0') FOR [spam_count],
        CONSTRAINT [DF__bayes_var__ham_c__3C69FB99] DEFAULT ('0') FOR [ham_count],
        CONSTRAINT [DF__bayes_var__token__3D5E1FD2] DEFAULT ('0') FOR [token_count],
        CONSTRAINT [DF__bayes_var__last___3E52440B] DEFAULT ('0') FOR [last_expire],
        CONSTRAINT [DF__bayes_var__last___3F466844] DEFAULT ('0') FOR [last_atime_delta],
        CONSTRAINT [DF__bayes_var__last___403A8C7D] DEFAULT ('0') FOR [last_expire_reduce],
        CONSTRAINT [DF__bayes_var__oldes__412EB0B6] DEFAULT ('2147483647') FOR [oldest_token_age],
        CONSTRAINT [DF__bayes_var__newes__4222D4EF] DEFAULT ('0') FOR [newest_token_age],
        CONSTRAINT [IX_bayes_vars_username] UNIQUE  NONCLUSTERED 
        (
                [username]
        )  ON [PRIMARY] 
GO

CREATE FUNCTION [dbo].[RPAD] (@string varchar(4000) , @length int, @pad char(1))
RETURNS varchar(4000) AS  
BEGIN
return (substring(@string,1,len(@string)) + replicate(@pad,@length-len(@string)))
END
GO

GRANT  EXECUTE  ON [dbo].[RPAD]  TO [public]
GO