Snowflake Vs MS-SQL - Part 3
Temporary Tables
MS-SQL Server
When you create temporary table, you can NOT create with same name as that of main table. In SQL, you have to use # or ## to create temporary table.
Consider you have a table "Main_Table" under DEV schema say with 1000 records and if you create temporary table without records then temporary table gets created.
When you fire a select query as below, it returns zero records. This means it pulls the records from newly created temporary table and not from the main table.
If you create a view on this newly created temp table and fire select statement on the view then you get zero records.
If you move to different session/worksheet and fire select statement on view then you get actual count of the table. Because temporary table's scope is for a particular session.
And finally, when you drop this table, temporary table gets deleted, while actual Main_Table still exists.
Yogesh Shinde
Comments
Post a Comment