Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Get the List of all tables using foreign key

    • 0
    • 2
    • 1
    • 1
    • 0
    • 0
    • 0
    • 0
    • 226
    Comment on it

    Hello All,

    Many time, We want to know that, What are all the tables who have referenced a column as a "foreign key" which is a "Primary Key" of other table.

    Example:-- In a database I have one Company table which stores company information with CompanyId as a primary key. We wants to list all the tables which are using "CompanyId" as a foreign key.

    Solution:----

    SELECT * FROM sys.foreign_keys WHERE type='F' AND OBJECT_NAME(referenced_object_id)='Company'
    EXEC sp_fkeys 'Company'

    Above SQL statement will provide you the desired output.

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: