is it possible to declare a variable in tsql without defining columns explicitly ?
Something like
declare @tab as select * from myTable
is it possible to declare a variable in tsql without defining columns explicitly ?
Something like
declare @tab as select * from myTable
You can select into a temp table ... which looks like it will do what you're after.
select *
into #myTempTable
from myTable
You must define columns when declaring a table varaible. If you want to do something like that you may need to revisit your design. If you want to create a proc that does anything to any table, that is a bad idea in SQL. Databases operate best when not designed generically and you should not be trying ito generalize queries.
And you should not be using select * for any production query anyway as it is a SQL Antipattern.