如何在执行SQL脚本时回显打印语句 [英] How to echo print statements while executing a sql script

查看:584
本文介绍了如何在执行SQL脚本时回显打印语句的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们有一个简单的sql脚本,需要针对MySQL数据库执行该脚本,并且希望在脚本的进度上打印日志语句(例如,将10条记录插入foo或从bar中删除5条记录).我们该怎么做?

We have a simple sql script which needs to be executed against a MySQL database and we would like print log statements on the progress of the script (e.g. Inserted 10 records into foo or Deleted 5 records from bar). How do we do this?

  1. 我想知道用于插入/更新/删除语句的语法.
  2. 我如何知道受语句影响的行数.
  3. 我还希望使用脚本顶部的关闭或打开命令使用ECHO来控制打印它们.
  4. 该脚本应可在Windows/Linux操作系统上移植.

推荐答案

这将为您提供在sql脚本中的简单打印:

This will give you are simple print within a sql script:

select 'This is a comment' AS '';

或者,如果直接在updatedeleteinsert命令之后使用,则会向状态更新中添加一些动态数据:

Alternatively, this will add some dynamic data to your status update if used directly after an update, delete, or insert command:

select concat ("Updated ", row_count(), " rows") as ''; 

这篇关于如何在执行SQL脚本时回显打印语句的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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