Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in SQL by (55.6k points)

Can anyone explain how to declare a variable in SQL?

1 Answer

0 votes
by (119k points)

In SQL, we can declare a variable using DECLARE statement. The following statement is used to declare a variable named @start_year:

DECLARE @start_year SMALLINT;

In above statement, SMALL INT is a datatype of @start_year variable.

If we want to assign the value, we can use the SET statement. Use the following statement to assign ‘2020’ value to the variable @start_year we have created:

SET @start_year = 2020;

If you wish to learn SQL from Industry experts, I recommend enrolling in this SQL Course by Intellipaat that provides instructor-led training, and also certification.  

Related questions

0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
asked Jul 5, 2019 in SQL by Tech4ever (20.3k points)

Browse Categories

...