Linked Questions
48 questions linked to/from How can I list all foreign keys referencing a given table in SQL Server?
2 votes
2 answers
4k views
Retrieve table relationships from MS Access DB using C#
I am using C# with MS Access 2010. I need to retrieve the table relationships from the DB in order to determine the relationships between entities and use them in my C# code. I need the same ...
2 votes
6 answers
486 views
Find what Foreign keys are in use
I have about 50 tables with created-by and changed-by referencing the user table. When I want to delete the user, I would like to create a list of what tables this user has data in, so one can go ...
0 votes
2 answers
4k views
How can I list all foreign keys in a Table?
Suppose, I know the name of a Table TableName1 in the Database Database1. I want to find: the foreign keys that table has. what foreign tables they are referencing. what foreign columns they are ...
3 votes
2 answers
745 views
Can I retrieve the impacted constraint(s) from a InvalidConstraintException?
Two days ago, I have asked this question on how to modify deletion rules of foreign key constraints at runtime. That question has been answered, but now I would like to generalise my program: ...
2 votes
3 answers
951 views
Different behavior in 2 SQL servers
I have a project that run some integration tests. The project creates a new database each time and run the tests against this new db. Recently I moved this project to a new server and I'm having some ...
2 votes
1 answer
2k views
How to find all the relations between all tables with INFORMATION_SCHEMA in SQL Server?
Is there a way to get all relations between all db tables by using INFORMATION_SCHEMA? I tried to use INFORMATION_SCHEMA.KEY_COLUMN_USAGE to get it, because it works with MySQL, but it doesn't have ...
3 votes
3 answers
556 views
SQL Server 2005: How to drop selected tables, with all related objects
There is a copy of a huge MS Sql Server 2005 database, with more than 1300 tables, plus hundreds of stored procedures and dozens of views, not counting jobs. It is used by several applications. I ...
0 votes
1 answer
879 views
Find the table column the foreign key is pointing at
I have a legacy Microsoft SQL Server database with many tables. I have a foreign key in table Order called CategoryID. I cannot find the table column the foreign key CategoryID is pointing to. I do ...
0 votes
3 answers
882 views
Get list of all columns with complete details (Identity, nullabel,primary key) in sql server without duplicate column
I have need to automate the process of database upgrade process. So by getting the column structure of a table i need to create update/insert/create sql statement's . BY problem was i am getting ...
1 vote
2 answers
237 views
Find all foreign key references to a certain table
I have a table that I would like to find all the other tables that foreign key it. I thought this thread had the answer: How can I list all foreign keys referencing a given table in SQL Server? But ...
1 vote
2 answers
848 views
Generic script for finding orphaned data in Microsoft SQL Server tables
I have a Microsoft SQL Server 2012 database with a huge amount of tables (>100). I have also many many-to-many relation tables. All PK/FK relationships are made in the tables so that i know in which ...
0 votes
1 answer
788 views
SqlException: How to drop constraint, delete table and reinstate constraint?
I've got a method that deletes all data in a table however this wont work if there is a foreign key constraint. How do I check if there any reference constraints exist, delete those entriesfirst and ...
1 vote
1 answer
513 views
How to list foreign key and its reference column in an existing SQL Server query
I am using the following query to list the table constraint(Primary Keys, Unique Keys, Default keys), however, I am having hard time in getting a list of foreign keys and its references (columns). ...
0 votes
2 answers
347 views
Visualize relationships between tables
I'm trying to accomplish the following: I have several tables, some of them containing primary keys from other tables. I tried to prepare a SQLFiddle for clarification, you can find it here http://...
0 votes
1 answer
565 views
How to identify Foreign Keys from sys tables in SQL Server?
I used the following query to return Primary Keys of two tables. Is there a similar way to query for the Foreign Keys? I am not familiar with creating DBs but I dont see any Foreign Keys defined in ...