-- ==============================
-- 长登科技 www.ppfor.com
-- 唐镇波   2010-04-19
-- ------------------------------
-- Discuz用户表
-- ==============================

--Discuz用户ID表
if not exists (select * from sysobjects where id = object_id(N'[PPFOR_TZB_DiscuzUser]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
CREATE TABLE [PPFOR_TZB_DiscuzUser] (	
	[memberID] int not null unique REFERENCES [PPFOR_TZB_Member]([_ID]) ON DELETE CASCADE,	
	[discuzUserID] int not null default(0)
)
PPFOR_GO;

if exists (select * from sysobjects where id = object_id(N'[PPFOR_TZB_DiscuzUser_Update]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [PPFOR_TZB_DiscuzUser_Update]
PPFOR_GO;
create procedure PPFOR_TZB_DiscuzUser_Update(@memberID int,@discuzUserID int)
as
	begin
		if exists (select [discuzUserID] from [PPFOR_TZB_DiscuzUser] where [memberID]=@memberID)
			update [PPFOR_TZB_DiscuzUser] set [discuzUserID]=@discuzUserID where [memberID]=@memberID
		else
			insert [PPFOR_TZB_DiscuzUser] values (@memberID,@discuzUserID)
	end
PPFOR_GO;

if exists (select * from sysobjects where id = object_id(N'[PPFOR_TZB_DiscuzUser_Delete]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [PPFOR_TZB_DiscuzUser_Delete]
PPFOR_GO;
create procedure PPFOR_TZB_DiscuzUser_Delete(@discuzUserID int)
as
	begin
		if @discuzUserID>0
			update [PPFOR_TZB_DiscuzUser] set [discuzUserID]=0 where [discuzUserID]=@discuzUserID
	end
PPFOR_GO;

if exists (select * from sysobjects where id = object_id(N'[PPFOR_TZB_DiscuzUser_GetModel]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [PPFOR_TZB_DiscuzUser_GetModel]
PPFOR_GO;
create procedure PPFOR_TZB_DiscuzUser_GetModel(@memberID int)
as
	begin
		select [memberID],[discuzUserID] from [PPFOR_TZB_DiscuzUser] where [memberID]=@memberID
	end
PPFOR_GO;