SQL Numeric data types are used to store numeric values such as integers and decimals. They include INT for whole numbers and DECIMAL for precise decimal values.
Example
DECLARE @myInt INT = 42;
SELECT @myInt;
SQL Date and Time Data Types
SQL Date and Time data types are used to store date and time values. They include DATETIME for the date and time together and DATE for the date only.
SQL Unicode Character and String data types are used for multilingual text. They include NVARCHAR for variable-length Unicode strings and NCHAR for fixed-length Unicode strings.
Example
-- Create a table to store Unicode text
CREATE TABLE Greetings (
ID INT PRIMARY KEY,
IndianGreeting NVARCHAR(100)
);
-- Insert an Indian greeting in English into the table
INSERT INTO Greetings (ID, IndianGreeting)
VALUES
(1, N'Namaste, SQL Server!'); -- "Namaste" is a common Indian greeting-- Retrieve and display the Indian greeting from the table
SELECT * FROM Greetings;
SQL Binary Data Types
SQL Binary data types store binary data, such as images or files. They include VARBINARY for variable-length binary data.
SQL Miscellaneous data types include unique identifiers (UNIQUEIDENTIFIER) and SQL_VARIANT for storing values of various data types in a single column.
The DECLARE @local_variable statement is used to declare a local variable in SQL Server. Local variables are scoped to the batch or stored procedure where they are declared.
Example
DECLARE @myVariable INT;
SET @myVariable = 100;
SET @local_variable
The SET @local_variable statement assigns a value to a previously declared local variable in SQL Server.
Example
DECLARE @myVariable INT;
SET @myVariable = 42;
SELECT @local_variable
The SELECT @local_variable statement is used to retrieve and display the value stored in a local variable.
Example
DECLARE @myVariable INT;
SET @myVariable = 73;
SELECT @myVariable;