Tuesday, 30 September 2014

Example of temporary table and Table variable in Sql server for beginners.

---Table variable Example-----


declare @tablevar table(id int,vichelid varchar(100))
insert into @tablevar  select ID,vichelid from Tab_20130926
select * from @tablevar


---Temprory table-----------------------------------------------------------


create table #temptable(id int,vichelid varchar(100))
insert into #temptable select ID,vichelid from Tab_20130926
select * from #temptable
drop table #temptable


Also refer this Link for better understanding...Here you can see the advantage and disadvantage and scop of Table variable and temporary table.
http://www.codeproject.com/Articles/42553/Quick-Overview-Temporary-Tables-in-SQL-Server-2005

http://stackoverflow.com/questions/2742511/temporary-tables-in-sql-server
http://www.sqlservercentral.com/articles/T-SQL/temptablesinsqlserver/1279/
http://databases.aspfaq.com/database/should-i-use-a-temp-table-or-a-table-variable.html

No comments:

Post a Comment