SQL 2000:获取表的外键关系的 T-SQL
与 SQL Server 2000 - 查询表的外键类似但不相同关系
我需要一个T-SQL语句,该语句将在给定表名的SQL 2000中工作,将返回该表的外键关系,例如
表MyFristTable有一个到MySecondTable的外键,其中MyFirstTable.ColA必须在MySecondTable中.ColB. 如果为 MyFirstTable 运行 sql 语句(或存储过程)并返回 NB 行的结果集,我会很高兴
Column | FK_Table | FK_COLUMN
----------------------------------
ColA | MySecondTable | ColB
:我有 SQL 2005 的示例,但它们不起作用,因为它们依赖 sys.foreign_key_columns
我宁愿不必解析 sp_help 语句的结果。
谢谢,
Similar but NOT IDENTICAL to SQL Server 2000 - Query a Table’s Foreign Key relationships
I need a T-SQL statement that will work SQL 2000 that given a table name, will return the foreign key relationships for that table e.g.
Table MyFristTable has a foreign key to MySecondTable, where MyFirstTable.ColA must be in MySecondTable.ColB. I'd be delighted, if the sql statement (or stored proc) is ran for MyFirstTable and returned a result set on the lines of
Column | FK_Table | FK_COLUMN
----------------------------------
ColA | MySecondTable | ColB
NB: I have samples for SQL 2005 that won't work because they rely on sys.foreign_key_columns
I'd rather not have to parse out the results of the sp_help statement.
Thanks,
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我必须为查询做同样的事情,在尝试了一个与 sys 表非常相似的版本后,我发现了这个存储过程:
看起来这可以在 SQL Server 2000。
另外,我发现在某些情况下,此存储过程和此处的查询之间存在细微差别。 我猜 sp_fkeys 是规范版本。
I had to do this exact thing for a query, and I found this stored procedure, after trying a version much like the sys table one:
It looks like this is available in SQL Server 2000.
Also, I found that in a few cases there were minor differences between this stored proc and the queries here. I'm guessing sp_fkeys is the canonical version.
注意 我认为只使用了 SQL 2000 中可用的系统视图(即 sysXXX 视图而不是 SQL 2005 sys.XXX 视图),但我实际上只在 SQL 2005 环境中对此进行了测试。
NOTE I have I think used only those system views available in SQL 2000 (ie the sysXXX ones rather than the SQL 2005 sys.XXX ones) but I have only actually tested this in a SQL 2005 environemnt.
我曾经需要这样的东西,所以我只是查看系统存储过程的源代码,然后将我需要的内容复制到我自己的过程中,并使其按我需要的方式工作。
您可以查看 sp_helpconstraint 的源代码...
I needed something like this once, so I just looked at the source code of the system stored procedure and copied what I needed into my own procedure and made it work as I needed.
You might look at sp_helpconstraint's source code...
我在谷歌中发现了这个......所以如果这项工作不是我的优点。 希望有帮助
I found this in google... so if this work is not my merit. Hope it help