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 named foo
is permenant, for that db/schema. A table named #foo
is a temporary table - it only exists for that connection, and is removed when the connection is closed or reset. A table named ##foo
is a global temporary table, and exists everywhere, but is intended to be temporary. This is mainly used when bulk-shifting data.
The use of #t
here is so that the table only exists on that connection, so we can re-run the test trivially.
Also, a table named @foo
is either a table-variable, or a table-valued-parameter, and only exists for that command / sproc.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With