I am querying the system views to obtain all the Foreign Keys (name, columns, parent name, parent columns, etc)for a table. Some tables have more than 1 FK so I need to rank them in order:Here is the query:SELECT FKcols.TABLE_NAME, FKcols.CONSTRAINT_NAMEFROM INFORMATION_SCHEMA.REFERENTIAL_CONSTRAINTS fks INNER JOIN INFORMATION_SCHEMA.KEY_COLUMN_USAGE FKcols ON FKcols.CONSTRAINT_NAME = fks.CONSTRAINT_NAMEINNER JOIN INFORMATION_SCHEMA.TABLE_CONSTRAINTS pks ON pks.CONSTRAINT_NAME = fks.UNIQUE_CONSTRAINT_NAMEINNER JOIN INFORMATION_SCHEMA.KEY_COLUMN_USAGE PKcols ON PKcols.CONSTRAINT_NAME = pks.CONSTRAINT_NAME AND FKcols.ORDINAL_POSITION = PKcols.ORDINAL_POSITION
Here is the result set that I want (so each FK constraint is assigned a different number only for each table):1 Item FK_Item_Header1 Item FK_Item_Header1 ItemDiscount FK_ItemDiscount_Header1 ItemDiscount FK_ItemDiscount_Header2 ItemDiscount FK_ItemDiscount_Item1 Tender FK_Tender_Header1 Tender FK_Tender_Header
Also, does anyone know of any good material that explains the ROW_NUMBER function to someone that does not have a mathematical background - i.e. so that a child could understand...)ThanksHearty head pats