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



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

if exists(select 1 from sysobjects where name='FK_templatePrivilege_privilege' and xtype='F')
Alter table templatePrivilege drop constraint FK_templatePrivilege_privilege
GO

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



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



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



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



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



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

if not exists(select * from sysobjects where parent_obj=object_id('bigClass') and xtype='PK')
 alter table bigClass add constraint pkId primary key (pkId)
GO


CREATE TABLE [contribute] (
	[pkId] [int] IDENTITY (1, 1) NOT NULL ,
	[intactTitle] [varchar] (100) COLLATE Chinese_PRC_CI_AS NULL ,
	[Author] [varchar] (100) COLLATE Chinese_PRC_CI_AS NULL ,
	[AuthorMail] [varchar] (100) COLLATE Chinese_PRC_CI_AS NULL ,
	[CopyFrom] [varchar] (100) COLLATE Chinese_PRC_CI_AS NULL ,
	[copyFromLink] [varchar] (100) COLLATE Chinese_PRC_CI_AS NULL ,
	[about] [varchar] (100) COLLATE Chinese_PRC_CI_AS NULL ,
	[pageType] [int] NULL ,
	[autoPageCharNum] [int] NULL ,
	[content] [text] COLLATE Chinese_PRC_CI_AS NULL ,
	[userId] [int] NULL ,
	[updateTime] [datetime] NULL ,
	[state] [int] NULL ,
	[MenuId] [int] NULL ,
	[bigClassId] [int] NULL ,
	[updateIp] [varchar] (100) COLLATE Chinese_PRC_CI_AS NULL ,
	[contributeId] [int] NULL ,
	[auditRemark] [text] COLLATE Chinese_PRC_CI_AS NULL ,
	[newsId] [int] NULL ,
	CONSTRAINT [contribute_PK] PRIMARY KEY  CLUSTERED 
	(
		[pkId]
	)  ON [PRIMARY] 
) ON [PRIMARY]
GO



CREATE TABLE [contributeClass] (
	[pkId] [int] IDENTITY (1, 1) NOT NULL ,
	[contributeClassId] [int] NULL ,
	[bigClassId] [int] NULL ,
	CONSTRAINT [PK_contributeClass] PRIMARY KEY  CLUSTERED 
	(
		[pkId]
	)  ON [PRIMARY] ,
	CONSTRAINT [FK_contributeClass_bigClass] FOREIGN KEY 
	(
		[bigClassId]
	) REFERENCES [bigClass] (
		[pkId]
	),
	CONSTRAINT [FK_contributeClass_menu] FOREIGN KEY 
	(
		[contributeClassId]
	) REFERENCES [menu] (
		[pkId]
	)
) ON [PRIMARY]
GO



CREATE TABLE [privilege] (
	[pkId] [int] IDENTITY (1, 1) NOT NULL ,
	[name] [varchar] (100) COLLATE Chinese_PRC_CI_AS NULL ,
	[nameRemark] [varchar] (100) COLLATE Chinese_PRC_CI_AS NULL ,
	[accreditValue] [varchar] (100) COLLATE Chinese_PRC_CI_AS NULL ,
	[accreditRemark] [varchar] (200) COLLATE Chinese_PRC_CI_AS NULL ,
	[showType] [varchar] (100) COLLATE Chinese_PRC_CI_AS NULL ,
	[itemEnglish] [varchar] (200) COLLATE Chinese_PRC_CI_AS NULL ,
	[itemChinese] [varchar] (200) COLLATE Chinese_PRC_CI_AS NULL ,
	CONSTRAINT [PK_privilege] PRIMARY KEY  CLUSTERED 
	(
		[pkId]
	)  ON [PRIMARY] 
) ON [PRIMARY]
GO



CREATE TABLE [templatePrivilege] (
	[pkId] [int] IDENTITY (1, 1) NOT NULL ,
	[templateId] [int] NULL ,
	[privilegeId] [int] NULL ,
	CONSTRAINT [PK_templatePrivilege] PRIMARY KEY  CLUSTERED 
	(
		[pkId]
	)  ON [PRIMARY] ,
	CONSTRAINT [FK_templatePrivilege_privilege] FOREIGN KEY 
	(
		[privilegeId]
	) REFERENCES [privilege] (
		[pkId]
	),
	CONSTRAINT [FK_templatePrivilege_template] FOREIGN KEY 
	(
		[templateId]
	) REFERENCES [template] (
		[pkId]
	)
) ON [PRIMARY]
GO



CREATE TABLE [siteContributeClass] (
	[pkId] [int] IDENTITY (1, 1) NOT NULL ,
	[bigClassId] [int] NULL ,
	CONSTRAINT [siteContributeClass_PK] PRIMARY KEY  CLUSTERED 
	(
		[pkId]
	)  ON [PRIMARY] 
) ON [PRIMARY]
GO



CREATE TABLE [siteContribute] (
	[pkId] [int] IDENTITY (1, 1) NOT NULL ,
	[intactTitle] [varchar] (100) COLLATE Chinese_PRC_CI_AS NULL ,
	[Author] [varchar] (100) COLLATE Chinese_PRC_CI_AS NULL ,
	[AuthorMail] [varchar] (100) COLLATE Chinese_PRC_CI_AS NULL ,
	[CopyFrom] [varchar] (100) COLLATE Chinese_PRC_CI_AS NULL ,
	[copyFromLink] [varchar] (100) COLLATE Chinese_PRC_CI_AS NULL ,
	[about] [varchar] (100) COLLATE Chinese_PRC_CI_AS NULL ,
	[pageType] [int] NULL ,
	[autoPageCharNum] [int] NULL ,
	[content] [text] COLLATE Chinese_PRC_CI_AS NULL ,
	[updateTime] [datetime] NULL ,
	[state] [int] NULL ,
	[bigClassId] [int] NULL ,
	[updateIp] [varchar] (100) COLLATE Chinese_PRC_CI_AS NULL ,
	[auditRemark] [text] COLLATE Chinese_PRC_CI_AS NULL ,
	[userName] [varchar] (100) COLLATE Chinese_PRC_CI_AS NULL ,
	[newsId] [int] NULL ,
	[originalNewsId] [int] NULL ,
	CONSTRAINT [siteContribute_PK] PRIMARY KEY  CLUSTERED 
	(
		[pkId]
	)  ON [PRIMARY] 
) ON [PRIMARY]
GO


CREATE TABLE [todayInHistory] (
	[pkId] [int] IDENTITY (1, 1) NOT NULL ,
	[newsId] [int] NOT NULL ,
	[happenType] [int] NOT NULL ,
	[happenDate] [datetime] NOT NULL ,
	CONSTRAINT [PK_todayInHistory] PRIMARY KEY  CLUSTERED 
	(
		[pkId]
	)  ON [PRIMARY] 
) ON [PRIMARY]
GO


CREATE TABLE [siteOtherProperty] (
	[pkId] [int] IDENTITY (1, 1) NOT NULL ,
	[newsDefaultClick] [int] NULL ,
	[showNewHours] [int] NULL ,
	[showHotClick] [int] NULL ,
	CONSTRAINT [PK_siteOtherProperty] PRIMARY KEY  CLUSTERED 
	(
		[pkId]
	)  ON [PRIMARY] 
) ON [PRIMARY]
GO
