The command for variable declaration in SQL is DECLARE, which is used to declare variables to store temporary data. Syntax: DECLARE variable_name data_type [(size)] [DEFAULT default_value]. Parameters: variable_name is the variable name, data_type is the data type, (size) specifies the maximum length for the string type, [DEFAULT default_value] is the optional default value. For example: DECLARE @age INT; declares the integer variable @age. DECLARE @name VARCHAR(5
Commands for variable declaration in SQL
In SQL, use DECLARE
command to declare variables. Variables are containers for storing temporary data and can be used in queries.
<code>DECLARE variable_name data_type [(size)] [DEFAULT default_value];</code>
variable_name:
,
DATE, etc.
(size): @age:
<code>DECLARE @age INT;</code>
@name and set the default value to "Unknown":
<code>DECLARE @name VARCHAR(50) DEFAULT 'Unknown';</code>
Follow-up operations
SET command to assign it
<code>SET @age = 25;</code>
<code>SELECT * FROM customers WHERE age > @age;</code>
The above is the detailed content of What is the command for variable declaration in sql. For more information, please follow other related articles on the PHP Chinese website!