How to create a temporary table in SQL Server

When you are creating SQL scripts you will sometimes need to create a temporary file. This can be done in 2 different ways in SQL Server.

— The scope of this temporary table is only the SPID that created the Table.
CREATE TABLE #TableTemp
(
  tableName varchar(40),
  rowCount int
)

— This temporary table can be used by every SPID in the SQL Instance,
— until it is dropped or the server is restarted
CREATE TABLE ##TableTemp
(
  tableName varchar(40),
  rowCount int
)

Dette indlæg blev udgivet i SQL Server - scripts og tagget , . Bogmærk permalinket.