﻿ALTER TABLE dnt_users DROP CONSTRAINT [DF__dnt_users__oltim__14F1071C]
;

ALTER TABLE dnt_users ALTER column oltime int not null
;

ALTER TABLE dnt_users ADD CONSTRAINT [DF__dnt_users__oltim__14F1071C] DEFAULT (0) FOR [oltime]
;



if exists (select * from sysobjects where id = object_id(N'[dnt_moderatormanagelog]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dnt_moderatormanagelog]

;

CREATE TABLE [dnt_moderatormanagelog] (
	[id] [int] IDENTITY (1, 1) NOT NULL ,
	[moderatoruid] [int] NULL ,
	[moderatorname] [nvarchar] (50) COLLATE Chinese_PRC_CI_AS NULL ,
	[groupid] [int] NULL ,
	[grouptitle] [nvarchar] (50) COLLATE Chinese_PRC_CI_AS NULL ,
	[ip] [varchar] (15) COLLATE Chinese_PRC_CI_AS NULL ,
	[postdatetime] [datetime] NULL ,
	[fid] [int] NULL ,
	[fname] [nvarchar] (100) COLLATE Chinese_PRC_CI_AS NULL ,
	[tid] [int] NULL ,
	[title] [varchar] (200) COLLATE Chinese_PRC_CI_AS NULL ,
	[actions] [varchar] (50) COLLATE Chinese_PRC_CI_AS NULL ,
	[reason] [nvarchar] (200) COLLATE Chinese_PRC_CI_AS NULL 
) ON [PRIMARY]

;

ALTER TABLE [dnt_moderatormanagelog] ADD 
	CONSTRAINT [DF_dnt_moderatormanagelog_postdatetime] DEFAULT (getdate()) FOR [postdatetime]

;




if exists (select * from sysobjects where id = object_id(N'[dnt_online]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dnt_online]
;

CREATE TABLE [dnt_online] (
	[olid] [int] IDENTITY (1, 1) NOT NULL ,
	[userid] [int] NOT NULL ,
	[ip] [varchar] (15) COLLATE Chinese_PRC_CI_AS NOT NULL ,
	[username] [nvarchar] (20) COLLATE Chinese_PRC_CI_AS NOT NULL ,
	[tickcount] [int] NOT NULL ,
	[nickname] [nvarchar] (20) COLLATE Chinese_PRC_CI_AS NOT NULL ,
	[password] [char] (32) COLLATE Chinese_PRC_CI_AS NOT NULL ,
	[groupid] [smallint] NOT NULL ,
	[olimg] [varchar] (80) COLLATE Chinese_PRC_CI_AS NOT NULL ,
	[adminid] [smallint] NOT NULL ,
	[invisible] [smallint] NOT NULL ,
	[action] [smallint] NOT NULL ,
	[lastactivity] [smallint] NOT NULL ,
	[lastposttime] [datetime] NOT NULL ,
	[lastsearchtime] [datetime] NOT NULL ,
	[lastupdatetime] [datetime] NOT NULL ,
	[forumid] [int] NOT NULL ,
	[forumname] [nvarchar] (50) COLLATE Chinese_PRC_CI_AS NOT NULL ,
	[titleid] [int] NOT NULL ,
	[title] [nvarchar] (80) COLLATE Chinese_PRC_CI_AS NOT NULL ,
	[verifycode] [varchar] (10) COLLATE Chinese_PRC_CI_AS NOT NULL 
) ON [PRIMARY]
;

ALTER TABLE [dnt_online] WITH NOCHECK ADD 
	CONSTRAINT [PK_dnt_online] PRIMARY KEY  CLUSTERED 
	(
		[olid]
	)  ON [PRIMARY] 
;

ALTER TABLE [dnt_online] ADD 
	CONSTRAINT [DF_dnt_online_userid] DEFAULT ((-1)) FOR [userid],
	CONSTRAINT [DF_dnt_online_ip] DEFAULT ('0.0.0.0') FOR [ip],
	CONSTRAINT [DF_dnt_online_username] DEFAULT ('') FOR [username],
	CONSTRAINT [DF_dnt_online_tickcount] DEFAULT (0) FOR [tickcount],
	CONSTRAINT [DF_dnt_online_nickname] DEFAULT ('') FOR [nickname],
	CONSTRAINT [DF_dnt_online_password] DEFAULT ('') FOR [password],
	CONSTRAINT [DF_dnt_online_groupid] DEFAULT (0) FOR [groupid],
	CONSTRAINT [DF_dnt_online_olimg] DEFAULT ('') FOR [olimg],
	CONSTRAINT [DF_dnt_online_adminid] DEFAULT (0) FOR [adminid],
	CONSTRAINT [DF_dnt_online_invisible] DEFAULT (0) FOR [invisible],
	CONSTRAINT [DF_dnt_online_action] DEFAULT (0) FOR [action],
	CONSTRAINT [DF_dnt_online_lastactivity] DEFAULT (0) FOR [lastactivity],
	CONSTRAINT [DF_dnt_online_lastposttime] DEFAULT ('1900-1-1 00:00:00') FOR [lastposttime],
	CONSTRAINT [DF_dnt_online_lastsearchtime] DEFAULT ('1900-1-1 00:00:00') FOR [lastsearchtime],
	CONSTRAINT [DF_dnt_online_lastupdatetime] DEFAULT (getdate()) FOR [lastupdatetime],
	CONSTRAINT [DF_dnt_online_forumid] DEFAULT (0) FOR [forumid],
	CONSTRAINT [DF_dnt_online_forumname] DEFAULT ('') FOR [forumname],
	CONSTRAINT [DF_dnt_online_titleid] DEFAULT (0) FOR [titleid],
	CONSTRAINT [DF_dnt_online_title] DEFAULT ('') FOR [title],
	CONSTRAINT [DF_dnt_online_verifycode] DEFAULT ('') FOR [verifycode]
;



if (not exists (select * from sysindexes where name='PK_dnt_topics'))
    ALTER TABLE [dnt_topics] ADD 
	CONSTRAINT [PK_dnt_topics] PRIMARY KEY  NONCLUSTERED 
	(
		[tid]
	)  ON [PRIMARY] 
;




ALTER TABLE dnt_onlinelist ALTER column title nvarchar(50) not null
;



if exists (select * from sysobjects where id = object_id(N'[dnt_failedlogins]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dnt_failedlogins]
;

CREATE TABLE [dnt_failedlogins] (
	[ip] [char] (15) COLLATE Chinese_PRC_CI_AS NOT NULL ,
	[errcount] [smallint] NOT NULL ,
	[lastupdate] [smalldatetime] NOT NULL 
) ON [PRIMARY]
;

ALTER TABLE [dnt_failedlogins] WITH NOCHECK ADD 
	CONSTRAINT [PK_dnt_failedlogins] PRIMARY KEY  CLUSTERED 
	(
		[ip]
	)  ON [PRIMARY] 
;

ALTER TABLE [dnt_failedlogins] ADD 
	CONSTRAINT [DF_dnt_failedlogins_errcount] DEFAULT (0) FOR [errcount],
	CONSTRAINT [DF_dnt_failedlogins_lastupdate] DEFAULT (getdate()) FOR [lastupdate]
;


ALTER TABLE [dnt_forums] ADD 
[colcount] smallint NOT NULL,
CONSTRAINT [DF_dnt_forums_colcount] DEFAULT (1) FOR [colcount];


ALTER TABLE [dnt_forums] ADD 

[curtopics] [int]  NOT NULL,
CONSTRAINT [DF_dnt_forums_curtopics] DEFAULT (0) FOR [curtopics];


Update [dnt_forums] SET [status]=1 WHERE [status]>0
;


CREATE UNIQUE  CLUSTERED  INDEX [list] ON [dnt_topics]([fid], [displayorder], [lastpostid] DESC ) WITH  DROP_EXISTING   ON [PRIMARY]
;

update [dnt_users] set [showemail]=2 where [showemail]=1
;

update [dnt_users] set [showemail]=1 where [showemail]=0
;

update [dnt_users] set [showemail]=0 where [showemail]=2
;
   