sql >> Database >  >> RDS >> Mysql

SQL UPDATE-syntaxis - weergegeven door DBMS

Dit artikel bevat de SQL UPDATE syntaxis, zoals geïmplementeerd door verschillende databasebeheersystemen (DBMS'en). De syntaxis wordt precies weergegeven zoals elke leverancier deze op hun website heeft vermeld. Klik op de toepasselijke link om meer details over de syntaxis voor een bepaalde leverancier te bekijken.

De gedekte DBMS'en zijn MySQL, SQL Server, PostgreSQL en Oracle Database.

MySQL

Uit de MySQL 5.7 Reference Manual.

Syntaxis voor één tabel:

UPDATE [LOW_PRIORITY] [IGNORE] table_reference
    SET col_name1={expr1|DEFAULT} [, col_name2={expr2|DEFAULT}] ...
    [WHERE where_condition]
    [ORDER BY ...]
    [LIMIT row_count]

Syntaxis voor meerdere tabellen:

UPDATE [LOW_PRIORITY] [IGNORE] table_references
    SET col_name1={expr1|DEFAULT} [, col_name2={expr2|DEFAULT}] ...
    [WHERE where_condition]

SQL-server

Uit de Transact-SQL-referentie:

[ WITH <common_table_expression> [...n] ]
UPDATE 
    [ TOP ( expression ) [ PERCENT ] ] 
    { { table_alias | <object> | rowset_function_limited 
         [ WITH ( <Table_Hint_Limited> [ ...n ] ) ]
      }
      | @table_variable    
    }
    SET
        { column_name = { expression | DEFAULT | NULL }
          | { udt_column_name.{ { property_name = expression
                                | field_name = expression }
                                | method_name ( argument [ ,...n ] )
                              }
          }
          | column_name { .WRITE ( expression , @Offset , @Length ) }
          | @variable = expression
          | @variable = column = expression
          | column_name { += | -= | *= | /= | %= | &= | ^= | |= } expression
          | @variable { += | -= | *= | /= | %= | &= | ^= | |= } expression
          | @variable = column { += | -= | *= | /= | %= | &= | ^= | |= } expression
        } [ ,...n ] 

    [ <OUTPUT Clause> ]
    [ FROM{ <table_source> } [ ,...n ] ] 
    [ WHERE { <search_condition> 
            | { [ CURRENT OF 
                  { { [ GLOBAL ] cursor_name } 
                      | cursor_variable_name 
                  } 
                ]
              }
            } 
    ] 
    [ OPTION ( <query_hint> [ ,...n ] ) ]
[ ; ]

<object> ::=
{ 
    [ server_name . database_name . schema_name . 
    | database_name .[ schema_name ] . 
    | schema_name .
    ]
    table_or_view_name}

PostgreSQL

Uit de PostgreSQL 9.5-handleiding:

[ WITH [ RECURSIVE ] with_query [, ...] ]
UPDATE [ ONLY ] table_name [ * ] [ [ AS ] alias ]
    SET { column_name = { expression | DEFAULT } |
          ( column_name [, ...] ) = ( { expression | DEFAULT } [, ...] ) |
          ( column_name [, ...] ) = ( sub-SELECT )
        } [, ...]
    [ FROM from_list ]
    [ WHERE condition | WHERE CURRENT OF cursor_name ]
    [ RETURNING * | output_expression [ [ AS ] output_name ] [, ...] ]

Oracle-database

Uit de Oracle Database Online Documentation 12c Release 1 (12.1):

UPDATE [ hint ]
   { dml_table_expression_clause
   | ONLY (dml_table_expression_clause)
   } [ t_alias ]
   update_set_clause
   [ where_clause ]
   [ returning_clause ]
   [error_logging_clause] ;

 DML_table_expression_clause::=

{ [ schema. ]
  { table
    [ partition_extension_clause
    | @ dblink
    ]
  | { view | materialized view } [ @ dblink ]
  }
| ( subquery [ subquery_restriction_clause ] )
| table_collection_expression
}

partition_extension_clause::=

{ PARTITION (partition)
| PARTITION FOR (partition_key_value [, partition_key_value]...)
| SUBPARTITION (subpartition)
| SUBPARTITION FOR (subpartition_key_value [, subpartition_key_value]...)
}

subquery_restriction_clause ::=

WITH { READ ONLY
     | CHECK OPTION 
     } [ CONSTRAINT constraint ]

table_collection_expression ::=

TABLE (collection_expression) [ (+) ]

update_set_clause ::=

SET
{ { (column [, column ]...) = (subquery)
  | column = { expr | (subquery) | DEFAULT }
  }
     [, { (column [, column]...) = (subquery)
        | column = { expr | (subquery) | DEFAULT }
        }
     ]...
| VALUE (t_alias) = { expr | (subquery) }
}

where_clause ::=

WHERE condition

returning_clause::=

{ RETURN | RETURNING } expr [, expr ]...
INTO data_item [, data_item ]...

error_logging_clause::=

LOG ERRORS 
  [ INTO [schema.] table ]
  [ (simple_expression) ]
  [ REJECT LIMIT { integer | UNLIMITED } ]

Over de UPDATE Verklaring

De UPDATE statement wijzigt de waarden van de opgegeven kolommen in alle rijen die aan de voorwaarde voldoen. Alleen de kolommen die moeten worden gewijzigd, hoeven te worden opgenomen in de SET clausule; kolommen die niet expliciet zijn gewijzigd behouden hun eerdere waarden.


  1. SQL CASE-instructie

  2. Nieuwe manier om bestanden te kopiëren in SQL Server 2019

  3. Een MySQL-database maken

  4. Wordt de methode onUpgrade ooit aangeroepen?