I'm building a report from a series of known tables and their primary keys, e.g.:
BOOKS.bookid
AUTHORS.authorid
GENRE.genreid
What I would like to do is build a t-sql report that simply shows the table, the primary key, and the next available PK, e.g.:
**tabl_name prim_key avail_key**
BOOKS BOOKID 281
AUTHORS AUTHORID 29
GENRE GENREID 18
I already have the table name and its PK by using the information_schema, but somehow joining that with the actual table to derive its next available PK is proving elusive. I'm guessing there's some sort of dynamic sql with cursors solution, but that's maxing my sql skills out.