检测 存储过程/表/函数是否存在函数 fExists

类别: Javascript, function
标签: func, table, tsql, exists, proc, fExists
摘要: ..
正文:

  1. if EXISTS(select 1 from sysobjects where type='fn' and name='fExists')
  2. Begin
  3.  Drop Function fExists
  4. End
  5. Go

  6. Create Function dbo.fExists
  7. (-- shawl.qiu TSql
  8.  @vChrTableName varchar(200)
  9.  ,@vChrType varchar(200) = 'u'
  10. )
  11. Returns Bit
  12. As
  13. Begin 
  14.  Set @vChrType = Lower(@vChrType)
  15.  declare @MyVar varchar(200)
  16.  
  17.  set @MyVar =
  18.  Case @vChrType
  19.  when 'p' then
  20.   'p'
  21.  when 'fn' then 'fn'
  22.  else
  23.   'u'
  24.  End

  25.  if EXISTS(select 1 from sysobjects where type=@MyVar and name=@vChrTableName)
  26.  Begin
  27.   Return(1)
  28.  End
  29.  
  30.  Return(0)

  31. End -- end function fExists
  32. Go


  33. -- if dbo.fExists('Mytest', default)=1
  34. --  print 'exists'
  35. -- else
  36. --  print 'no exists'
  37. -- 
  38. -- 
  39. -- print  dbo.fExists('Mytest', default)
  40. -- print  dbo.fExists('Mytestx', default)

  41. -- print dbo.fExists('pMyTest', 'p')
  42. -- print dbo.fExists('pMyTestx', 'p')
  43. -- 
  44. -- print dbo.fExists('fExistsTable', 'fn')
  45. -- print dbo.fExists('fExistsTablex', 'fn')
 
文章相关信息:
主题: 检测 存储过程/表/函数是否存在函数 fExists
发表者: shawl.qiu
电子邮件: shawl.qiu@gmail.com
QQ: 908202921
MSN: btbtd@msn.com
Homepage: http://www.btbtd.org/
Blog: http://blog.csdn.net/btbtd/
发表日期: 2007-6-13 18:18:48
更新日期: 2007-6-13 18:18:48
来源引用: shawl.qiu CSharp DotNet 个人资料管理系统
引用本页: http://gi.2288.org/mod/code/display/Default.aspx?aid=467
关闭
Google
搜索WWW
搜索www.btbtd.org
搜索blog.csdn.net
Powered by shawl.qiu © 2008-2010 the shawl.qiu Javascript Kits
Copyright © 2008-2010 by shawl.qiu