Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

New to Stored Procedures

Status
Not open for further replies.

Steve95

MIS
Nov 3, 2004
265
US
Hi All

Iam new to sql and stored procedures..please can someone tell me what the follwoing code does....

declare @rates table
(
exchange_rate decimal (18,6),
gbp_exchange_rate decimal (18,6),
final_exchange_rate decimal (18,6),
General_Purpose_Code_Name varchar(10),
original_currency char(4)
)

Also how do temporary tables work? Is an actual table created within a db?

Many Thanks in advance
 
This is NOT a temporary table. It is a table variable. In many ways, they work the same, but there are some considerable differences.

A table variable is completely contained within memory. A Temp Table is stored in the TempDB.

When the stored procedure is done running, the table variable goes away.

Table variables are usually faster than temp tables, but only testing both ways will tell you for sure.

-George

Strong and bitter words indicate a weak cause. - Fortune cookie wisdom
 
Also because table variables are stored in memory not on disk, it is recommended that you only use them when you need to load up less than a couple of thousand rows. Anything over that should be done in a temp table otherwise you will be using to much memory.

With a table variable you can't load the output from a stored procedure in to it.

With a table variable you also can not created indexes to increase performance while you can with temp tables.

With a temp table you can created it, then run a stored procedure and have the stored procedure access the temp table. You can not do this with a table variable.

Denny
MCSA (2003) / MCDBA (SQL 2000)
MCTS (SQL 2005 / Microsoft Windows SharePoint Services 3.0: Configuration / Microsoft Office SharePoint Server 2007: Configuration)
MCITP Database Administrator (SQL 2005) / Database Developer (SQL 2005)

--Anything is possible. All it takes is a little research. (Me)
[noevil]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top