您应该将 SQL 存储过程存储在源代码管理中吗? [英] Should you store your SQL Stored Procedures in Source Control?

查看:31
本文介绍了您应该将 SQL 存储过程存储在源代码管理中吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在开发具有大量存储过程的应用程序时,是否应该将它们存储在某种源版本控制系统(例如源安全、TFS、SVN)中?如果是这样,为什么?是否有使用 SQL Server Management Studio 执行此操作的便捷前端方法?

When developing an application with lots of stored procedures, should you store them in some sort of source versioning system (such as source-safe, TFS, SVN)? If so, why? And is there a convenient front end way to do this with SQL Server Management Studio?

推荐答案

是的.所有代码都应存储在源代码管理中.

Yes. All code should be stored in source control.

简单地说,代码就是代码,错误会发生.很高兴能够回过头来看看随着时间的推移发生了什么变化并能够回到这些变化.

Simply put, code is code and mistakes happen. It's nice to be able to go back and see what changed over time and be able to go back to those changes.

我们必须手动将其添加到源代码控制系统,但您可以为 Sql Server 管理系统创建插件.我从来没有创建过一个自动将它添加到源代码管理,但我想你可以.此外,所有代码都存储在 sql 表中,因此理论上您可以创建一个进程或其他东西来遍历表并检索所有代码并自动提交.

We have to add it manually to a source control system, but you can create addons for the Sql Server the Management System. I haven't ever created one to automatically add it to source control, but I suppose you could. Also, all the code is stored in sql tables, so you could in theory create a process or something to go through the table(s) and retrieve all the code and commit it automatically.

更新:我总是会编写额外的代码来检查代码是否存在以及它是否不创建填充程序,然后实际脚本执行并更改程序.

Update: I would always write extra code to check and see if the code exists and if it doesn't create a filler procedure and then the actual script do and alter procedure.

IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE 
id = OBJECT_ID(N'[dbo].[SomeStoredProcedure]') AND 
OBJECTPROPERTY(id,N'IsProcedure') = 1)

EXEC sp_executesql N'CREATE PROCEDURE [dbo].[SomeStoredProcedure] AS

SELECT ''SPROC Template'''

GO

SET ANSI_NULLS ON

GO

SET QUOTED_IDENTIFIER ON

GO

 ALTER PROCEDURE SomeStoredProcedure

删除并重新创建将删除您为其设置的所有用户权限.

Doing a drop and recreate will remove all the user permissions you have setup for it.

这篇关于您应该将 SQL 存储过程存储在源代码管理中吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆