exec master..xp_cmdshell
'bcp "Select routine_definition from OnlyVC.information_Schema.routines order by routine_name" queryout "d:\1.sql" -c –T'

加粗部分为db的name

执行前要注意2个地方:

1.先执行

EXEC sp_configure 'show advanced options', 1
RECONFIGURE WITH OVERRIDE
EXEC sp_configure 'xp_cmdshell', 1
RECONFIGURE WITH OVERRIDE
EXEC sp_configure  'show advanced options', 0

否则会遇到下面的错误:

Msg 15281, Level 16, State 1, Procedure xp_cmdshell, Line 1
SQL Server blocked access to procedure 'sys.xp_cmdshell' of component 'xp_cmdshell' because this component is turned off as part of the security configuration for this server. A system administrator can enable the use of 'xp_cmdshell' by using sp_configure. For more information about enabling 'xp_cmdshell', see "Surface Area Configuration" in SQL Server Books Online.

2.添加-T参数:

否则会遇到下面的错误:

从SQL Server里导出存储过程和用户自定义函数

User name not provided, either use -U to provide the user name or use -T for Trusted Connection

相关文章:

  • 2021-06-28
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-11-23
  • 2022-02-23
猜你喜欢
  • 2021-06-12
  • 2021-07-30
  • 2021-06-06
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案