sql server - Global temp tables with SQLCMD -


in ssms, can create global temp variable in 1 batch , use in another. this:

create table ##temp (col1 int) go  drop table ##temp go 

with sqlcmd, create global temp table in 1 call , not exist in second.

sqlcmd -s localhost -d tempdb -e -q "create table ##temp (col1 int)"  sqlcmd -s localhost -d tempdb -e -q "drop table ##temp" msg 3701, level 11, state 5, server vatllxt7lgbare2, line 1 cannot drop table '##temp', because not exist or not have permission. 

is global temp table not supposed stick around until server reset?

yes that's correct cause global temporary table exists in connection/session created , gets dropped automatically if connection closes. in case, first sqlcmd creates table

sqlcmd -s localhost -d tempdb -e -q "create table ##temp (col1 int)" 

and connection closes drops temporary table , in next connection doesn't exists anymore

sqlcmd -s localhost -d tempdb -e -q "drop table ##temp" 

Comments

Popular posts from this blog

Android : Making Listview full screen -

javascript - Parse JSON from the body of the POST -

javascript - Chrome Extension: Interacting with iframe embedded within popup -