C#检测SqlServer中某张表是否存在

-- =============================================
-- Author:		<杨俊明(菩提下的杨过 http://yjmyzz.cnblogs.com/)>
-- Create date: <2010-5-17>
-- Description:	<检查指定表是否存在>
-- =============================================
Create PROCEDURE up_TableExists
	@tableName nvarchar(50) 
AS
BEGIN
	declare @sql nvarchar(max);
	set @sql = 'select COUNT(*) from sysobjects where id=object_id(N''' + @tableName + ''') and OBJECTPROPERTY(id,N''IsUserTable'')=1';
	print @sql
	exec(@sql)
END
GO

c#调用这个存储过程,返回1则存在,返回0则表不存在

posted @ 2010-05-17 14:04  菩提树下的杨过  阅读(4974)  评论(4编辑  收藏  举报