declare variable sql server code example
Example 1: sql declare variable
DECLARE @MyCounter int;
SET @MyCounter = 0;
Example 2: declare table variable sql server
DECLARE @table_variable_name TABLE (
column_list
);
Example:
DECLARE @product_table TABLE (
product_name VARCHAR(MAX) NOT NULL,
brand_id INT NOT NULL,
list_price DEC(11,2) NOT NULL
);
Example 3: how to declare a variable in sql
DECLARE @COURSE_ID AS INT, @COURSE_NAME VARCHAR (10);
Example 4: local variables in sql
Local variables:
These variables can be used or exist
only inside the function. These variables
are not used or referred by any other function.
Global variables:
These variables are the variables which
can be accessed throughout the program.
Global variables cannot be created
whenever that function is called.