Hello friends, In this article, we will learn different ways to create different types of table in Sql Server with in just 5 minutes.
Step 1: Sql Server User Session based Temporary Table #tbStudent.
Sessional temporary table should always begins with #
CREATE TABLE #tbStudent
(
ID INT IDENTITY(1,1) PRIMARY KEY,
StudentName NVARCHAR(200),
CLASSID INT,
ROLLNO NVARCHAR(20)
)
Go
SELECT * FROM #tbStudent
Go
Step 2: Sql Server Global Temporary Table ##tbStudent. Global temporary table should always begins with ##.
Global temporary table will be available for all sessions for a particular user.
CREATE TABLE ##tbStudent
(
ID INT IDENTITY(1,1) PRIMARY KEY,
StudentName NVARCHAR(200),
CLASSID INT,
ROLLNO NVARCHAR(20)
)
Go
SELECT * FROM ##tbStudent
Go
Step 3: Sql Server permanent Table tbStudent.
CREATE TABLE tbStudent
(
ID INT IDENTITY(1,1) PRIMARY KEY,
StudentName NVARCHAR(200),
CLASSID INT,
ROLLNO NVARCHAR(20)
)
Go
SELECT * FROM tbStudent
Go
Step 4: Sql Server Table Variable
DECLARE @tbStudent TABLE
(
ID INT IDENTITY(1,1) PRIMARY KEY,
StudentName NVARCHAR(200),
CLASSID INT,
ROLLNO NVARCHAR(20)
)
SELECT * FROM @tbStudent
Go
Step 5: Create Sql Server Table from another existing table without data.
SELECT * INTO ##tbStudentDup FROM
(SELECT TOP 0 * FROM ##tbStudent) AS A
GO
SELECT * FROM ##tbStudentDup
Go
Step 6: Create Sql Server Table from another existing table with data.
SELECT * INTO ##tbStudentDup FROM
(SELECT * FROM ##tbStudent) AS A
GO
SELECT * FROM ##tbStudentDup
Go
If you have any query or question or topic on which, we might have to write an article for your interest or any kind of suggestion regarding this post, Just feel free to write us, by hit add comment button below or contact via Contact Us form.
Your feedback and suggestions will be highly appreciated. Also try to leave comments from your valid verified email account, so that we can respond you quickly.