This post was already published yesterday, someone deleted it by mistake so I had to recreate it…sorry for that (and thanks for google cache :-))

SSMS Tools PACK is an Add-In (Add-On) for Microsoft SQL Server Management Studio and Microsoft SQL Server Management Studio Express, this tool is developed by Mladen Prajdić.

SSMS Tools PACK contains a few upgrades to the IDE that were missing from Management Studio:

Some of these features are now available in SSMS 2008 but the tool is still very useful if you are using SSMS 2008. I am going to focus on the CRUD (Create, Read, Update, Delete) stored procedure generation functionality.

SSMS Tools PACK is available for the following SSMS versions

SQL Server Management Studio 2008

SQL Server Management Studio 2008 Express

SQL Server Management Studio 2005

SQL Server Management Studio 2005 Express

Download SSMS Tools PACK here: http://www.ssmstoolspack.com/Download.aspx

After it is installed create this table

T-SQL
1
2
3
4
5
6
7
CREATE TABLE Test (ID INT PRIMARY KEY IDENTITY,
                    LastName VARCHAR(40) not null,
                    FirstName VARCHAR(40) not null,
                    MiddleInitial CHAR(1)  null,
                    Salutation VARCHAR(10) null,
                    InsertedDate DATETIME not null,
                    LastUpdatedDate DATETIME not null)
CREATE TABLE Test (ID INT PRIMARY KEY IDENTITY,
                    LastName VARCHAR(40) not null,
                    FirstName VARCHAR(40) not null,
                    MiddleInitial CHAR(1)  null,
                    Salutation VARCHAR(10) null,
                    InsertedDate DATETIME not null,
                    LastUpdatedDate DATETIME not null)

Now from the menu select SSMS Tools–>CRUD Generator–>Options (see pic below)

I like to prefix my procs with pr instead of usp_ (See pic below)

You can customize how the procs will be generated, so for example the INSERT proc template looks like this

T-SQL
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
IF OBJECT_ID('[|schema|].[|procName|]') IS NOT NULL
BEGIN
    DROP PROC [|schema|].[|procName|]
END
GO
 
/*
Created by: SQLDenis
Version:    1.0
 
 
 
*/
CREATE PROC [|schema|].[|procName|]
|inputParams|
AS
    SET NOCOUNT ON
    SET XACT_ABORT ON  
   
    BEGIN TRAN
   
    INSERT INTO [|schema|].[|tableName|] (|insertColumnList|)
    SELECT |values|
   
    -- Begin Return Select <- do not remove
    SELECT |selectColumnList|
    FROM   [|schema|].[|tableName|]
    WHERE  |whereStatement|
    -- End Return Select <- do not remove
               
    COMMIT
GO
IF OBJECT_ID('[|schema|].[|procName|]') IS NOT NULL
BEGIN
    DROP PROC [|schema|].[|procName|]
END
GO
 
/*
Created by: SQLDenis
Version:    1.0
 
 
 
*/
CREATE PROC [|schema|].[|procName|]
|inputParams|
AS
    SET NOCOUNT ON
    SET XACT_ABORT ON  
   
    BEGIN TRAN
   
    INSERT INTO [|schema|].[|tableName|] (|insertColumnList|)
    SELECT |values|
   
    -- Begin Return Select <- do not remove
    SELECT |selectColumnList|
    FROM   [|schema|].[|tableName|]
    WHERE  |whereStatement|
    -- End Return Select <- do not remove
               
    COMMIT
GO

As you can see I added a comment block there that has my name and the initial version number. Having all your developers use a tool like this is great because you will have all the same looking procs and don’t have to worry that some people use @Error or @ErrorCode or @ErrorID. You just modify the template to have the error checking that you have standardized upon and you are done

So now let’s see what SSMS Tools PACK generates

Right click on the table you created, select SSMS Tools and then Create CRUD (See image below)

The following code will be generated

T-SQL
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
USE [Test];
GO
 
IF OBJECT_ID('[dbo].[prTestSelect]') IS NOT NULL
BEGIN
    DROP PROC [dbo].[prTestSelect]
END
GO
 
/*
Created by: SQLDenis
Version:    1.0
 
 
 
*/
CREATE PROC [dbo].[prTestSelect]
    @ID INT
AS
    SET NOCOUNT ON
    SET XACT_ABORT ON  
 
    BEGIN TRAN
 
    SELECT [ID], [FirstName], [InsertedDate], [LastName], [LastUpdatedDate], [MiddleInitial], [Salutation]
    FROM   [dbo].[Test]
    WHERE  ([ID] = @ID OR @ID IS NULL)
 
    COMMIT
GO
IF OBJECT_ID('[dbo].[prTestInsert]') IS NOT NULL
BEGIN
    DROP PROC [dbo].[prTestInsert]
END
GO
 
/*
Created by: SQLDenis
Version:    1.0
 
 
 
*/
CREATE PROC [dbo].[prTestInsert]
    @FirstName VARCHAR(40),
    @InsertedDate DATETIME,
    @LastName VARCHAR(40),
    @LastUpdatedDate DATETIME,
    @MiddleInitial CHAR(1),
    @Salutation VARCHAR(10)
AS
    SET NOCOUNT ON
    SET XACT_ABORT ON  
   
    BEGIN TRAN
   
    INSERT INTO [dbo].[Test] ([FirstName], [InsertedDate], [LastName], [LastUpdatedDate], [MiddleInitial], [Salutation])
    SELECT @FirstName, @InsertedDate, @LastName, @LastUpdatedDate, @MiddleInitial, @Salutation
   
    -- Begin Return Select <- do not remove
    SELECT [ID], [FirstName], [InsertedDate], [LastName], [LastUpdatedDate], [MiddleInitial], [Salutation]
    FROM   [dbo].[Test]
    WHERE  [ID] = SCOPE_IDENTITY()
    -- End Return Select <- do not remove
               
    COMMIT
GO
IF OBJECT_ID('[dbo].[prTestUpdate]') IS NOT NULL
BEGIN
    DROP PROC [dbo].[prTestUpdate]
END
GO
 
/*
Created by: SQLDenis
Version:    1.0
 
 
 
*/
CREATE PROC [dbo].[prTestUpdate]
    @ID INT,
    @FirstName VARCHAR(40),
    @InsertedDate DATETIME,
    @LastName VARCHAR(40),
    @LastUpdatedDate DATETIME,
    @MiddleInitial CHAR(1),
    @Salutation VARCHAR(10)
AS
    SET NOCOUNT ON
    SET XACT_ABORT ON  
   
    BEGIN TRAN
 
    UPDATE [dbo].[Test]
    SET    [FirstName] = @FirstName, [InsertedDate] = @InsertedDate, [LastName] = @LastName, [LastUpdatedDate] = @LastUpdatedDate, [MiddleInitial] = @MiddleInitial, [Salutation] = @Salutation
    WHERE  [ID] = @ID
   
    -- Begin Return Select <- do not remove
    SELECT [ID], [FirstName], [InsertedDate], [LastName], [LastUpdatedDate], [MiddleInitial], [Salutation]
    FROM   [dbo].[Test]
    WHERE  [ID] = @ID   
    -- End Return Select <- do not remove
 
    COMMIT TRAN
GO
IF OBJECT_ID('[dbo].[prTestDelete]') IS NOT NULL
BEGIN
    DROP PROC [dbo].[prTestDelete]
END
GO
 
/*
Created by: SQLDenis
Version:    1.0
 
 
 
*/
CREATE PROC [dbo].[prTestDelete]
    @ID INT
AS
    SET NOCOUNT ON
    SET XACT_ABORT ON  
   
    BEGIN TRAN
 
    DELETE
    FROM   [dbo].[Test]
    WHERE  [ID] = @ID
 
    COMMIT
GO
 
----------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------
USE [Test];
GO
 
IF OBJECT_ID('[dbo].[prTestSelect]') IS NOT NULL
BEGIN
    DROP PROC [dbo].[prTestSelect]
END
GO
 
/*
Created by: SQLDenis
Version:    1.0
 
 
 
*/
CREATE PROC [dbo].[prTestSelect]
    @ID INT
AS
    SET NOCOUNT ON
    SET XACT_ABORT ON  
 
    BEGIN TRAN
 
    SELECT [ID], [FirstName], [InsertedDate], [LastName], [LastUpdatedDate], [MiddleInitial], [Salutation]
    FROM   [dbo].[Test]
    WHERE  ([ID] = @ID OR @ID IS NULL)
 
    COMMIT
GO
IF OBJECT_ID('[dbo].[prTestInsert]') IS NOT NULL
BEGIN
    DROP PROC [dbo].[prTestInsert]
END
GO
 
/*
Created by: SQLDenis
Version:    1.0
 
 
 
*/
CREATE PROC [dbo].[prTestInsert]
    @FirstName VARCHAR(40),
    @InsertedDate DATETIME,
    @LastName VARCHAR(40),
    @LastUpdatedDate DATETIME,
    @MiddleInitial CHAR(1),
    @Salutation VARCHAR(10)
AS
    SET NOCOUNT ON
    SET XACT_ABORT ON  
   
    BEGIN TRAN
   
    INSERT INTO [dbo].[Test] ([FirstName], [InsertedDate], [LastName], [LastUpdatedDate], [MiddleInitial], [Salutation])
    SELECT @FirstName, @InsertedDate, @LastName, @LastUpdatedDate, @MiddleInitial, @Salutation
   
    -- Begin Return Select <- do not remove
    SELECT [ID], [FirstName], [InsertedDate], [LastName], [LastUpdatedDate], [MiddleInitial], [Salutation]
    FROM   [dbo].[Test]
    WHERE  [ID] = SCOPE_IDENTITY()
    -- End Return Select <- do not remove
               
    COMMIT
GO
IF OBJECT_ID('[dbo].[prTestUpdate]') IS NOT NULL
BEGIN
    DROP PROC [dbo].[prTestUpdate]
END
GO
 
/*
Created by: SQLDenis
Version:    1.0
 
 
 
*/
CREATE PROC [dbo].[prTestUpdate]
    @ID INT,
    @FirstName VARCHAR(40),
    @InsertedDate DATETIME,
    @LastName VARCHAR(40),
    @LastUpdatedDate DATETIME,
    @MiddleInitial CHAR(1),
    @Salutation VARCHAR(10)
AS
    SET NOCOUNT ON
    SET XACT_ABORT ON  
   
    BEGIN TRAN
 
    UPDATE [dbo].[Test]
    SET    [FirstName] = @FirstName, [InsertedDate] = @InsertedDate, [LastName] = @LastName, [LastUpdatedDate] = @LastUpdatedDate, [MiddleInitial] = @MiddleInitial, [Salutation] = @Salutation
    WHERE  [ID] = @ID
   
    -- Begin Return Select <- do not remove
    SELECT [ID], [FirstName], [InsertedDate], [LastName], [LastUpdatedDate], [MiddleInitial], [Salutation]
    FROM   [dbo].[Test]
    WHERE  [ID] = @ID   
    -- End Return Select <- do not remove
 
    COMMIT TRAN
GO
IF OBJECT_ID('[dbo].[prTestDelete]') IS NOT NULL
BEGIN
    DROP PROC [dbo].[prTestDelete]
END
GO
 
/*
Created by: SQLDenis
Version:    1.0
 
 
 
*/
CREATE PROC [dbo].[prTestDelete]
    @ID INT
AS
    SET NOCOUNT ON
    SET XACT_ABORT ON  
   
    BEGIN TRAN
 
    DELETE
    FROM   [dbo].[Test]
    WHERE  [ID] = @ID
 
    COMMIT
GO
 
----------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------

As you can see that is a huge time saver, you can of course customize it so that it conforms to your style guide.

Don’t forget to thank Mladen Prajdić on twitter: http://twitter.com/MladenPrajdic or to donate if this tool is useful to you

*** If you have a SQL related question try our Microsoft SQL Server Programming forum or our Microsoft SQL Server Admin forum