How to add Stored Procedures to Version Control

后端 未结 6 545
礼貌的吻别
礼貌的吻别 2021-01-31 17:53

Our team just experienced for the first time the hassle of not having version control for our DB. How can we add stored procedures at the very least to version control? The cur

6条回答
  •  别跟我提以往
    2021-01-31 18:46

    We just add the CREATE statement to source control in a .sql file, e.g.:

    -- p_my_sp.sql
    CREATE PROCEDURE p_my_sp
    AS
        -- Procedure
    

    Make sure that you only put one SP per file, and that the filename exactly matches the procedure name (it makes things so much easier to find the procedure in source control)

    You then just need to be disciplined about not applying a stored procedure to your database that hasn't come from source control.

    An alternative would be to save the SP as an ALTER statement instead - this has the advantage of making it easier to update an existing database, but means you need to do some tweaking to create a new empty database.

提交回复
热议问题