is it possible to call a sql script from a stored procedure in another sql script?

前端 未结 2 953
渐次进展
渐次进展 2020-12-03 18:26

I\'d like to use . to call sql script from inside a stored proc like so...

delimiter ///
create procedure append_procedure()
BEGIN
\\. test.sql;    
END; ///         


        
相关标签:
2条回答
  • 2020-12-03 18:56

    If you're on Sql Sevrer 2005 you can use the xp_cmdshell command.

    http://msdn.microsoft.com/en-us/library/ms175046(SQL.90).aspx

    Or

    http://www.sqlservercentral.com/articles/Administering/scriptscheduling/450/

    0 讨论(0)
  • 2020-12-03 19:03

    There is a set of commands that are builtin to the mysql client. They're documented under "mysql Commands." These include DELIMITER, SOURCE, HELP, CONNECT, USE, QUIT, etc.

    The \. (or SOURCE) command is one of these builtins. You can't execute these builtin commands programmatically, nor from within a stored procedure.

    It'd be like trying to run a UNIX shell builtin from a C program using execl().

    A different analogy might be in a web browser, where you can type in special requests like "about:" that are handled by the browser app itself; these don't result in any HTTP request to a remote web site.

    Also, it wouldn't help if you could source a script from within a stored procedure, because the script itself likely contains a bunch of commands that are mysql client builtins, and thus cannot be run by the stored proc.


    See also my answers to these related questions:

    • Running MySQL *.sql files in PHP
    • Loading .sql files from within PHP
    • PHP: multiple SQL queries in one mysql_query statement
    0 讨论(0)
提交回复
热议问题