dnlnln / generate-sql-merge

Generate SQL MERGE statements with Table data
MIT License
337 stars 151 forks source link

Allow sp_generate_merge to be installed without sysadmin/db_owner rights #98

Closed dnlnln closed 1 year ago

dnlnln commented 1 year ago

Currently, sp_generate_merge is installed as a system stored procedure. Installing into master DB in this way means that sysadmin privileges are required to create the sproc. The only other option was to install into an individual database, but even this requires db_owner role membership (or more precisely, CREATE PROC permission within the DB).

This PR makes it possible to install sp_generate_merge as a temporary proc, making it possible for anyone with read access to use the proc in their environment.

To generate merge statements via a temporary proc:

  1. Edit sp_generate_merge.sql, replacing all occurrences of sp_generate_merge with #sp_generate_merge
  2. Connect to the database that you want to use the proc within i.e. USE [AdventureWorks]
  3. Execute the script
  4. Generate merge statements as follows: EXEC [#sp_generate_merge] @Schema='Person', @Table_Name='AddressType'