国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 開發 > 綜合 > 正文

刪除數據庫的所有存儲過程、主鍵、外鍵、索引等

2024-07-21 02:08:00
字體:
來源:轉載
供稿:網友

--刪除存儲過程
declare @string varchar(8000)
while exists(select name from sysobjects where type='p' and status>=0)
begin
 select top 1 @string='drop  procedure '+name  from   sysobjects    where   type = 'p' and status>=0
 --select @string
 exec(@string)
end

go

--默認值或 default 約束
declare @string varchar(8000)
while exists(select name from sysobjects where xtype='d')
begin
 select top 1 @string='alter table '+b.name+' drop constraint '+a.name
  from (select parent_obj,name from sysobjects where xtype='d') a,
        (select id,name from sysobjects where objectproperty(id, n'isusertable') = 1) b
    where a.parent_obj=b.id
 exec(@string)
end

go

--unique 約束
declare @string varchar(8000)
while exists(select name from sysobjects where xtype='uq')
begin
 select top 1 @string='alter table '+b.name+' drop constraint '+a.name
  from (select parent_obj,name from sysobjects where xtype='uq') a,
        (select id,name from sysobjects where objectproperty(id, n'isusertable') = 1) b
    where a.parent_obj=b.id
 exec(@string)
end

go

--foreign key 約束
declare @string varchar(8000)
while exists(select name from sysobjects where type='f')
begin
 select top 1 @string='alter table '+b.name+' drop constraint '+a.name
  from (select parent_obj,name from sysobjects where type='f') a,
        (select id,name from sysobjects where objectproperty(id, n'isusertable') = 1) b
    where a.parent_obj=b.id
 exec(@string)
end

go

--primary key 約束
declare @string varchar(8000)
while exists(select name from sysobjects where xtype='pk')
begin
 select top 1 @string='alter table '+b.name+' drop constraint '+a.name
  from (select parent_obj,name from sysobjects where xtype='pk') a,
        (select id,name from sysobjects where objectproperty(id, n'isusertable') = 1) b
    where a.parent_obj=b.id
 exec(@string)
end

go

--觸發器
declare @string varchar(8000)
while exists(select name from sysobjects where xtype='tr')
begin
 select top 1 @string='drop trigger '+name from sysobjects where xtype='tr'
 exec(@string)
end

go

 

--索引
declare @string varchar(8000)
while exists(
 select table_name= o.name,index_name= x.name
  from sysobjects o, sysindexes x, syscolumns c, sysindexkeys xk
  where o.type in ('u')
  and convert(bit,(x.status & 0x800)/0x800)=0
  and x.id = o.id
  and o.id = c.id
  and o.id = xk.id
  and x.indid = xk.indid
  and c.colid = xk.colid
  and xk.keyno <= x.keycnt
  and permissions(o.id, c.name) <> 0
  and     (x.status&32) = 0  -- no hypothetical indexes
  group by o.name,x.name)
begin
select top 1 @string='drop index '+o.name+'.'+ x.name
  from sysobjects o, sysindexes x, syscolumns c, sysindexkeys xk
  where o.type in ('u')
  and convert(bit,(x.status & 0x800)/0x800)=0
  and x.id = o.id
  and o.id = c.id
  and o.id = xk.id
  and x.indid = xk.indid
  and c.colid = xk.colid
  and xk.keyno <= x.keycnt
  and permissions(o.id, c.name) <> 0
  and     (x.status&32) = 0  -- no hypothetical indexes
  group by o.name,x.name
exec(@string)
end

 

go

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 和政县| 甘南县| 颍上县| 灵璧县| 南昌市| 耒阳市| 静海县| 岳阳市| 鄂温| 庆阳市| 延津县| 仁布县| 阳城县| 军事| 大姚县| 望城县| 平山县| 永城市| 大宁县| 井研县| 综艺| 博爱县| 襄城县| 若尔盖县| 五河县| 左贡县| 黑水县| 江达县| 成都市| 宁化县| 婺源县| 沁阳市| 中阳县| 安乡县| 星子县| 天祝| 新邵县| 新龙县| 平南县| 康马县| 前郭尔|