Changes data in existing rows, either by adding data or by modifying existing data.
update [top unsigned_integer] [[database.]owner.]{table_name | view_name} set [[[database.]owner.]{table_name.|view_name.}] column_name1 = {expression1 | NULL | (select_statement)} | variable_name1 = {expression1 | NULL | (select_statement)} [, column_name2 = {expression2 | NULL | (select_statement)}]... | [, variable_name2 = {expression2 | NULL | (select_statement)}]... [from [[database.]owner.]{view_name [readpast]| table_name [(index {index_name | table_name} [prefetch size][lru|mru])]} [readpast] [,[[database.]owner.]{view_name [readpast] | table_name [(index {index_name | table_name} [prefetch size][lru|mru])]}] [readpast] ...] [where search_conditions] [plan "abstract plan"]
update [[database.]owner.]{table_name | view_name} set [[[database.]owner.]{table_name.|view_name.}] column_name1 = {expression1 | NULL | (select_statement)} | variable_name1 = {expression1 | NULL | (select_statement)} [, column_name2 = {expression2 | NULL | (select_statement)}]... | [, variable_name2 = {expression2 | NULL | (select_statement)}]... where current of cursor_name
When using prefetch and designating the prefetch size (size), the minimum is 2K and any power of two on the logical page size up to 16K. prefetch size options in kilobytes are:
Logical Page Size |
Prefetch Size Options |
---|---|
2 |
2, 4, 8 16 |
4 |
4, 8, 16, 32 |
8 |
8, 16, 32, 64 |
16 |
16, 32, 64, 128 |
The prefetch size specified in the query is only a suggestion. To allow the size specification configure the data cache at that size. If you do not configure the data cache to a specific size, the default prefetch size is used.
If CIS is enabled, you cannot use prefetch for remote servers.
update authors set au_lname = "MacBadden" where au_lname = "McBadden"
update titles set total_sales = total_sales + qty from titles, salesdetail, sales where titles.title_id = salesdetail.title_id and salesdetail.stor_id = sales.stor_id and salesdetail.ord_num = sales.ord_num and sales.date in (select max (sales.date) from sales)
update titles set price = 24.95 where current of title_crsr
update titles set price = 18.95 where syb_identity = 4
declare @x money select @x = 0 update titles set total_sales = total_sales + 1, @x = price where title_id = "BU1032"
update salesdetail set discount = 40 from salesdetail readpast where title_id like "BU1032" and qty > 100
Use update to change values in rows that have already been inserted. Use insert to add new rows.
You can refer to as many as 15 tables in an update statement.
update interacts with the ignore_dup_key, ignore_dup_row, and allow_dup_row options set with the create index command. See create index for more information.
You can define a trigger that takes a specified action when an update command is issued on a specified table or on a specified column in a table.
In pre-12.5.2 versions of SAP ASE, queries that used update and delete on views with a union all clause were sometimes resolved without using worktables, which occasionally lead to incorrect results. In SAP ASE 12.5.2, queries that use update and delete on views with a union all clause are always resolved using worktables in tempdb.
See also sp_bindefault, sp_bindrule, sp_help, sp_helpartition, sp_helpindex, sp_unbindefault, sp_unbindrule in Reference Manual: Procedures.
ANSI SQL – Compliance level: Entry-level compliant.
The use of a from clause or a qualified table or column name are Transact-SQL extensions detected by the FIPS flagger. Updates through a join view or a view of which the target list contains an expression are Transact-SQL extensions that cannot be detected until run time and are not flagged by the FIPS flagger.
The use of variables.
readpast
If set ansi_permissions is on, you need update permission on the table being updated and, in addition, you must have select permission on all columns appearing in the where clause and on all columns following the set clause. By default, ansi_permissions is off.
The following describes permission checks for update that differ based on your granular permissions settings.
Setting | Description |
---|---|
Enabled | With granular permissions enabled, you must be the table or view owner, or a user with update permission.. |
Disabled | With granular permissions disabled, you must be the table or view owner, a user with update permission, or a user with sa_role. |
Values in event and extrainfo columns of sysaudits are:
Information | Values |
---|---|
Event | 70 |
Audit option | update |
Command or access audited | update to a table |
Information in extrainfo |
|
Information | Values |
---|---|
Event | 71 |
Audit option | update |
Command or access audited | update to a view |
Information in extrainfo |
|