DEV Community

Discussion on: Comparing SQL Views and Stored Procedures

Collapse
 
sqlknowitall profile image
Jared Karney • Edited

Great comparison! It's important to note that nesting views (referencing a view within a view) will almost certainly cause performance issues. I would also note that views are best used to obfuscate data from a source table when other data in that table is needed. Think of a report writer who needs access to employee name and title, but shouldn't have access to ssn or salary. You can create a view with only the columns you need and grant access to the view. In general, I wouldn't recommend using views simply for commonly joined tables. Developers should always write out all of their code or risk unintended changes to the view or nesting of views, IMHO. I would only recommend using views to obfuscate data or to present a simplified version of a query to a report writer who isn't privy to the schema of the database or particularly proficient in SQL.