Ms SQL Server has two types of local temporary tables and global temporary tables: local temporary tables are only visible in the current session, starting with a symbol # (such as # tablename ); the global temporary table is visible in all sessions and starts with a symbol # (for example, # tablename ).
SQL Server automatically adds a digital suffix to the table name of each local temporary table to distinguish temporary tables created by different users with the same name, the created temporary table will appear in the User table of the tempdb database, while the metadata is stored in the sysobjects table of the tempdb database (the name consists of the specified table name and the digital suffix generated by the system, the specified table name cannot exceed 116 characters ).
Ms SQL server automatically deletes the local temporary table when the user instance is disconnected and automatically deletes the global temporary table when all users that reference the global temporary table are disconnected.Of course, you can also explicitly call the drop TABLE statement to delete a temporary table. The statement to delete an existing temporary table is as follows:If object_id ('tempdb .. # tmp_tbl_name ') is not null drop table # tmp_tbl_name