Databases 6 min read

Using the RETURNING Syntax in Tencent Cloud Enterprise MySQL (CDB)

This article demonstrates how to use the RETURNING clause in Tencent Cloud Enterprise MySQL to retrieve inserted, replaced, or deleted rows directly, showing step‑by‑step examples with images and explaining the behavior of RETURNING, REPLACE RETURNING, and DELETE RETURNING statements.

Tencent Database Technology
Tencent Database Technology
Tencent Database Technology
Using the RETURNING Syntax in Tencent Cloud Enterprise MySQL (CDB)

This article, presented with video and text, introduces the usage of the RETURNING syntax in Tencent Cloud Enterprise MySQL (CDB).

Background

In some database scenarios, users want to retrieve the rows they have just inserted after executing an INSERT statement. One way is to wrap the INSERT and a SELECT in a transaction.

Tencent Cloud Enterprise MySQL (CDB) supports a simpler method by using the RETURNING syntax, which appends the keyword RETURNING to an INSERT statement to directly return the newly inserted rows.

Demo

You can watch a video demonstration on Bilibili via the Tencent Architect channel, and the following text shows the usage of the RETURNING syntax.

First, log into the database instance and use an empty table for the demo. Insert a row using RETURNING; the result of RETURNING * returns all columns of the inserted row, while RETURNING id and RETURNING s return only the id and s columns respectively.

The RETURNING syntax also supports operations on the returned columns. The SQL statements shown return columns that have been transformed as expected.

replace returning and delete returning are also demonstrated.

For replace returning , we replace the column s of the row where id = 2 with the value abcd. After the replace, using RETURNING returns the modified row.

For delete returning , we perform a full‑table delete. After inserting two rows into table t, the statement DELETE FROM t RETURNING * deletes both rows and returns them, confirming that the DELETE statement can also return the affected rows.

This concludes a brief introduction to the RETURNING syntax; you are welcome to try Tencent Cloud Enterprise MySQL.

The Tencent Database Technology team supports internal services such as QQ Space, WeChat Red Packets, Tencent Ads, Tencent Music, Tencent News, and external products on Tencent Cloud like CynosDB, CDB, CTSDB, MongoDB, CES, etc. The team focuses on continuous kernel and architecture optimization to improve performance and stability, providing reliable database services for both internal and cloud customers. This public account aims to share professional database knowledge with enthusiasts.

↓ ↓ Click "Read Original" to view the Tencent Cloud Enterprise MySQL product details page

SQLdatabaseMySQLTencent CloudRETURNING
Tencent Database Technology
Written by

Tencent Database Technology

Tencent's Database R&D team supports internal services such as WeChat Pay, WeChat Red Packets, Tencent Advertising, and Tencent Music, and provides external support on Tencent Cloud for TencentDB products like CynosDB, CDB, and TDSQL. This public account aims to promote and share professional database knowledge, growing together with database enthusiasts.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.