/****** Object:  Table [dbo].[UserRoleTest]    Script Date: 2009-5-25 4:33:17 ******/
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[UserRoleTest]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[UserRoleTest]
GO

CREATE TABLE [dbo].[UserRoleTest] (
	[ID] [int] IDENTITY (1, 1) NOT NULL ,
	[Name] [nvarchar] (50) COLLATE Chinese_PRC_CI_AS NULL ,
	[NameC] [nvarchar] (50) COLLATE Chinese_PRC_CI_AS NULL ,
	CONSTRAINT [PK_UserRoleTest] PRIMARY KEY  CLUSTERED 
	(
		[ID]
	)  ON [PRIMARY] 
) ON [PRIMARY]
GO

GRANT  SELECT  ON [dbo].[UserRoleTest]  TO [public]
GO


exec sp_addextendedproperty N'MS_Description', N'自动增长', N'user', N'dbo', N'table', N'UserRoleTest', N'column', N'ID'
GO
exec sp_addextendedproperty N'MS_Description', N'角色名', N'user', N'dbo', N'table', N'UserRoleTest', N'column', N'Name'
GO
exec sp_addextendedproperty N'MS_Description', N'中文角色名', N'user', N'dbo', N'table', N'UserRoleTest', N'column', N'NameC'

GO

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


SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO

/****** Object:  User Defined Function dbo.UDF_PublicStringEscapeTest    Script Date: 2009-5-25 4:33:27 ******/
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[UDF_PublicStringEscapeTest]') and xtype in (N'FN', N'IF', N'TF'))
drop function [dbo].[UDF_PublicStringEscapeTest]
GO

--==============================================================================================
--==用户函数，给出一个字符串，将其中的单引号 （'） 转换成两个单引号 （''），就是，将其中的单引号逃逸
--==这个 UDF 用在有动态语句存在的场合，用来逃逸输入参数中的单引号，因为如果不逃逸，将发生类似  WHERE GoodsName='Lady's Overcoat' 的尴尬局面
--==为了满足所有场合，该函数的输出输出参数都为 NVARCHAR(4000)
--==============================================================================================
--==输入参数：@InputString -- 将被处理的字符串
--==返回结果：nvarchar -- 逃逸处理后的字符串
--==============================================================================================
--==版权所有 2001-2009 COMSHARP CMS （锐商企业CMS） http://www.comsharp.com
--==最新修改 2008-10-26
--==============================================================================================

CREATE FUNCTION dbo.UDF_PublicStringEscapeTest (@InputString NVARCHAR(4000))  

RETURNS nvarchar(4000) 

AS  

--ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ

BEGIN 
	RETURN REPLACE(@InputString,'''','''''')
END

--ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ







GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

GRANT  EXECUTE  ON [dbo].[UDF_PublicStringEscapeTest]  TO [public]
GO


if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[UDF_PublicStringEscapeTest]') and xtype in (N'FN', N'IF', N'TF'))
drop function [dbo].[UDF_PublicStringEscapeTest]
GO