SET serves two core purposes in SQL:1. UPDATE clause – In every major dialect, SET appears inside an UPDATE statement to assign new values to one or more columns in the rows that satisfy the WHERE filter. Each column is paired with an expression, literal, sub-query, or function call. If the WHERE clause is omitted, the assignment affects every row in the table.2. Stand-alone statement – Many databases (PostgreSQL, SQL Server, MySQL, Oracle, Snowflake) implement a separate SET command that alters run-time settings (e.g., search_path, ANSI_WARNINGS) or assigns values to local/session variables. The exact syntax, available options, and scoping rules vary by vendor, but the intent is the same: change state for the current transaction, session, or connection.Key behaviors and caveats:- ORDER of assignments does not influence execution; all expressions are evaluated on the original row state unless the dialect specifies otherwise.- Expressions may refer to columns being updated (self-assignment) but not to aliases defined in the same SET list.- The stand-alone form is not part of the ANSI standard; always confirm syntax in your dialect documentation.- Permissions: UPDATE requires UPDATE privileges on the target table; session SET requires proper role or ALTER SESSION permissions.- In transactional databases, SET inside UPDATE is rolled back if the transaction is rolled back. Stand-alone SET options may or may not roll back, depending on the database (for example, SET LOCAL in PostgreSQL reverts at transaction end).
table_name
(identifier) - Target table to update.column
(identifier) - Column to assign.expression
(any) - Value or calculation assigned to the column.condition
(boolean) - Optional filter limiting affected rows.option_name
(identifier) - Session or system option (stand-alone SET).variable / @variable
(identifier) - User or local variable (dialect-specific).SQL-92 (UPDATE ... SET). Vendor-specific stand-alone SET appeared earlier (e.g., Sybase SQL Server 4.x).
No. Without WHERE, every row in the table is updated. Add a WHERE clause to target specific rows and avoid accidental data loss.
No. Only the UPDATE ... SET clause is standardized. Stand-alone SET for session options and variables is implemented differently by each vendor.
Yes. Separate each column-expression pair with commas inside the SET list: SET col1 = val1, col2 = val2.
UPDATE ... SET changes roll back if the transaction fails. Session-level SET may or may not roll back, depending on your database. Use PostgreSQL's SET LOCAL for transactional scope.