如何为 Visual Studio 创建新的存储过程模板?

发布于 2024-07-26 02:22:59 字数 766 浏览 6 评论 0原文

我想为我们的开发团队创建新存储过程的模板。

但是,我似乎无法为数据库对象创建模板项。 我知道对于 DLL/C# 相关项目,就像“文件 > 导出模板...”一样简单,

如何将新的 SQL 模板添加到我的数据库项目中?

这是我的模板:

IF EXISTS (select 1 from information_schema.routines where specific_schema = '_SCHEMA_' and routine_name = '_NAME_')
    BEGIN
        print 'Dropping Procedure _SCHEMA_._NAME_'
        DROP  Procedure  _SCHEMA_._NAME_
    END
GO

print 'Creating Procedure _SCHEMA_._NAME_'
GO
CREATE Procedure _SCHEMA_._NAME_
    (
        @parameter1 int
    ,   @parameter2 varchar(10)
    )
AS
BEGIN

END
GO

GRANT EXEC ON _SCHEMA_._NAME_ TO _ROLE_
GO

谢谢!

编辑:哇,这是我第一次有一个问题一整天都没有答案!

是只有我一个人使用项目模板吗?还是没有其他人使用项目模板? 我领导了许多开发人员,告诉他们“使用这个模板”与“阅读文档并那样做”更容易。

I would like to create a template for new stored procedures for our development team.

However, I can't seem to create template items for Database objects. I know for DLL/C#-related items, it's as simple as "File > Export Template ..."

How can I add new SQL templates to my Database project?

Here's my template:

IF EXISTS (select 1 from information_schema.routines where specific_schema = '_SCHEMA_' and routine_name = '_NAME_')
    BEGIN
        print 'Dropping Procedure _SCHEMA_._NAME_'
        DROP  Procedure  _SCHEMA_._NAME_
    END
GO

print 'Creating Procedure _SCHEMA_._NAME_'
GO
CREATE Procedure _SCHEMA_._NAME_
    (
        @parameter1 int
    ,   @parameter2 varchar(10)
    )
AS
BEGIN

END
GO

GRANT EXEC ON _SCHEMA_._NAME_ TO _ROLE_
GO

Thanks!

Edit: Wow, it's the first time I've had a question a whole day without any answers!

Is it just me, or does no one else use Item Templates? I lead a number of developers, and it's easier to tell them "use this template" vs. "read the docs and do it that way".

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

久而酒知 2024-08-02 02:22:59

找到了。

以下是包含文件的文件夹:

C:\Program Files\Microsoft Visual Studio 9.0\Common7\Tools\Templates\Database Project Items

可以直接将 New Stored procedure Script.sql 替换为您的自己的。 如果您想添加一个(我就是这样做的),您可以编辑 NewDataItems.vsdir 文件以显示自定义图标。

Found it.

Here is the folder with the files:

C:\Program Files\Microsoft Visual Studio 9.0\Common7\Tools\Templates\Database Project Items

It's straight-forward to replace the New Stored Procedure Script.sql with your own. If you want to add one (which I did) you can edit the NewDataItems.vsdir file to show a custom icon.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文