I’m just reading this sample from the Dapper “manual”:
connection.Execute(@"
set nocount on
create table #t(i int)
set nocount off
insert #t
select @a a union all select @b
set nocount on
drop table #t", new {a=1, b=2 })
.IsEqualTo(2);
Are the #t’s a special syntax for something? Or are they just there to confuse me? 🙂
Yes,
#means something important in TSQL – a table namedfoois permenant, for that db/schema. A table named#foois a temporary table – it only exists for that connection, and is removed when the connection is closed or reset. A table named##foois a global temporary table, and exists everywhere, but is intended to be temporary. This is mainly used when bulk-shifting data.The use of
#there is so that the table only exists on that connection, so we can re-run the test trivially.Also, a table named
@foois either a table-variable, or a table-valued-parameter, and only exists for that command / sproc.