I have a large SQL database where I need to check the structure of tables and columns (and not the data itself). Therefore, I need to create a list of all tables, then for each table, all its columns, then for each column, its data type, length / precision, ordinal position and whether it is part of the primary key for this table.
I can get most of what I need with the following query:
SELECT TABLE_NAME, ORDINAL_POSITION, COLUMN_NAME, DATA_TYPE, CHARACTER_MAXIMUM_LENGTH, NUMERIC_PRECISION, NUMERIC_SCALE FROM INFORMATION_SCHEMA.COLUMNS
However, I'm not sure how to check if a column is part of the primary key. In addition, for those tables where PK consists of more than one column, I want to know the ordinal position of each column in the key. The information I have found so far is about installing the key, not reading it.
I am interested in doing this in both SQL Server and Oracle.
source share