SQL set

Created By: chatGPT

SQL SET is a command used to assign values to variables or to update the settings of the SQL environment. It is often used in stored procedures or in scripts to manage variable states. The following explains the primary uses of the SET command in SQL.
1. Setting a Variable: When you need to store a value into a variable, you can use the SET command. This is particularly useful in T-SQL (Transact-SQL).
DECLARE @VariableName INT;
SET @VariableName = 10;
2. Updating Values in a Table: You can also utilize SET in an UPDATE statement to modify existing data. This is most commonly used to change the values of specific columns in a database table.
UPDATE Employees
SET Salary = Salary * 1.1
WHERE Department = 'Sales';
3. Session Settings: SET can also configure session-level parameters such as the date format or transaction isolation levels. This allows control over how SQL sessions behave during execution.
SET DATEFORMAT ymd;
SET TRANSACTION ISOLATION LEVEL READ COMMITTED;
4. Setting Options: You may also set options that affect the behavior of the SQL environment. This can include enabling or disabling specific features.
SET NOCOUNT ON;
SET ANSI_NULLS ON;
Introduction And SetupSelectFromWhereJoinInner JoinLeft JoinRight JoinFull JoinOnGroup ByHavingOrder ByLimitInsert IntoValuesUpdateSetDeleteCreate TableAlter TableDrop TableCreate IndexDrop IndexUnionUnion AllIntersectExceptCaseWhenThenElseEndInBetweenLikeIs NullIs Not NullExistsNot ExistsAndOrNotAsWithDistinctCountSumAvgMinMaxCastCoalesceNullifSubstringConcatLowerUpperTrimReplaceRoundFloorCeilAbsModCurrent_dateCurrent_timeCurrent_timestamp