Skip to content
Advertisement

How to find table name using primary key name in sql?

I have names of primary keys in a variable and I need to find the table to which they belong. The db has many table so linear search is not an option.

Advertisement

Answer

you can try this out ::

SELECT table_name 
FROM information_Schema.columns 
WHERE column_name='dept_id' 
  and ordinal_position = 1;
User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement