Often times a DBA or BI developer needs to quickly create a view or select statement against a cryptic transactional table as part of an ETL or reporting requirement. The typical process involves selecting all columns from the base table, looking for foreign keys, finding the referenced tables, figuring out if outer join needed, adding tables to the FROM clause, etc. This is often a time consuming task, especially if foreign key columns are named differently from base table foreign key columns.
The attached script jump starts the process. SSMS has a nice context menu option to "Select top 1000 rows", this script does similar query, except it links to all the foreign key tables and retreives all the columns from them. It also adds joins, correctly adding LEFT OUTER when needed. The primary keys are indicated by adding a "_PK" to the column alias.
To use just set the @tab variable at the beginning of the script. The output is an XML document with View DDL. The view is essentially a denormalized version of the base table. This view can be used for basic reporting, ETL extraction, or creating a history table for volatile base tables. Hope you find it useful!