Pivot tables and views in a database