LOCAL TEMPORARY TABLE in SQL Server
This tutorial explains how to use LOCAL TEMPORARY TABLE in SQL Server with syntax and examples.
The local temporary table LOCAL TEMPORARY TABLE is stored in tempdb and SQL Server will automatically delete the table when it is no longer used.
Syntax
CREATE TABLE #ten_bang
(
cot1 kieudulieu [ NULL | NOT NULL ],
cot2 kieudulieu [ NULL | NOT NULL ],
…
);
Variable name or variable value
ten_bang
The name of the local temp table wants to be created, starting with the # character.
cot1, cot2
The column you want to create in the table. Each column has 1 data type, must be specified to contain NULL or NOT NULL values, otherwise default is NULL.
Data types in SQL Server
Note
The local temp table LOCAL TEMPORARY TABLE has a prefix of # (for example, need #nhanvien).
For example
CREATE TABLE #nhanvien
( id_nhanvien INT PRIMARY KEY,
ho (VARCHAR(50) NOT NULL,
ten (VARCHAR(50),
luong MONEY,
);
For example, the CREATE TABLE command will create a local temporary table named #nhanvien with 4 columns:
- nhanvien, INT data type, does not contain NULL value.
- cough, VARCHAR data type (maximum length of 50 characters) and contains no NULL value.
- ten, VARCHAR data type, can contain NULL values.
- , MONEY data type, can contain NULL values.
- Primary key PRIMARY KEY for table ## nhanvien is id_nhanvien.
The # table is stored in tempdb and SQL Server will be automatically deleted when the SQL Server session is no longer needed.
Previous post: GLOBAL TEMPORARY TABLE in SQL Server
The following article: Foreign Key foreign key in SQL Server
You should read it
- ALIAS in SQL Server
- How to set up a local web server (Local Web Server) on Windows, macOS, and Linux
- CREATE TABLE command in SQL Server
- Segment tables in SQL Server
- DROP TABLE command in SQL Server
- PIVOT clause in SQL Server
- ALTER TABLE statement in SQL Server
- The difference between web server and app server
May be interested
- The TRUNCATE TABLE command in SQL Serverthe truncate table statement is used to delete all records from a table in sql server.
- ALTER TABLE statement in SQL Serverin sql server, the alter table statement is used to add columns, edit columns, delete columns, rename columns or rename tables.
- Install frames and temporary images on Facebookwith a temporary avatar feature on facebook, you no longer have to remember to change your avatar after holiday or anniversary instead, it will automatically do it for you.
- PIVOT clause in SQL Serverin sql server (transact-sql), the pivot clause allows cross tabulation to pass data from one table to another.
- CLONE TABLE in SQLthis article will show you in detail how to use clone table in sql with a specific example to make it easier to visualize and capture.
- What is Temporary File? How to delete temporary files on windows computerswhen you use the software, some temporary files are created and not deleted, filling up memory for a long time. here's how to delete temporary files on a windows computer.
- 9 pros and cons of using a local LLMsince chatgpt emerged in november 2022, the term large language model (llm) has quickly moved from a term reserved for ai enthusiasts to a buzzword on everyone's lips.
- How to make a Raspberry Pi a web servertoday's article will show you how to turn a raspberry pi into a personal web server. at the end of this tutorial, you will learn how to install the apache web server on the raspberry pi, set up php and create a simple website to access over the local network.
- INSERT statement in SQL Serverthe insert statement in sql server (transact-sql) is used to insert one or more records into a table.
- 35 tools, scripts and plugins to build HTML Tablethere are many ways to visualize data, ie you can design a beautiful infographics or create interactive charts. it all depends on your data and how you want to present them.