Hi,
Can I use CTE for insert, update and delete opeation ?
Or its only use for select command only ???
Thanks,
Sidhartha Patnaik
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Priyanka SinghRank #1,215 · 1.5K reputationPosted Apr 22, 2019, 10:37 PM EDT
Using the CTE –
We can define CTEs by adding a WITH clause directly before SELECT, INSERT, UPDATE, DELETE, or MERGE statement. The WITH clause can include one or more CTEs seperated by commas. The following syntax can be followed:
After you define your WITH clause with the CTEs, you can then reference the CTEs as you would refer any other table. However, you can refer a CTE only within the execution scope of the statement that immediately follows the WITH clause. After you’ve run your statement, the CTE result set is not available to other statements.
Amit KumarRank #459 · 5.4K reputationPosted Apr 22, 2019, 8:25 PM EDT
Rajanikant HawaldarRank #110 · 20.2K reputationPosted Apr 22, 2019, 8:34 PM EDT
Sidhartha PatnaikRank #5,346 · 302 reputationPosted Apr 22, 2019, 10:00 PM EDT
Sidhartha PatnaikRank #5,346 · 302 reputationPosted May 4, 2019, 4:59 AM EDT
Vinitha TRank #8,005 · 230 reputationPosted Nov 19, 2021, 10:06 AM EST
Rajeev KumarRank #1,334 · 1.3K reputationPosted Mar 7, 2023, 12:30 AM EST
A CTE must be followed by a single SELECT, INSERT, UPDATE, MERGE, or DELETE statement that references some or all the CTE columns. A CTE can also be specified in a CREATE VIEW statement as part of the defining SELECT statement of the view.