In Microsoft SQL, if I want to get information about where a column with a certain column name appears in my database, I can run this query:
select * from information_schema.columns where column_name = 'XXXXX';
This query returns a wealth of information about the instances where a column with the name appears, but I don't see anything about referential constraints.
I've tried some other queries below, but none seem to yield the information I want:
select * from INFORMATION_SCHEMA.REFERENTIAL_CONSTRAINTS
select * from INFORMATION_SCHEMA.TABLE_CONSTRAINTS
select * from INFORMATION_SCHEMA.CONSTRAINT_COLUMN_USAGE
I want to write a query that would do something like this:
select table_schema, table_name from INFORMATION_SCHEMA.COLUMNS
where column_name = 'XXXXX' and IsPrimaryKey = 1;
Edit: It was suggested that this question duplicates a question about finding the primary key of a given table. This question is related, but different because I am starting out knowing the name of a column (which may occur in many tables) and I want to be able to tell if there is a table with a primary key column with the same name.