564 attributed reviews in the last 3 years
Refreshingly small course sizes
Outstandingly good courseware
Whizzy online classrooms
Wise Owls only (no freelancers)
Almost no cancellations
We have genuine integrity
We invoice after training
Review 30+ years of Wise Owl
View our top 100 clients
Search our website
We also send out useful tips in a monthly email newsletter ...
Temporary Tables in SQL - a Training Blog Part two of a four-part series of blogs |
---|
If you want training in how to use temporary tables in SQL, read on! This blog shows how to create temporary tables and how to drop them safely whether or not they exist. Finally, the blog lists the pros and cons of using temporary tables in SQL.
This article is part of a complete SQL tutorial. Another way to learn SQL is to attend a Wise Owl SQL training course. |
You don't need to know where temporary tables are stored, but it's all good background! Consider this SQL:
USE MOVIES
GO
-- create a temporary table containing movies
CREATE TABLE #BestMoviesEver(
MovieId int IDENTITY(1,1) PRIMARY KEY,
MovieName varchar(50),
Rating int
)
-- add in 4 movies
INSERT INTO #BestMoviesEver (MovieName, Rating) VALUES (
'Watchmen', 9 )
INSERT INTO #BestMoviesEver (MovieName, Rating) VALUES (
'The Departed', 8 )
INSERT INTO #BestMoviesEver (MovieName, Rating) VALUES (
'The Matrix', 10 )
INSERT INTO #BestMoviesEver (MovieName, Rating) VALUES (
'The Sound of Music', 9 )
-- list them back out
SELECT * FROM #BestMoviesEver
Here's what you get when you run this:
When you show the records in the temporary table, this is what you get.
So where is the temporary table stored? The answer is in a system database called tempdb:
The temporary table just created. The full table name is over 100 characters long, since it contains a unique number attaching it to this particular user of SQL.
Knowing this fact helps us make sure that we can drop the temporary table before we try to recreate it, as shown in the next part of this blog.
Parts of this blog |
---|
|
Some other pages relevant to the above blogs include:
Kingsmoor House
Railway Street
GLOSSOP
SK13 2AA
Landmark Offices
99 Bishopsgate
LONDON
EC2M 3XD
Holiday Inn
25 Aytoun Street
MANCHESTER
M1 3AE
© Wise Owl Business Solutions Ltd 2023. All Rights Reserved.