if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[FK_Fm_comment_Fm_model_main]') and OBJECTPROPERTY(id, N'IsForeignKey') = 1)
ALTER TABLE [dbo].[Fm_comment] DROP CONSTRAINT FK_Fm_comment_Fm_model_main
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[FK_Fm_power_Fm_role]') and OBJECTPROPERTY(id, N'IsForeignKey') = 1)
ALTER TABLE [dbo].[Fm_power] DROP CONSTRAINT FK_Fm_power_Fm_role
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[FK_Fm_urcenter_Fm_role]') and OBJECTPROPERTY(id, N'IsForeignKey') = 1)
ALTER TABLE [dbo].[Fm_urcenter] DROP CONSTRAINT FK_Fm_urcenter_Fm_role
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[FK_Fm_urcenter_Fm_user]') and OBJECTPROPERTY(id, N'IsForeignKey') = 1)
ALTER TABLE [dbo].[Fm_urcenter] DROP CONSTRAINT FK_Fm_urcenter_Fm_user
GO

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

CREATE TABLE [dbo].[Fm_ad] (
	[adid] [int] IDENTITY (1, 1) NOT NULL ,
	[adletter] [varchar] (100) COLLATE Chinese_PRC_CI_AS NOT NULL ,
	[adpic] [varchar] (100) COLLATE Chinese_PRC_CI_AS NOT NULL ,
	[adjs] [varchar] (500) COLLATE Chinese_PRC_CI_AS NOT NULL ,
	[adurl] [varchar] (200) COLLATE Chinese_PRC_CI_AS NOT NULL ,
	[acid] [int] NOT NULL 
) ON [PRIMARY]
GO

CREATE TABLE [dbo].[Fm_adclass] (
	[acid] [int] IDENTITY (1, 1) NOT NULL ,
	[acname] [varchar] (100) COLLATE Chinese_PRC_CI_AS NOT NULL ,
	[acintro] [varchar] (1000) COLLATE Chinese_PRC_CI_AS NOT NULL 
) ON [PRIMARY]
GO

CREATE TABLE [dbo].[Fm_affiche] (
	[aff_id] [int] IDENTITY (1, 1) NOT NULL ,
	[aff_title] [varchar] (200) COLLATE Chinese_PRC_CI_AS NULL ,
	[aff_content] [varchar] (6000) COLLATE Chinese_PRC_CI_AS NULL ,
	[aff_user] [varchar] (50) COLLATE Chinese_PRC_CI_AS NULL ,
	[aff_btime] [datetime] NULL ,
	[aff_look] [int] NULL 
) ON [PRIMARY]
GO

CREATE TABLE [dbo].[Fm_author] (
	[au_id] [int] IDENTITY (1, 1) NOT NULL ,
	[au_name] [varchar] (100) COLLATE Chinese_PRC_CI_AS NULL 
) ON [PRIMARY]
GO

CREATE TABLE [dbo].[Fm_column] (
	[cl_id] [int] NOT NULL ,
	[cl_name] [varchar] (100) COLLATE Chinese_PRC_CI_AS NOT NULL ,
	[cl_tg] [bit] NULL ,
	[cl_xs] [bit] NULL ,
	[cl_path] [varchar] (60) COLLATE Chinese_PRC_CI_AS NULL ,
	[cl_location] [bit] NULL ,
	[cl_options] [int] NULL ,
	[cl_attribute] [int] NULL ,
	[cl_temp_index] [varchar] (100) COLLATE Chinese_PRC_CI_AS NULL ,
	[cl_temp_list] [varchar] (100) COLLATE Chinese_PRC_CI_AS NULL ,
	[cl_temp_cont] [varchar] (100) COLLATE Chinese_PRC_CI_AS NULL ,
	[cl_default] [varchar] (100) COLLATE Chinese_PRC_CI_AS NULL ,
	[cl_content] [varchar] (100) COLLATE Chinese_PRC_CI_AS NULL ,
	[cl_list] [varchar] (100) COLLATE Chinese_PRC_CI_AS NULL ,
	[cl_url] [varchar] (100) COLLATE Chinese_PRC_CI_AS NULL ,
	[cl_keyword] [varchar] (300) COLLATE Chinese_PRC_CI_AS NULL ,
	[cl_intro] [varchar] (500) COLLATE Chinese_PRC_CI_AS NULL ,
	[cl_parent] [varchar] (50) COLLATE Chinese_PRC_CI_AS NULL ,
	[cl_px] [int] NULL 
) ON [PRIMARY]
GO

CREATE TABLE [dbo].[Fm_comment] (
	[comid] [int] IDENTITY (1, 1) NOT NULL ,
	[username] [varchar] (50) COLLATE Chinese_PRC_CI_AS NULL ,
	[content] [varchar] (500) COLLATE Chinese_PRC_CI_AS NOT NULL ,
	[writetime] [datetime] NOT NULL ,
	[docid] [int] NOT NULL ,
	[ip] [varchar] (50) COLLATE Chinese_PRC_CI_AS NULL ,
	[lou] [int] NOT NULL ,
	[support] [int] NOT NULL ,
	[against] [int] NOT NULL 
) ON [PRIMARY]
GO

CREATE TABLE [dbo].[Fm_group] (
	[g_id] [int] NOT NULL ,
	[g_name] [varchar] (50) COLLATE Chinese_PRC_CI_AS NOT NULL 
) ON [PRIMARY]
GO

CREATE TABLE [dbo].[Fm_link] (
	[link_id] [int] IDENTITY (1, 1) NOT NULL ,
	[link_name] [varchar] (50) COLLATE Chinese_PRC_CI_AS NULL ,
	[link_url] [varchar] (50) COLLATE Chinese_PRC_CI_AS NULL ,
	[link_px] [int] NULL ,
	[link_type] [bit] NULL ,
	[link_logo] [varchar] (100) COLLATE Chinese_PRC_CI_AS NULL ,
	[link_intro] [varchar] (300) COLLATE Chinese_PRC_CI_AS NULL 
) ON [PRIMARY]
GO

CREATE TABLE [dbo].[Fm_login] (
	[lo_id] [int] IDENTITY (1, 1) NOT NULL ,
	[lo_user] [varchar] (50) COLLATE Chinese_PRC_CI_AS NULL ,
	[lo_ip] [varchar] (50) COLLATE Chinese_PRC_CI_AS NULL ,
	[lo_time] [datetime] NULL 
) ON [PRIMARY]
GO

CREATE TABLE [dbo].[Fm_member_menu] (
	[mid] [int] NOT NULL ,
	[mname] [varchar] (50) COLLATE Chinese_PRC_CI_AS NOT NULL ,
	[url] [varchar] (300) COLLATE Chinese_PRC_CI_AS NOT NULL ,
	[parent] [int] NOT NULL 
) ON [PRIMARY]
GO

CREATE TABLE [dbo].[Fm_member_power] (
	[pid] [int] IDENTITY (1, 1) NOT NULL ,
	[mid] [int] NOT NULL ,
	[rid] [int] NOT NULL 
) ON [PRIMARY]
GO

CREATE TABLE [dbo].[Fm_menu] (
	[m_id] [int] NOT NULL ,
	[m_name] [varchar] (50) COLLATE Chinese_PRC_CI_AS NULL ,
	[m_url] [varchar] (50) COLLATE Chinese_PRC_CI_AS NULL ,
	[m_type] [int] NULL ,
	[m_parent] [varchar] (10) COLLATE Chinese_PRC_CI_AS NULL 
) ON [PRIMARY]
GO

CREATE TABLE [dbo].[Fm_model] (
	[mid] [int] NOT NULL ,
	[mtype] [int] NULL ,
	[enmark] [varchar] (80) COLLATE Chinese_PRC_CI_AS NOT NULL ,
	[cnmark] [varchar] (100) COLLATE Chinese_PRC_CI_AS NOT NULL ,
	[tablename] [varchar] (50) COLLATE Chinese_PRC_CI_AS NOT NULL ,
	[adminadd] [varchar] (100) COLLATE Chinese_PRC_CI_AS NOT NULL ,
	[adminlist] [varchar] (100) COLLATE Chinese_PRC_CI_AS NOT NULL ,
	[adminedit] [varchar] (100) COLLATE Chinese_PRC_CI_AS NOT NULL ,
	[useradd] [varchar] (100) COLLATE Chinese_PRC_CI_AS NULL ,
	[userlist] [varchar] (100) COLLATE Chinese_PRC_CI_AS NULL ,
	[useredit] [varchar] (100) COLLATE Chinese_PRC_CI_AS NULL 
) ON [PRIMARY]
GO

CREATE TABLE [dbo].[Fm_model_article] (
	[docid] [int] NOT NULL ,
	[content] [text] COLLATE Chinese_PRC_CI_AS NOT NULL ,
	[author] [varchar] (100) COLLATE Chinese_PRC_CI_AS NULL ,
	[source] [varchar] (100) COLLATE Chinese_PRC_CI_AS NULL 
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
GO

CREATE TABLE [dbo].[Fm_model_htm] (
	[htmid] [int] IDENTITY (1, 1) NOT NULL ,
	[docid] [int] NULL ,
	[path] [varchar] (100) COLLATE Chinese_PRC_CI_AS NULL ,
	[page] [int] NULL 
) ON [PRIMARY]
GO

CREATE TABLE [dbo].[Fm_model_main] (
	[docid] [int] IDENTITY (1, 1) NOT NULL ,
	[colid] [int] NOT NULL ,
	[title] [varchar] (300) COLLATE Chinese_PRC_CI_AS NOT NULL ,
	[head] [bit] NOT NULL ,
	[map] [bit] NOT NULL ,
	[flash] [bit] NOT NULL ,
	[commend] [bit] NOT NULL ,
	[bold] [bit] NOT NULL ,
	[writertime] [smalldatetime] NOT NULL ,
	[username] [varchar] (50) COLLATE Chinese_PRC_CI_AS NULL ,
	[click] [int] NOT NULL ,
	[audit] [bit] NOT NULL ,
	[comment] [bit] NOT NULL ,
	[color] [varchar] (30) COLLATE Chinese_PRC_CI_AS NULL ,
	[keyword] [varchar] (300) COLLATE Chinese_PRC_CI_AS NULL ,
	[intro] [varchar] (1000) COLLATE Chinese_PRC_CI_AS NULL ,
	[html] [bit] NOT NULL ,
	[topclick] [int] NULL ,
	[tread] [int] NULL ,
	[thumbnail] [varchar] (150) COLLATE Chinese_PRC_CI_AS NULL 
) ON [PRIMARY]
GO

CREATE TABLE [dbo].[Fm_power] (
	[p_id] [int] IDENTITY (1, 1) NOT NULL ,
	[m_id] [int] NULL ,
	[r_id] [int] NULL 
) ON [PRIMARY]
GO

CREATE TABLE [dbo].[Fm_role] (
	[r_id] [int] IDENTITY (1, 1) NOT NULL ,
	[r_name] [varchar] (50) COLLATE Chinese_PRC_CI_AS NULL ,
	[g_id] [int] NULL 
) ON [PRIMARY]
GO

CREATE TABLE [dbo].[Fm_singlepage] (
	[sid] [int] IDENTITY (1, 1) NOT NULL ,
	[stitle] [varchar] (100) COLLATE Chinese_PRC_CI_AS NOT NULL ,
	[skeywords] [varchar] (100) COLLATE Chinese_PRC_CI_AS NOT NULL ,
	[sintro] [varchar] (300) COLLATE Chinese_PRC_CI_AS NOT NULL ,
	[scontent] [text] COLLATE Chinese_PRC_CI_AS NOT NULL ,
	[stemplates] [varchar] (50) COLLATE Chinese_PRC_CI_AS NOT NULL ,
	[spath] [varchar] (80) COLLATE Chinese_PRC_CI_AS NOT NULL 
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
GO

CREATE TABLE [dbo].[Fm_source] (
	[so_id] [int] IDENTITY (1, 1) NOT NULL ,
	[so_name] [varchar] (50) COLLATE Chinese_PRC_CI_AS NULL 
) ON [PRIMARY]
GO

CREATE TABLE [dbo].[Fm_urcenter] (
	[c_id] [int] IDENTITY (1, 1) NOT NULL ,
	[u_id] [int] NULL ,
	[r_id] [int] NULL 
) ON [PRIMARY]
GO

CREATE TABLE [dbo].[Fm_user] (
	[u_id] [int] IDENTITY (1, 1) NOT NULL ,
	[u_name] [varchar] (20) COLLATE Chinese_PRC_CI_AS NOT NULL ,
	[u_pass] [varchar] (300) COLLATE Chinese_PRC_CI_AS NOT NULL ,
	[u_nc] [varchar] (30) COLLATE Chinese_PRC_CI_AS NULL ,
	[u_mail] [varchar] (50) COLLATE Chinese_PRC_CI_AS NOT NULL 
) ON [PRIMARY]
GO

CREATE TABLE [dbo].[Fm_webset] (
	[sid] [int] NOT NULL ,
	[webname] [varchar] (100) COLLATE Chinese_PRC_CI_AS NULL ,
	[weburl] [varchar] (100) COLLATE Chinese_PRC_CI_AS NULL ,
	[title] [varchar] (50) COLLATE Chinese_PRC_CI_AS NULL ,
	[uppath] [varchar] (50) COLLATE Chinese_PRC_CI_AS NULL ,
	[keyword] [varchar] (300) COLLATE Chinese_PRC_CI_AS NULL ,
	[intro] [varchar] (300) COLLATE Chinese_PRC_CI_AS NULL ,
	[banquan] [varchar] (500) COLLATE Chinese_PRC_CI_AS NULL ,
	[beian] [varchar] (50) COLLATE Chinese_PRC_CI_AS NULL ,
	[member] [bit] NULL ,
	[tougao] [bit] NULL ,
	[html] [varchar] (100) COLLATE Chinese_PRC_CI_AS NULL 
) ON [PRIMARY]
GO

ALTER TABLE [dbo].[Fm_ad] ADD 
	CONSTRAINT [PK_Fm_ad] PRIMARY KEY  CLUSTERED 
	(
		[adid]
	)  ON [PRIMARY] 
GO

ALTER TABLE [dbo].[Fm_adclass] ADD 
	CONSTRAINT [PK_Fm_adclass] PRIMARY KEY  CLUSTERED 
	(
		[acid]
	)  ON [PRIMARY] 
GO

ALTER TABLE [dbo].[Fm_affiche] ADD 
	CONSTRAINT [PK_Fm_affiche] PRIMARY KEY  CLUSTERED 
	(
		[aff_id]
	)  ON [PRIMARY] 
GO

ALTER TABLE [dbo].[Fm_author] ADD 
	CONSTRAINT [PK_Fm_author] PRIMARY KEY  CLUSTERED 
	(
		[au_id]
	)  ON [PRIMARY] 
GO

ALTER TABLE [dbo].[Fm_column] ADD 
	CONSTRAINT [PK_Fm_Artclass] PRIMARY KEY  CLUSTERED 
	(
		[cl_id]
	)  ON [PRIMARY] 
GO

ALTER TABLE [dbo].[Fm_comment] ADD 
	CONSTRAINT [PK_Fm_comment] PRIMARY KEY  CLUSTERED 
	(
		[comid]
	)  ON [PRIMARY] 
GO

ALTER TABLE [dbo].[Fm_group] ADD 
	CONSTRAINT [PK_Fm_group] PRIMARY KEY  CLUSTERED 
	(
		[g_id]
	)  ON [PRIMARY] 
GO

ALTER TABLE [dbo].[Fm_link] ADD 
	CONSTRAINT [PK_Fm_link] PRIMARY KEY  CLUSTERED 
	(
		[link_id]
	)  ON [PRIMARY] 
GO

ALTER TABLE [dbo].[Fm_login] ADD 
	CONSTRAINT [PK_Fm_login] PRIMARY KEY  CLUSTERED 
	(
		[lo_id]
	)  ON [PRIMARY] 
GO

ALTER TABLE [dbo].[Fm_member_menu] ADD 
	CONSTRAINT [PK_Fm_member_menu] PRIMARY KEY  CLUSTERED 
	(
		[mid]
	)  ON [PRIMARY] 
GO

ALTER TABLE [dbo].[Fm_member_power] ADD 
	CONSTRAINT [PK_Fm_member_power] PRIMARY KEY  CLUSTERED 
	(
		[pid]
	)  ON [PRIMARY] 
GO

ALTER TABLE [dbo].[Fm_menu] ADD 
	CONSTRAINT [PK_Fm_menu] PRIMARY KEY  CLUSTERED 
	(
		[m_id]
	)  ON [PRIMARY] 
GO

ALTER TABLE [dbo].[Fm_model] ADD 
	CONSTRAINT [PK_Fm_model] PRIMARY KEY  CLUSTERED 
	(
		[mid]
	)  ON [PRIMARY] 
GO

ALTER TABLE [dbo].[Fm_model_article] ADD 
	CONSTRAINT [PK_Fm_model_article] PRIMARY KEY  CLUSTERED 
	(
		[docid]
	)  ON [PRIMARY] 
GO

ALTER TABLE [dbo].[Fm_model_htm] ADD 
	CONSTRAINT [PK_Fm_htm] PRIMARY KEY  CLUSTERED 
	(
		[htmid]
	)  ON [PRIMARY] 
GO

ALTER TABLE [dbo].[Fm_model_main] ADD 
	CONSTRAINT [PK_Fm_mode_main] PRIMARY KEY  CLUSTERED 
	(
		[docid]
	)  ON [PRIMARY] 
GO

ALTER TABLE [dbo].[Fm_power] ADD 
	CONSTRAINT [PK_Fm_power] PRIMARY KEY  CLUSTERED 
	(
		[p_id]
	)  ON [PRIMARY] 
GO

ALTER TABLE [dbo].[Fm_role] ADD 
	CONSTRAINT [PK_Fm_role] PRIMARY KEY  CLUSTERED 
	(
		[r_id]
	)  ON [PRIMARY] 
GO

ALTER TABLE [dbo].[Fm_singlepage] ADD 
	CONSTRAINT [PK_Fm_singlepage] PRIMARY KEY  CLUSTERED 
	(
		[sid]
	)  ON [PRIMARY] 
GO

ALTER TABLE [dbo].[Fm_source] ADD 
	CONSTRAINT [PK_Fm_source] PRIMARY KEY  CLUSTERED 
	(
		[so_id]
	)  ON [PRIMARY] 
GO

ALTER TABLE [dbo].[Fm_urcenter] ADD 
	CONSTRAINT [PK_Fm_urcenter] PRIMARY KEY  CLUSTERED 
	(
		[c_id]
	)  ON [PRIMARY] 
GO

ALTER TABLE [dbo].[Fm_user] ADD 
	CONSTRAINT [PK_Fm_user] PRIMARY KEY  CLUSTERED 
	(
		[u_id]
	)  ON [PRIMARY] 
GO

ALTER TABLE [dbo].[Fm_webset] ADD 
	CONSTRAINT [PK_Fm_Webset] PRIMARY KEY  CLUSTERED 
	(
		[sid]
	)  ON [PRIMARY] 
GO

ALTER TABLE [dbo].[Fm_comment] ADD 
	CONSTRAINT [FK_Fm_comment_Fm_model_main] FOREIGN KEY 
	(
		[docid]
	) REFERENCES [dbo].[Fm_model_main] (
		[docid]
	) ON DELETE CASCADE  NOT FOR REPLICATION 
GO

ALTER TABLE [dbo].[Fm_power] ADD 
	CONSTRAINT [FK_Fm_power_Fm_role] FOREIGN KEY 
	(
		[r_id]
	) REFERENCES [dbo].[Fm_role] (
		[r_id]
	) ON DELETE CASCADE  NOT FOR REPLICATION 
GO

ALTER TABLE [dbo].[Fm_urcenter] ADD 
	CONSTRAINT [FK_Fm_urcenter_Fm_role] FOREIGN KEY 
	(
		[r_id]
	) REFERENCES [dbo].[Fm_role] (
		[r_id]
	) ON DELETE CASCADE  NOT FOR REPLICATION ,
	CONSTRAINT [FK_Fm_urcenter_Fm_user] FOREIGN KEY 
	(
		[u_id]
	) REFERENCES [dbo].[Fm_user] (
		[u_id]
	) ON DELETE CASCADE  NOT FOR REPLICATION 
GO



create view Fm_adclass_ad
as
select ad.*,ac.acname from Fm_ad as ad inner join Fm_adclass as ac on ad.acid=ac.acid

GO


CREATE VIEW dbo.Fm_model_article_view
AS
SELECT main.*, art.content, art.author, art.source, col.cl_name,col.cl_parent, htm.path
FROM dbo.Fm_model_main main INNER JOIN
      dbo.Fm_model_article art ON main.docid = art.docid INNER JOIN
      dbo.Fm_column col ON main.colid = col.cl_id LEFT OUTER JOIN
          (SELECT *
         FROM Fm_model_htm
         WHERE page = 1) htm ON main.docid = htm.docid

GO


CREATE VIEW dbo.Fm_model_search_view
AS
SELECT main.docid, main.colid, main.title,main.intro,main.keyword, main.writertime,main.audit,main.html,htm.path
FROM dbo.Fm_model_main main  LEFT OUTER JOIN
          (SELECT *
         FROM Fm_model_htm
         WHERE page = 1) htm ON main.docid = htm.docid where audit=1


GO


CREATE VIEW dbo.Fm_model_view
AS
SELECT main.docid, main.colid, main.title, main.writertime, main.username, main.click, 
      main.audit, main.head, main.map, main.flash, main.commend, main.bold,main.html,
      col.cl_name, col.cl_path
FROM dbo.Fm_model_main main INNER JOIN
      dbo.Fm_column col ON main.colid = col.cl_id LEFT OUTER JOIN
          (SELECT *
         FROM Fm_model_htm
         WHERE page = 1) htm ON main.docid = htm.docid


GO


create view Fm_role_view
as
select r.r_id,r.r_name,g.g_id,g.g_name from Fm_role as r 
            inner join Fm_group as g on r.g_id=g.g_id 


GO


create view Fm_comment_view
as
select main.title,com.* from Fm_model_main as main inner join Fm_comment as com
       on main.docid=com.docid

GO


CREATE VIEW dbo.Fm_user_view
AS
SELECT u.*, r.r_id, r.r_name, g.g_id, g.g_name,ur.c_id
FROM dbo.Fm_user u LEFT OUTER JOIN
      dbo.Fm_urcenter ur ON u.u_id = ur.u_id LEFT OUTER JOIN
      dbo.Fm_role r ON ur.r_id = r.r_id LEFT OUTER JOIN
      dbo.Fm_group g ON r.g_id = g.g_id


GO


