如何将现有的SQL Server存储过程添加到源代码控制中?

时间:2022-09-11 17:18:31

Right now we have a bunch of database servers with stored procedures running in them that are poorly documented and exist nowhere else.

现在,我们有一堆数据库服务器,其中运行的存储过程文档很差,在其他任何地方都不存在。

When a change is made to one, there is no log, and it's really hard to figure out why something that was working suddenly fails.

当对1进行更改时,就没有日志了,而且很难弄清楚为什么某些工作突然失败。

We've recently switched to using proper version control using SVN, so I was hoping to add these stored procedures to version control.

我们最近改用了使用SVN的适当版本控制,因此我希望将这些存储过程添加到版本控制中。

We are a .Net shop, and I'm aware that there exists a Database project type. Would that be a good approach?

我们是一个。net商店,我知道存在一个数据库项目类型。这是一个好方法吗?

Alternatively I could just keep the stored procedures as text files and operate on those, but I'm wondering about the annoying deployment steps involved with doing so.

或者,我可以将存储过程保存为文本文件并对其进行操作,但是我想知道这样做会涉及到哪些恼人的部署步骤。

5 个解决方案

#1


3  

In Visual Studio, I created an empty project and added the scripts to it. Its part of my server schema solution. Now every single script in under source control. I also added a folder structure as well to try and keep the sanity. When the application is finished we will have probably close to 3000 scripts under source control under multiple server schemas. Not saying this is the best, but it is working for our project. The solution also has a utility which uses SMO to actually run/deploy all the scripts, so everything is contained in one solution. Screen shot attached showing some of the structure for your reference...

在Visual Studio中,我创建了一个空项目并将脚本添加到它。它是我的服务器模式解决方案的一部分。现在每个脚本都在源代码控制下。我还添加了一个文件夹结构,以保持其完整性。当应用程序完成时,我们可能会在多个服务器模式下的源代码控制下拥有近3000个脚本。不是说这是最好的,但它正在为我们的项目工作。该解决方案还有一个实用程序,它使用SMO实际运行/部署所有脚本,因此所有内容都包含在一个解决方案中。屏幕截图显示了一些结构,供您参考……

如何将现有的SQL Server存储过程添加到源代码控制中?

#2


5  

Check out redgate's sql source control. It has an interface built into SSMS and can integrate with SVN.

查看redgate的sql源代码控件。它有一个内置在SSMS中的接口,可以与SVN集成。

http://www.red-gate.com/products/sql-development/sql-source-control/

http://www.red-gate.com/products/sql-development/sql-source-control/

#3


2  

A database project is a good choice, in my opinion. You can import the entire database, including tables, views, stored procedures, etc. Visual Studio will use this information to build an in-memory model of the database.

在我看来,数据库项目是个不错的选择。您可以导入整个数据库,包括表、视图、存储过程等。Visual Studio将使用这些信息构建数据库的内存模型。

It can use this for several purposes, including making sure your stored procedures are properly accessing the tables. For instance, it caught me trying to insert an Integer parameter into a smallint column.

它可以用于多种目的,包括确保存储过程正确地访问表。例如,它发现我试图将一个整数参数插入到smallint列中。

#4


1  

Yes, I would recommend a database project -- you can synchronize database elements (tables/stored procedures, etc...) in either direction: source files to DB, or DB to source files.

是的,我推荐一个数据库项目——您可以将数据库元素(表/存储过程等)同步到两个方向:源文件到DB,或者DB到源文件。

You could start by creating an empty database project, then syncing from the existing database(s) to your project, which creates the .sql create scripts for you.

您可以先创建一个空的数据库项目,然后从现有的数据库同步到您的项目,该项目为您创建.sql创建脚本。

And you can use the database project to create deployment scripts too. Very handy.

您也可以使用数据库项目来创建部署脚本。非常方便。

#5


1  

We use the database project and have good results with it. All DML exists in the project (3000+ items).

我们使用数据库项目,并取得了良好的结果。所有DML都存在于项目中(3000多个项目)。

Developers must make changes to the DML in source control and check them in, and only what is checked in will be promoted/deployed.

开发人员必须在源代码控制中对DML进行更改并检入它们,只有检入的内容才会被提升/部署。

Our source control is TFS, and I noticed that deleting procs from the VS interface doesnt always mark the proc for deleting in source control. Not sure what SVN does with it.

我们的源控件是TFS,我注意到从VS接口删除proc并不总是标记源控件中删除proc。不知道SVN用它做什么。

#1


3  

In Visual Studio, I created an empty project and added the scripts to it. Its part of my server schema solution. Now every single script in under source control. I also added a folder structure as well to try and keep the sanity. When the application is finished we will have probably close to 3000 scripts under source control under multiple server schemas. Not saying this is the best, but it is working for our project. The solution also has a utility which uses SMO to actually run/deploy all the scripts, so everything is contained in one solution. Screen shot attached showing some of the structure for your reference...

在Visual Studio中,我创建了一个空项目并将脚本添加到它。它是我的服务器模式解决方案的一部分。现在每个脚本都在源代码控制下。我还添加了一个文件夹结构,以保持其完整性。当应用程序完成时,我们可能会在多个服务器模式下的源代码控制下拥有近3000个脚本。不是说这是最好的,但它正在为我们的项目工作。该解决方案还有一个实用程序,它使用SMO实际运行/部署所有脚本,因此所有内容都包含在一个解决方案中。屏幕截图显示了一些结构,供您参考……

如何将现有的SQL Server存储过程添加到源代码控制中?

#2


5  

Check out redgate's sql source control. It has an interface built into SSMS and can integrate with SVN.

查看redgate的sql源代码控件。它有一个内置在SSMS中的接口,可以与SVN集成。

http://www.red-gate.com/products/sql-development/sql-source-control/

http://www.red-gate.com/products/sql-development/sql-source-control/

#3


2  

A database project is a good choice, in my opinion. You can import the entire database, including tables, views, stored procedures, etc. Visual Studio will use this information to build an in-memory model of the database.

在我看来,数据库项目是个不错的选择。您可以导入整个数据库,包括表、视图、存储过程等。Visual Studio将使用这些信息构建数据库的内存模型。

It can use this for several purposes, including making sure your stored procedures are properly accessing the tables. For instance, it caught me trying to insert an Integer parameter into a smallint column.

它可以用于多种目的,包括确保存储过程正确地访问表。例如,它发现我试图将一个整数参数插入到smallint列中。

#4


1  

Yes, I would recommend a database project -- you can synchronize database elements (tables/stored procedures, etc...) in either direction: source files to DB, or DB to source files.

是的,我推荐一个数据库项目——您可以将数据库元素(表/存储过程等)同步到两个方向:源文件到DB,或者DB到源文件。

You could start by creating an empty database project, then syncing from the existing database(s) to your project, which creates the .sql create scripts for you.

您可以先创建一个空的数据库项目,然后从现有的数据库同步到您的项目,该项目为您创建.sql创建脚本。

And you can use the database project to create deployment scripts too. Very handy.

您也可以使用数据库项目来创建部署脚本。非常方便。

#5


1  

We use the database project and have good results with it. All DML exists in the project (3000+ items).

我们使用数据库项目,并取得了良好的结果。所有DML都存在于项目中(3000多个项目)。

Developers must make changes to the DML in source control and check them in, and only what is checked in will be promoted/deployed.

开发人员必须在源代码控制中对DML进行更改并检入它们,只有检入的内容才会被提升/部署。

Our source control is TFS, and I noticed that deleting procs from the VS interface doesnt always mark the proc for deleting in source control. Not sure what SVN does with it.

我们的源控件是TFS,我注意到从VS接口删除proc并不总是标记源控件中删除proc。不知道SVN用它做什么。