查询一个数据库并使用结果更新另一个数据库 [英] Querying one database and using the results to update another

查看:107
本文介绍了查询一个数据库并使用结果更新另一个数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我正在尝试使用mysql数据库创建存储过程,该存储过程在一个数据库表上查询并使用结果更新另一个数据库表.

我不确定该怎么做.任何建议/解决方案将不胜感激!

这是一段示例代码,可让您大致了解我要执行的操作.

样本代码:

Hi,
I''m trying to create a stored procedure with a mysql Database that queries on one database table and uses the results to update another database table.

I''m not sure how to go about this. Any advice/solutions would be much appreciated!

Here''s a piece of sample code to give you an idea of what I''m attempting to do.

SAMPLE CODE:

DELIMITER //
CREATE PROCEDURE()
BEGIN
SELECT @count := COUNT(col) FROM DB1.TBL1;
UNION
UPDATE DB2.TBL2 SET @count = col;
END//

推荐答案

对于UPDATE语句中的入门者来说,SET部分向后,它应该为SET col = @count,并且您尚未声明@count变量,但是不确定最后一部分在MySql中是否重要.

但是,可以尝试的其他方法是 [
Well for starters in the UPDATE statement the the SET section is backwards it should be SET col = @count and you haven''t declared the @count variable, not sure if this last part matters in MySql though.

However something else to try is this[^].
Or see if this, which is just from the link, works.
UPDATE DB2.TBL2 a, DB1.TBL1 b
SET a.col= COUNT(b.col)


这篇关于查询一个数据库并使用结果更新另一个数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆