Temporary Tables Versus Views

Now that you have learned what temporary tables and views are and how to create them, it is up to you to decide which is better to use and when. Remember that a view does not actually store any more or duplicate data in the database. However, whenever a view is accessed, the SELECT statement contained in the view is executed and the current data is returned.

In contrast, when a temporary table is created, it contains a duplicate of the data you are working with. If the underlying tables are changed, the data in the temporary table will not reflect these changes unless you drop and re-create it.

Get Sams Teach Yourself Transact-SQL in 21 Days, Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.