Appendix: SQL Syntax（7）
Tags: opengauss
Published: 2023-03-13 03:50:27

**GRANT**
Grants permissions to roles and users.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/clm388bpok8or3w4rykx.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/dfo7hmqe4ojt14d4hagm.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/66sk43am7x0c3vsi2srt.png)

**INSERT**
Inserts new rows into a table.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/tcexa57yez6abtohh0jo.png)

**LOCK**
Obtains a table-level lock.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/nn197bto1t1h72zw4waq.png)

**MERGE INTO**
Conditionally matches data in a target table with that in a source table. If data matches, **UPDATE** is executed on the target table; if data does not match, **INSERT** is executed. You can use this syntax to run **UPDATE** and **INSERT** at a time for convenience

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/qffmzx5hzqff6au1vf8b.png)

**MOVE**
Repositions a cursor without retrieving any data. **MOVE** works exactly like the **FETCH** command, except it only positions the cursor and does not return rows.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/m6uzridl1lv2vx1esxh5.png)

**PREPARE**
Creates a prepared statement.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/jt80233l9p1gyzzl1p1i.png)

**PREPARE TRANSACTION**
Prepares the current transaction for two-phase commit.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/4ivbog7m5n3pfjso7kfw.png)

**REASSIGN OWNED**
Changes the owner of the database object.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/6a6bb9uphj9uew6wf8n6.png)

**REFRESH MATERIALIZED VIEW**
Refreshes a materialized view in complete refresh mode.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/u0ujijx6nhxpqb4h5ykp.png)

**REINDEX**
Rebuilds an index using the data stored in the index's table, replacing the old copy of the index.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/vsi324twbleacunivbcj.png)

**RESET**
Restores run-time parameters to their default values. The default values are defined in the **postgresql.conf** configuration file.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/za1dbcn3nq50633mhfrt.png)

**REVOKE**
Revokes permissions from one or more roles.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ym05w98lxf9mqqrqgxla.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8ttigk3fqa2ejgotbgia.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/uv0yjpn4r4h4rn517lb5.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/41lda7y6bi7zl8svzz6w.png)

**ROLLBACK**
Rolls back the current transaction and backs out all updates in the transaction.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8vcwqkfxor0hxz13u4d7.png)

**ROLLBACK PREPARED**
Prepares the current transaction for two-phase commit.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/xbkpsw0ruhiousqdyssa.png)

**SAVEPOINT**
Establishes a new savepoint within the current transaction.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/6ntaxdmirf6dwifx5f7w.png)

**SELECT**
Retrieves data from a table or view.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/82flqcklqn0jbt1wzncf.png)

**SELECT INTO**
Defines a new table based on a query result and inserts data obtained by query to the new table.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/r0ra4a6i1wonxtxe84eo.png)

**SET**
Modifies a run-time parameter.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/kqanyfu9jsvk6xyoanss.png)

**SET CONSTRAINTS**
Sets a constraint for checking the current transaction.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/nygysabdjmjwd590e54g.png)

**SET ROLE**
Sets the current user identifier of the current session.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/eju25ir1tyn9z251a4cv.png)

**SET SESSION AUTHORIZATION**
Sets the session user identifier and the current user identifier of the current SQL session to a specified user.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/qcv9qzfbfqfgjj8cxs72.png)

**SET TRANSACTION**
Sets constraints for checking the current transaction.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/lpd9ttaqlzypzrz489n9.png)

**SHOW**
Sows the current value of a run-time parameter.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/y1fakdcxa7rppinn982u.png)

**START TRANSACTION**
Starts a transaction. If the isolation level or read/write mode is specified, a new transaction will have those characteristics. You can also specify them using **SET TRANSACTION**.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ng0plp147rhkqf93tmwq.png)

**TRUNCATE**
Quickly removes all rows from a database table.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/qgvb2ilfdep29nv6jez7.png)

**UPDATE**
Updates data in a table. Changes the values of the specified columns in all rows that satisfy the condition. The WHERE clause clarifies conditions. The SET clause specifies the columns to be modified and columns that not specified in the SET clause retain their previous values.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8mozgadypxzi8oi7bsgi.png)

**VACUUM**
Recycles storage space occupied by rows that have been deleted from a table or B-Tree index. In normal database operation, rows that have been deleted are not physically removed from their table; instead, they remain present until a **VACUUM** is done. Therefore, it is necessary to do **VACUUM** periodically, especially on frequently-updated tables.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/bi0xc6wk5naat5vp4s1s.png)

**VALUES**
Computes a row or a set of rows based on given values. It is most commonly used to generate a constant table within a large statement.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8m2z7q3eb1mlggeefk4q.png)