简体   繁体   中英

MS SQL Server - How to export all Stored procedures from my machine to my friends machine?

How can i copy/export all stored procedures on MS SQL Server from my machine to a machine of my project partner ? It might be a basic question. Apologies.

Thank you.

You can generate script as follows-

  • Right click on database
  • Tasks
  • Generate Scripts
  • Select the objects you wish to script
  • Script to File
  • Run generated scripts against target database

If you want to select more than one objects (like SPs) tick the top-level checkbox beside "Stored Procedures" it selects them all together on 1 click.

It is s simple thing in SQL Management Studio, right click on the database go to tasks then to generate scripts and select stored procedures 在此处输入图片说明

You can extract the definitions of all stored procedures with this simple script.

select m.definition
from
    sys.objects as o
    inner join
        sys.sql_modules as m
            on o.object_id = m.object_id
where
    o.type = 'p'

Afterwards, you could run them all on the other machine. Yet, it barely ever is that easy. There might be underlying schemas or types which need to be there first. How about access to other databases or even linked servers within the stored procedure? All of these dependencies need to be addressed and resolved first before you can transfer the stored procedure to the other server.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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