Table variable in SQL Server

Let's have a preview of this amazing thing that is the Table variable in SQL Server.

Basic syntax

DECLARE @DevExperts TABLE
(Id INT PRIMARY KEY IDENTITY(1,1),
Name VARCHAR(MAX),
Country VARCHAR(MAX))

The column Id is defined to be the primary key and to iterate automatically.

Basic insert

INSERT INTO @DevExperts VALUES 
('Ada Lovelace', 'Uk'),
('Evelyn Boyd Granville', 'US'),
('Carol Shaw', 'US'),
('Adi Polak', 'global'),
('Trisha Gee', 'Spain'),
('Mala Gupta', 'India')

SELECT * FROM @DevExperts

The output is
capture.png

H2
H3
H4
3 columns
2 columns
1 column
Join the conversation now
Logo
Center