---
title: "清除表，存储过程"
author: "wfdoublext"
date: "2010-12-02T17:20:44Z"
tags: []
categories: ["数据库"]
slug: "untitled"
draft: false
lastmod: "2010-12-02T17:20:44Z"
id: 831821
url: "https://skyofdawn.iteye.com/blog/831821"
---

清除表

--declare @tname varchar(8000)

--set @tname=''

--select @tname=@tname + Name + ',' from sysobjects where xtype='U'

--select @tname='drop table ' + left(@tname,len(@tname)-1)

--exec(@tname).

 

 

--清除存储过程

--declare @procName varchar(500)

--     declare cur cursor

--           for select \[name] from sysobjects where type = 'p'

--     open cur

--     fetch next from cur into @procName

--      while @@fetch\_status = 0

--     begin

--            if @procName &lt;&gt; 'DeleteAllProcedures'

--                 exec('drop procedure ' + @procName)

--                 fetch next from cur into @procName

--     end

--     close cur

--     deallocate cur