How can I list all foreign keys referencing a given table in SQL Server?
How can I list all foreign keys referencing a given table in SQL Server?
Not sure why no one suggested but I use sp_fkeys
to query foreign keys for a given table:
EXEC sp_fkeys 'TableName'
You can also specify the schema:
EXEC sp_fkeys @pktable_name = 'TableName', @pktable_owner = 'dbo'
Without specifying the schema, the docs state the following:
If pktable_owner is not specified, the default table visibility rules of the underlying DBMS apply.
In SQL Server, if the current user owns a table with the specified name, that table's columns are returned. If pktable_owner is not specified and the current user does not own a table with the specified pktable_name, the procedure looks for a table with the specified pktable_name owned by the database owner. If one exists, that table's columns are returned.
测试了一下,还是很给力的。直接给出一张表A,会直接找到那些用了这张表A的字段作为外键 的其他表。
How can I list all foreign keys referencing a given table in SQL Server?的更多相关文章
- [转]How can I list all foreign keys referencing a given table in SQL Server?
本文转自:https://stackoverflow.com/questions/483193/how-can-i-list-all-foreign-keys-referencing-a-given- ...
- [PostgreSQL] Use Foreign Keys to Ensure Data Integrity in Postgres
Every movie needs a director and every rented movie needs to exist in the store. How do we make sure ...
- ORA-02266: unique/primary keys in table referenced by enabled foreign keys
在数据库里面使用TRUNCATE命令截断一个表的数据时,遇到如下错误 SQL >TRUNCATE TABLE ESCMOWNER.SUBX_ITEM ORA-02266: unique/prim ...
- ORA-02273: this unique/primary key is referenced by some foreign keys
关于ORA-02273错误,以前还真没有仔细留意过.昨天遇到了这个问题,遂顺便总结一番,以后遇到这类问题就可以直接用下面方案解决.如下所示,我们首先准备一下测试环境. CREATE TABLE TES ...
- 外键 Foreign keys
https://docs.microsoft.com/en-us/sql/relational-databases/tables/create-foreign-key-relationships?vi ...
- sql server create foreign key
in table design view(right click table and choose design), right click on a column, and select 'rela ...
- Sql Server 2008R2版本中有关外键Foreign的使用
原文:Sql Server 2008R2版本中有关外键Foreign的使用 1. 在数据库设计的过程中往往会想让2张表进行关联而使用到Foreign从而加强2张表之间的约束(如图) 以前有个问题一直没 ...
- How do I see all foreign keys to a table or column?
down voteaccepted For a Table: SELECT TABLE_NAME,COLUMN_NAME,CONSTRAINT_NAME, REFERENCED_TABLE_NAME, ...
- SQL Server 2008 R2——TRUNCATE TABLE 无法截断表 该表正由 FOREIGN KEY 约束引用
=================================版权声明================================= 版权声明:原创文章 禁止转载 请通过右侧公告中的“联系邮 ...
随机推荐
- RHEL6 Systemtap 安装笔记
以 RHEL6u3 为例 1 Systemtap 安装 yum install systemtap 跟systemtap有关的有6,7个,全装上,别偷懒 就用yum安装,别傻傻的去下rpm包,吃力不 ...
- 【python-opencv】18-图像梯度+图像边界
效果图: *一阶导数与Soble算子 *二阶导数与拉普拉斯算子 定义:把图片想象成连续函数,因为边缘部分的像素值是与旁边像素明显有区别的,所以对图片局部求极值,就可以得到整幅图片的边缘信息了. 不过图 ...
- html+css小总结
html+css小总结 1.块级元素 <div> <h1> <hr /> <p> <pre> <ol> <ul> & ...
- android加载gif图片
Android加载GIF图片的两种方式 方式一:使用第三开源框架直接在布局文件中加载gif 1.在工程的build.gradle中添加如下 buildscript { repositories { m ...
- 007-Redi-命令-脚本命令、链接命令、服务器命令、事务、HyperLogLog
Redis 脚本命令 下表列出了 redis 脚本常用命令: 序号 命令及描述 1 EVAL script numkeys key [key ...] arg [arg ...] 执行 Lua 脚本. ...
- jmeter 正则表达式提取器的使用(提取第一个匹配结果)
原文地址https://www.cnblogs.com/xueli/p/7405258.html?utm_source=itdadao&utm_medium=referral 正则表达式的用处 ...
- Selenium Webdriver——操作隐藏的元素(二)display属性
有时候我们会碰到一些元素不可见,这个时候selenium就无法对这些元素进行操作了.例如,下面的情况: 页面主要通过“display:none”来控制整个下拉框不可见.这个时候如果直接操作这个下拉框, ...
- unity3d-Visual Studio Tools for Unity快捷键
1.首先 当安装for unity 后,打开vs2013(我使用的是vs2013),右键可以看到for unity 提供了两个快捷键 2.其次 (Ctrl+Shift+M) 3.最后(Ctrl+Shi ...
- MySQL创建数据表并建立主外键关系
为mysql数据表建立主外键需要注意以下几点: 需要建立主外键关系的两个表的存储引擎必须是InnoDB. 外键列和参照列必须具有相似的数据类型,即可以隐式转换的数据类型. 外键列和参照列必须创建索引, ...
- linux中的查找命令
which命令:使用which命令可以看到某个系统命令是否存在,以及执行的到底是哪一个位置上的命令.在PATH指定的路径中进行搜索, 返回第一个搜索结果. which grep /bin/grep ...