EXEC sp_rename '[dnt_userfields].[bio]',  'bio2',  'COLUMN'
;
ALTER TABLE [dnt_userfields] ADD [bio] [nvarchar](500) NOT NULL DEFAULT ('')
;
UPDATE [dnt_userfields] SET [bio]=[bio2]
;
ALTER TABLE [dnt_userfields] DROP CONSTRAINT DF__dnt_userfie__bio__7D197D8B
;
ALTER TABLE [dnt_userfields] DROP COLUMN [bio2]
;

EXEC sp_rename '[dnt_userfields].[signature]',  'signature2',  'COLUMN'
;
ALTER TABLE [dnt_userfields] ADD [signature] [nvarchar](500) NOT NULL DEFAULT ('')
;
UPDATE [dnt_userfields] SET [signature]=[signature2]
;
ALTER TABLE [dnt_userfields] DROP CONSTRAINT DF__dnt_userf__signa__7E0DA1C4
;
ALTER TABLE [dnt_userfields] DROP COLUMN [signature2]
;


EXEC sp_rename '[dnt_userfields].[sightml]',  'sightml2',  'COLUMN'
;
ALTER TABLE [dnt_userfields] ADD [sightml] [nvarchar](1000) NOT NULL DEFAULT ('')
;
UPDATE [dnt_userfields] SET [sightml]=[sightml2]
;
ALTER TABLE [dnt_userfields] DROP CONSTRAINT DF_dnt_userfields_signahtml
;
ALTER TABLE [dnt_userfields] DROP COLUMN [sightml2]
;

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

update [dnt_advertisements] set [type]='0' where [type]='头部横幅广告'
;
update [dnt_advertisements] set [type]='1' where [type]='尾部横幅广告'
;
update [dnt_advertisements] set [type]='2' where [type]='页内文字广告'
;
update [dnt_advertisements] set [type]='3' where [type]='贴内广告'
;
update [dnt_advertisements] set [type]='4' where [type]='浮动广告'
;
update [dnt_advertisements] set [type]='5' where [type]='对联广告'
;


ALTER TABLE [dnt_forums] ALTER column [lasttitle] [nchar](60) NOT NULL
;
ALTER TABLE [dnt_topics] ALTER column [title] [nchar](60) NOT NULL
;
ALTER TABLE [dnt_online] ALTER column [title] [nvarchar](60) NOT NULL
;
ALTER TABLE [dnt_pms] ALTER column [subject] [nvarchar](60) NOT NULL
;
ALTER TABLE [dnt_posts1] ALTER column [title] [nchar](60) NOT NULL
;
ALTER TABLE [dnt_users] ALTER column [lastposttitle] [nchar](60) NOT NULL
;

ALTER TABLE [dnt_adminvisitlog] ALTER column [username] nvarchar(20) not null
;
ALTER TABLE [dnt_adminvisitlog] ALTER column [grouptitle] nvarchar(50) not null
;
ALTER TABLE [dnt_adminvisitlog] ALTER column [actions] nvarchar(100) not null
;
ALTER TABLE [dnt_adminvisitlog] ALTER column [others] nvarchar(200) not null
;

ALTER TABLE [dnt_advertisements] ALTER column [type] nvarchar(50) not null
;
ALTER TABLE [dnt_advertisements] ALTER column [title] nvarchar(50) not null
;
ALTER TABLE [dnt_advertisements] ALTER column [targets] nvarchar(255) not null
;

ALTER TABLE [dnt_bbcodes] ALTER column [example] nvarchar(255) not null
;

ALTER TABLE [dnt_creditslog] ALTER column [fromto] int not null
;

ALTER TABLE [dnt_forumfields] ALTER column [password] nvarchar(16) not null
;

ALTER TABLE [dnt_forumlinks] ALTER column [name] nvarchar(100) not null
;
ALTER TABLE [dnt_forumlinks] ALTER column [url] nvarchar(100) not null
;
ALTER TABLE [dnt_forumlinks] ALTER column [note] nvarchar(200) not null
;
ALTER TABLE [dnt_forumlinks] ALTER column [logo] nvarchar(100) not null
;

ALTER TABLE [dnt_medals] ALTER column [name] nvarchar(50) not null
;

ALTER TABLE [dnt_ratelog] ALTER column [username] nchar(20) not null
;

ALTER TABLE [dnt_smilies] ALTER column [code] nvarchar(30) not null
;

ALTER TABLE [dnt_statistics] ALTER column [lastusername] nchar(20) not null
;

ALTER TABLE [dnt_usergroups] ALTER column [raterange] nchar(500) not null
;

ALTER TABLE [dnt_words] ALTER column [admin] nvarchar(20) not null
;
ALTER TABLE [dnt_words] ALTER column [find] nvarchar(255) not null
;
ALTER TABLE [dnt_words] ALTER column [replacement] nvarchar(255) not null
;


EXEC sp_rename '[dnt_advertisements].[code]',  'code2',  'COLUMN'
;
ALTER TABLE [dnt_advertisements] ADD [code] [ntext]
;
UPDATE [dnt_advertisements] SET [code]=[code2]
;
ALTER TABLE [dnt_advertisements] DROP COLUMN [code2]
;

EXEC sp_rename '[dnt_advertisements].[parameters]',  'parameters2',  'COLUMN'
;
ALTER TABLE [dnt_advertisements] ADD [parameters] [ntext]
;
UPDATE [dnt_advertisements] SET [parameters]=[parameters2]
;
ALTER TABLE [dnt_advertisements] DROP COLUMN [parameters2]
;

EXEC sp_rename '[dnt_bbcodes].[explanation]',  'explanation2',  'COLUMN'
;
ALTER TABLE [dnt_bbcodes] ADD [explanation] [ntext]
;
UPDATE [dnt_bbcodes] SET [explanation]=[explanation2]
;
ALTER TABLE [dnt_bbcodes] DROP COLUMN [explanation2]
;

EXEC sp_rename '[dnt_bbcodes].[replacement]',  'replacement2',  'COLUMN'
;
ALTER TABLE [dnt_bbcodes] ADD [replacement] [ntext]
;
UPDATE [dnt_bbcodes] SET [replacement]=[replacement2]
;
ALTER TABLE [dnt_bbcodes] DROP COLUMN [replacement2]
;

EXEC sp_rename '[dnt_bbcodes].[paramsdescript]',  'paramsdescript2',  'COLUMN'
;
ALTER TABLE [dnt_bbcodes] ADD [paramsdescript] [ntext]
;
UPDATE [dnt_bbcodes] SET [paramsdescript]=[paramsdescript2]
;
ALTER TABLE [dnt_bbcodes] DROP COLUMN [paramsdescript2]
;

EXEC sp_rename '[dnt_bbcodes].[paramsdefvalue]',  'paramsdefvalue2',  'COLUMN'
;
ALTER TABLE [dnt_bbcodes] ADD [paramsdefvalue] [ntext]
;
UPDATE [dnt_bbcodes] SET [paramsdefvalue]=[paramsdefvalue2]
;
ALTER TABLE [dnt_bbcodes] DROP COLUMN [paramsdefvalue2]
;

EXEC sp_rename '[dnt_forumfields].[moderators]',  'moderators2',  'COLUMN'
;
ALTER TABLE [dnt_forumfields] ADD [moderators] [ntext]
;
UPDATE [dnt_forumfields] SET [moderators]=[moderators2]
;
ALTER TABLE [dnt_forumfields] DROP COLUMN [moderators2]
;

EXEC sp_rename '[dnt_forumfields].[description]',  'description2',  'COLUMN'
;
ALTER TABLE [dnt_forumfields] ADD [description] [ntext]
;
UPDATE [dnt_forumfields] SET [description]=[description2]
;
ALTER TABLE [dnt_forumfields] DROP COLUMN [description2]
;

if not exists(select 1 from sysobjects where parent_obj=object_id('dnt_failedlogins'))
begin
	CREATE TABLE [dnt_failedlogins] (
		[ip] [char] (15)  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]

end

;

if not exists(select 1 from sysobjects where parent_obj=object_id('dnt_online'))
begin
	CREATE TABLE [dnt_online] (
		[olid] [int] IDENTITY (1, 1) NOT NULL ,
		[userid] [int] NOT NULL ,
		[ip] [varchar] (15)  NOT NULL ,
		[username] [nvarchar] (20)  NOT NULL ,
		[tickcount] [int] NOT NULL ,
		[nickname] [nvarchar] (20)  NOT NULL ,
		[password] [char] (32)  NOT NULL ,
		[groupid] [smallint] NOT NULL ,
		[olimg] [varchar] (80)  NOT NULL ,
		[adminid] [smallint] NOT NULL ,
		[invisible] [smallint] NOT NULL ,
		[action] [smallint] NOT NULL ,
		[lastactivity] [smallint] NOT NULL ,
		[lastposttime] [datetime] NOT NULL ,
		[lastpostpmtime] [datetime] NOT NULL ,
		[lastsearchtime] [datetime] NOT NULL ,
		[lastupdatetime] [datetime] NOT NULL ,
		[forumid] [int] NOT NULL ,
		[forumname] [nvarchar] (50)  NOT NULL ,
		[titleid] [int] NOT NULL ,
		[title] [nvarchar] (60)  NOT NULL ,
		[verifycode] [varchar] (10)  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_lastpostpmtime] DEFAULT ('1900-1-1 00:00:00') FOR [lastpostpmtime],
		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]

	CREATE  INDEX [forum] ON [dnt_online]([userid], [forumid], [invisible]) ON [PRIMARY]

	CREATE  INDEX [invisible] ON [dnt_online]([userid], [invisible]) ON [PRIMARY]

	CREATE  INDEX [forumid] ON [dnt_online]([forumid]) ON [PRIMARY]

	CREATE  INDEX [password] ON [dnt_online]([userid], [password]) ON [PRIMARY]

	CREATE  INDEX [pwsecques] ON [dnt_users]([username], [password], [secques]) ON [PRIMARY]

	CREATE  INDEX [emailsecques] ON [dnt_users]([username], [email], [secques]) ON [PRIMARY]

	CREATE  INDEX [password] ON [dnt_users]([username], [password]) ON [PRIMARY]
	
	CREATE  INDEX [username] ON [dnt_users]([username]) ON [PRIMARY]

end

;


if not exists(select 1 from sysobjects where name='DF_dnt_forums_curtopics')
	ALTER TABLE [dnt_forums] ADD [curtopics] [int] NOT NULL,
		CONSTRAINT [DF_dnt_forums_curtopics] DEFAULT (0) FOR [curtopics]

;

if not exists(select 1 from sysobjects where name='DF_dnt_forums_colcount')
	ALTER TABLE [dnt_forums] ADD [colcount] [smallint] NOT NULL,
		CONSTRAINT [DF_dnt_forums_colcount] DEFAULT (1) FOR [colcount]
		
;

update [dnt_forums] set colcount = 1 where colcount=0

;

if not exists(select 1 from sysobjects where name='DF_dnt_forums_allowthumbnail')
	ALTER TABLE [dnt_forums] ADD [allowthumbnail] [int] NOT NULL,
		CONSTRAINT [DF_dnt_forums_allowthumbnail] DEFAULT ('0') FOR [allowthumbnail]
;

if not exists(select 1 from sysobjects where name='DF_dnt_online_lastpostpmtime')
	ALTER TABLE [dnt_online] ADD [lastpostpmtime] [datetime] NOT NULL,
		CONSTRAINT [DF_dnt_online_lastpostpmtime] DEFAULT (1) FOR [lastpostpmtime]
;


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

if not exists(select 1 from sysindexes where name='uid')
	 CREATE INDEX [uid] ON [dnt_attachments]([uid]) ON [PRIMARY]
;

update [dnt_forums] set [curtopics]=0 
;

update [dnt_forums] set [allowthumbnail]=0  where allowthumbnail is null
;