Login or Sign Up to become a member!
LessThanDot Sit Logo

LessThanDot

Data Management

Less Than Dot is a community of passionate IT professionals and enthusiasts dedicated to sharing technical knowledge, experience, and assistance. Inside you will find reference materials, interesting technical discussions, and expert tips and commentary. Once you register for an account you will have immediate access to the forums and all past articles and commentaries.

LTD Social Sitings

Lessthandot twitter Lessthandot Linkedin Lessthandot friendfeed Lessthandot facebook Lessthandot rss

Note: Watch for social icons on posts by your favorite authors to follow their postings on these and other social sites.

Your profile

    Search

    XML Feeds

    Google Ads

    « Learn About SQL Server 2008 R2 Project Gemini And Project Madison By Watching These VideosScripting all jobs on SQL Server 2005/2008 into one file »
    comments

    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

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


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


    Options



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



    Change proc prefix


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

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



    Create CRUD

    The following code will be generated

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

    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

    About the Author

    User bio imageDenis has been working with SQL Server since version 6.5. Although he worked as an ASP/JSP/ColdFusion developer before the dot com bust, he has been working exclusively as a database developer/architect since 2002. In addition to English, Denis is also fluent in Croatian and Dutch, but he can curse in many other languages and dialects (just ask the SQL optimizer) He lives in Princeton, NJ with his wife and three kids.
    Social SitingsTwitterFacebookLinkedInHomePageFlickrLTD RSS Feed
    8301 views
    Instapaper

    13 comments

    Comment from: Natas [Member] Email
    *****
    Natas This is sooo awesome, it will save me so much time when creating these CRUD procs since our shop does everything through procedures

    09/01/09 @ 13:27
    Comment from: Ted Krueger (onpnt) [Member]
    *****
    Ted Krueger (onpnt) Very nicely put together Denis. I'm sure MladenPrajdic would say the same.
    09/01/09 @ 18:35
    Comment from: Nithin Balakrishnan [Visitor]
    ****-
    Nithin Balakrishnan hey this is a nice tool... Few suggestions for your next version :-) On update and delete scripts in addition to primary key, facility to add row version in the where codition to handle optimistic concurrency.

    update Table set code=@code, description =@description, Version =version+1
    Where Id=@ID and Version =@version
    09/03/09 @ 01:59
    Comment from: Naomi Nosonovsky [Member]
    *****
    Naomi Nosonovsky Nice tool - I installed it and recommended to others
    09/05/09 @ 23:29
    Comment from: SonOfKermit [Visitor] · http://lessthandot.com
    SonOfKermit Agree 100%, awesome tool - recently upgraded our servers to SQL 2008 Server, as soon as I installed the developer bits on my PC I downloaded and installed SSMS Tools Pack - I can't use SSMS without it now!
    11/12/09 @ 02:48
    Comment from: Eslam Badawy [Visitor] Email · http://ideal-softwares.com
    Eslam Badawy Many thanks , it's Amazing tool
    12/14/09 @ 15:29
    Comment from: Ravie Sant [Visitor]
    Ravie Sant How did u show that query window with alternate background colors?....plz tell me...
    02/04/10 @ 07:02
    Comment from: SQLDenis [Member] Email
    SQLDenis Ravie, what window? are you talking about the border? that is just Aero Glass in Windows 7
    02/04/10 @ 07:04
    Comment from: Ted Krueger (onpnt) [Member]
    Ted Krueger (onpnt) Ravie, if you mean the registered server type names, go to SSMS Tools and then Window Connection Coloring. You just add the server names in there and assign them colors. Example: mine are green = dev, orange = UAT, red = prod

    If you mean the alternating row colors in this blog, that is the site and not in SSMS
    02/04/10 @ 20:51
    Comment from: Miguel [Visitor]
    Miguel Great job. Thank you for your dedication
    11/18/11 @ 22:18
    Comment from: Azhar Iqbal [Visitor]
    Azhar Iqbal Its very nice and handy tool.
    02/16/12 @ 03:48
    Comment from: Azhar Iqbal [Visitor]
    Azhar Iqbal I have added regions please tell me how to remove the regions.
    Thanks
    02/17/12 @ 03:21
    Comment from: Srinika [Visitor]
    Srinika It is one of the best tools.
    Unfortunately, I cannot get Collapsing functionality work for me :(
    I do not get any +/- sign even in the Begin-End.
    05/18/12 @ 12:48

    Leave a comment


    Your email address will not be revealed on this site.

    Your URL will be displayed.
    (Line breaks become <br />)
    (Name, email & website)
    (Allow users to contact you through a message form (your email will not be revealed.)