Good morning, the question arose in uploading data from the database, but how much my knowledge level tells me that # cannot be used in the name, and when executing the query in MS SQL SM Stodio does not create errors, but does not create a new table either

This script was previous DBA

if OBJECT_ID('tempdb..#tmp_houses') IS NOT NULL DROP TABLE #tmp_houses; if OBJECT_ID('tempdb..#tmp_plats') IS NOT NULL DROP TABLE #tmp_plats; CREATE TABLE #tmp_houses ( fh_id int, fias VARCHAR(500), mo_caption VARCHAR(255), city_name VARCHAR(255), ul_name VARCHAR(255), d_name VARCHAR(255), d numeric(13, 0), opl numeric(18, 2), plat numeric(18, 2), area_total numeric(18, 2), area_live numeric(18, 2), area_non_live numeric(18, 2), ss_type VARCHAR(255), ss_date date ) 
  • # used to name temporary tables. If you work in SSMS, then when creating such a table in the list of database tables, it will not be visible. However, the table will be created and its lifetime will be limited to your connection session, its scope will also be limited to your session. - teran

1 answer 1

This is a local temporary table that is available only in the script (or procedure) in which it is called. If the script is launched at the same time several times, then for each script its own table will be created and the data between them will not intersect. At the end of the script the table will be deleted.

  • 2
    Exactly only in the script, and not in the entire current session / session? - teran
  • Most likely only in the script, but I have not worked with mssql for three years, I can make a mess of it, check it and make sure. - heff
  • I do not need to check, I already know what the session. write you to be puzzled by this question. - teran
  • except when a temporary table is created in storage. then it is deleted upon completion of this teran - teran