简体   繁体   English

在存储过程mysql中使用临时表进行更新

[英]Using temporary tables for update in stored procedure mysql

有谁能描述一个简单的示例,该示例在存储过程中使用临时表来更新mysql中的两个表?

Two kind of temporary tables available. 有两种临时表可用。 One is session based and the other one is global temporary table. 一个是基于会话的,另一个是全局临时表。

Below is the simple example: 下面是简单的示例:

    Select A,b,c into #MyTemp From MyDbTable

In the above example, #myTemp is the temporary table that you are creating. 在上面的示例中,#myTemp是您正在创建的临时表。 MyDbTable is the one that exist in your database. MyDbTable是数据库中存在的一个。 You can create multiple temporary tables. 您可以创建多个临时表。

I would suggest reading the article from here: Link 我建议从这里阅读文章: 链接

 --Create a temp table and insert all these counts in it
  Create Table #OperatorReportCount(Id int identity,Particulars varchar(100),NoOfArticles int)

  --Insert these values in table
  Insert Into #OperatorReportCount(Particulars,NoOfArticles) Values('Articles processed',@ProcessedArticleCount)
  Insert Into #OperatorReportCount(Particulars,NoOfArticles) Values('Articles approved',@ArticlesApproved)
  Insert Into #OperatorReportCount(Particulars,NoOfArticles) Values('Articles rejected',@ArticleRejectedCount)
  Insert Into #OperatorReportCount(Particulars,NoOfArticles) Values('Rejections recieved',@RejectionsRecievedCount)
  Insert Into #OperatorReportCount(Particulars,NoOfArticles) Values('Articles put on hold',@ArticlesOnHoldCount)   

  --Select the operator count table
  Select Particulars,NoOfArticles From #OperatorReportCount

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM