易截截图软件、单文件、免安装、纯绿色、仅160KB

求SQL 脚本 - MS-SQL Server / 疑难问题

有没有一次性删除一个数据库中所有表的 

PK, FK, UK 的脚本阿

我想要达到的是:

一次性删除所有 PK, FK, UK, Index

然后

一次性重建

大家有什么建议吗?
SQL code:
--批量清除表内容:

--1.禁用外键约束
DECLARE c1 cursor for
select 'alter table ['+ object_name(parent_obj) + '] nocheck 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
end
close c1
deallocate c1
--2.清除表内容
DECLARE c2 cursor for
select 'truncate table ['+name +']; '
from sysobjects
where xtype = 'u'
open c2
declare @c2 varchar(8000)
fetch next from c2 into @c2
while(@@fetch_status=0)
begin
exec(@c2)
fetch next from c2 into @c2
end
close c2
deallocate c2
--3.启用外键约束
DECLARE c1 cursor for
select 'alter table ['+ object_name(parent_obj) + '] check 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
end
close c1
deallocate c1



本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/htl258/ar


相关问答:

jsp链接sql2000的疑问?



type Exception report


message

description The server encountered an internal error () that prevented it from fulfilling this request.

exception

org.apache.jas ......

ASP链接SQL的简单登陆界面 - .NET技术 / ASP.NET

protected void btnLogin_Click(object sender, EventArgs e)
  {
  SqlConnection conn = new SqlConnection("Server = (local);user id = sa;pwd = 1;database = Login");
&nb ......

求一个SQL语句 - MS-SQL Server / 基础类

字段1,字段2.....字段N,Status,ParentID
1,Name1....test1,1,99
1,Name1....test1,3,99
1,Name2....test2,1,101
1,Name2....test2,3,101
1,Name3....test3,2,101
1,Name1....test1,4,101
想要的结果是:
1,Na ......

两句SQL并一句,有问题. - MS-SQL Server / 基础类

第一句:
select ht.gfdm,gfdm.gfmc,gfdm.lb ,sum(jh.htdj*jh.htsl)as je
from ht left join gfdm on ht.gfdm=gfdm.gfdm 
 join jh on ht.htbh=jh.hth 
and ht.htbh not like'del%' and ht. ......

求一SQL写法 - MS-SQL Server / 基础类

id                           url                   rank     ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号