惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

SecWiki News
SecWiki News
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
V
Visual Studio Blog
博客园 - 叶小钗
S
SegmentFault 最新的问题
IT之家
IT之家
大猫的无限游戏
大猫的无限游戏
博客园_首页
Apple Machine Learning Research
Apple Machine Learning Research
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
月光博客
月光博客
酷 壳 – CoolShell
酷 壳 – CoolShell
腾讯CDC
D
Darknet – Hacking Tools, Hacker News & Cyber Security
V
V2EX
阮一峰的网络日志
阮一峰的网络日志
L
Lohrmann on Cybersecurity
量子位
C
Cyber Attacks, Cyber Crime and Cyber Security
T
Tor Project blog
J
Java Code Geeks
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
博客园 - 三生石上(FineUI控件)
Attack and Defense Labs
Attack and Defense Labs
AI
AI
The Cloudflare Blog
T
Tailwind CSS Blog
S
Schneier on Security
爱范儿
爱范儿
PCI Perspectives
PCI Perspectives
Stack Overflow Blog
Stack Overflow Blog
S
Secure Thoughts
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
T
The Exploit Database - CXSecurity.com
博客园 - 【当耐特】
V2EX - 技术
V2EX - 技术
S
Securelist
P
Proofpoint News Feed
T
Threat Research - Cisco Blogs
Help Net Security
Help Net Security
C
Cisco Blogs
N
News and Events Feed by Topic
人人都是产品经理
人人都是产品经理
B
Blog RSS Feed
K
Kaspersky official blog
T
The Blog of Author Tim Ferriss
G
Google Developers Blog
S
Security Affairs
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
Simon Willison's Weblog
Simon Willison's Weblog

博客园 - 空空儿

硬盘分区、寻址和系统启动过程 JavaScript里String.Format方法的实现 asp.net异步页 获取SQL Server数据行的物理地址信息(%%lockress%% & %%physloc%%) 利用Spire.DataExport将数据(Database/DataTable)导成各种文件 使用XML的value()方法将多行数据合并成一列 ASP.NET application and page life cycle SQL Server 2005 CLR 调用Web Service需要注意的几个问题 SQL SERVRE 2005 CLR TVF错误:从用户定义的表值函数获取新行时出错:Data access is not allowed in this context. PHP执行MYSQL存储过程报错:Commands out of sync; you can't run this command now 在C#里使用属性 - 空空儿 - 博客园 Read text file (txt, csv, log, tab, fixed length) 批量写数据---将XML数据批量写入数据库 对对象类型和调用方法属性进行存储以提升反射性能 过程 sp_addlinkedsrvlogin,第 91 行解密过程中出错的解决办法 生成大量随机字符串不同实现方式的效率对比 用SQL SERVER 2005新提供的命令实现行列转换 APM (异步编程模型) 利用宏让ERStudio生成代码文件
获取所有的外键信息
空空儿 · 2011-03-03 · via 博客园 - 空空儿

通过查询系统表,可以得到一个数据库里的所有外键信息,得到这些信息后就可以生成一些脚本,比如删除某张表的所有外键,根据现有外键信息生成新的外键.

    select fk.name fkname,constable.name constablename,conscol.name conscolname,reftable.name reftablename,refcol.name refcolname
        
from sys.foreign_keys fk
        
join sys.objects constable on fk.parent_object_id=constable.object_id
        
join sys.objects reftable on fk.referenced_object_id=reftable.object_id
        
join sys.foreign_key_columns fkc on fkc.constraint_object_id=fk.object_id 
        
join sys.columns conscol on fkc.parent_column_id =conscol.column_id and fkc.parent_object_id=conscol.object_id
        
join sys.columns refcol on fkc.referenced_column_id=refcol.column_id and fkc.referenced_object_id=refcol.object_id

以上查询得到外键名称,外键基表,外键列,外键引用表,外键引用列.

以下语句删除数据库db里关于tblname的外键:

use db
godeclare @references_name nvarchar(100),
        
@table_name nvarchar(100)declare cursor_references cursor for
    
select fk.name fkname,constable.name constable from sys.foreign_keys fk
        
join sys.objects constable on fk.parent_object_id=constable.object_id
        
join sys.objects reftable on fk.referenced_object_id=reftable.object_id
        
join sys.foreign_key_columns fkc on fkc.constraint_object_id=fk.object_id 
        
join sys.columns conscol on fkc.parent_column_id =conscol.column_id and fkc.parent_object_id=conscol.object_id
        
join sys.columns refcol on fkc.referenced_column_id=refcol.column_id and fkc.referenced_object_id=refcol.object_id
        
where reftable.name='tblname'
open cursor_references
fetch next from cursor_references into @references_name,@table_name
while @@fetch_status = 0
begin
    
exec('alter table '+@table_name+' drop constraint '+@references_name)
    
fetch next from cursor_references into @references_name,@table_name
end
close cursor_references
deallocate cursor_references