10774 - temporary tables or type table variables

Hi Experts

It is best temporary tables or type table variables
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

ste5anSenior DeveloperCommented:
Well, it depends on the use case...

Just a thought to your questions: Wouldn't you as Microsoft remove those possibilites, when they were always bad?
Éric MoreauSenior .Net ConsultantCommented:
They have different features for different needs.

If your have just a few rows (couple of thousands) and only need a one field primary key, the table variables are a better choice.

Most of other needs are better deserved by temp tables.
enrique_aeoAuthor Commented:
thanks experts

can you give me an example in T-SQL code
Big Business Goals? Which KPIs Will Help You

The most successful MSPs rely on metrics – known as key performance indicators (KPIs) – for making informed decisions that help their businesses thrive, rather than just survive. This eBook provides an overview of the most important KPIs used by top MSPs.

Éric MoreauSenior .Net ConsultantCommented:
an example of what?

The easiest is probably:
INSERT INTO @T VALUES(1),(2),(3),(4),(5)

INSERT INTO #T VALUES(1),(2),(3),(4),(5)



Open in new window

Duy PhamFreelance IT ConsultantCommented:
Dmitry Tsuranoff has made a quite detailed comparison.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Éric MoreauSenior .Net ConsultantCommented:
Jim, have you gone through the link? It was very exhaustive. And copying it here would be a simply plagiarism. I just don't understand that rule when the links is for a good reason.
Duy PhamFreelance IT ConsultantCommented:
@Éric:  Really sorry about that. I should have known about it before posting such a 'blind link', but I will surely and carefully read through the Terms of EE again to avoid that in the future.

I just thought that link did provide kinda good comparsion in details (not well structured though), and gave it as just a reference to Jim with no intension at all.
Duy PhamFreelance IT ConsultantCommented:
@Jim:  I do understand the EE's concern about blink link, and to be honest I couldn't agree with EE more on that.

At the time I saw the Enrique's question, my first thought was 'Hey, this guy is asking exactly the same question we did jump into when optimizing our queries few years ago. I can just gave him the helpful link we got before.'. That's it.

Anyway, thanks for guiding me. Is anything I should do to keep this thread from being 'dead' in the future in case the link disappear?
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft SQL Server

From novice to tech pro — start learning today.