Sql2005一次性刪除所有表和儲存過程

2022-09-11 00:18:46 字數 2729 閱讀 3532

一次性刪除資料庫所有表和所有儲存過程 sql語句

1、刪除所有的表:

如果由於外來鍵約束刪除table失敗,則先刪除所有約束:

--/第1步**********刪除所有表的外來鍵約束*************************/

declare c1 cursor for

select

'alter table [

'+ object_name(parent_obj) + '

] drop constraint [

'+name+'

]; '

from

sysobjects

where xtype = 'f'

open c1

declare @c1 varchar(

8000

)fetch next

from

c1 into @c1

while(@@fetch_status=0

)begin

exec(@c1)

fetch next

from

c1 into @c1

endclose c1

deallocate c1

--/第2步**********刪除所有表*************************/

use 資料庫

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)

2、刪除所有儲存過程

刪除所有的儲存過程同理可得,但不需要走第一步,只需將第2步的**的where xtype='u' 改成 where xtype='p',drop table 改成 drop procedure

ysobjects的xtype代表含義:

在資料庫內建立的每個物件(約束、預設值、日誌、規則、儲存過程等)在表中佔一行。只有在 tempdb 內,每個臨時物件才在該表中佔一行。

列名 資料型別 描述

name sysname 物件名。

id int 物件標識號。

xtype char(2) 物件型別。可以是下列物件型別中的一種:

c = check 約束

d = 預設值或 default 約束

f = foreign key 約束

l = 日誌

fn = 標量函式

if = 內嵌表函式

p = 儲存過程

pk = primary key 約束(型別是 k)

rf = 複製篩選儲存過程

s = 系統表

tf = 表函式

tr = 觸發器

u = 使用者表

uq = unique 約束(型別是 k)

v = 檢視

x = 擴充套件儲存過程

uid smallint 所有者物件的使用者 id。

info smallint 保留。僅限內部使用。

status int 保留。僅限內部使用。

base_schema_

ver int 保留。僅限內部使用。

replinfo int 保留。供複製使用。

parent_obj int 父物件的物件標識號(例如,對於觸發器或約束,該標識號為表 id)。

crdate datetime 物件的建立日期。

ftcatid smallint 為全文索引註冊的所有使用者表的全文目錄識別符號,對於沒有註冊的所有使用者表則為 0。

schema_ver int 版本號,該版本號在每次表的架構更改時都增加。

stats_schema_

ver int 保留。僅限內部使用。

type char(2) 物件型別。可以是下列值之一:

c = check 約束

d = 預設值或 default 約束

f = foreign key 約束

fn = 標量函式

if = 內嵌表函式

k = primary key 或 unique 約束

l = 日誌

p = 儲存過程

r = 規則

rf = 複製篩選儲存過程

s = 系統表

tf = 表函式

tr = 觸發器

u = 使用者表

v = 檢視

x = 擴充套件儲存過程

userstat smallint 保留。

sysstat smallint 內部狀態資訊。

indexdel smallint 保留。

refdate datetime 留作以後使用。

version int 留作以後使用。

deltrig int 保留。

instrig int 保留。

updtrig int 保留。

seltrig int 保留。

category int 用於發布、約束和標識。

cache smallint 保留。   

一次性退出所有activity

可以利用清理歷史棧的方法,來巧妙關閉所有activity,首先用乙個設定為不可見的activity a來啟動程式,這個activity a的作用只是用來墊棧底,只有啟動和退出程式才會用到這個activity,而你需要退出的時候,只需要跳轉至這個activity a 並讓a finish自己就可以實現...

一次性關閉所有的activity

看到很多關於應用退出的問題,今天在這裡為大家簡單總結一下,如果說的不對還望大家見諒。方法一 system.exit 0 和android.os.process.killprocess android.os.process.mypid 我想很多人都嘗試過,當關 閉多個activity的時候這兩個方法根...

oracle庫中所有表一次性轉hive表結構指令碼

select to char substr table prefix col strs table subfix,1,4000 con from select n.table prefix,wm concat m.col str as col strs,n.table subfix from sel...