I'm working on a project that is subject to certain corporate standards relating to SQL implementation. Specifically, that all SQL Server content be accessed only via stored proc. (No ORM or LINQ.)
80% or more of our needs can be handled through the basic CRUD (CREATE, READ, UPDATE, DELETE) type of procedure that should be fairly simple to generate. However, I've been unsuccessful so far in locating an existing tool that will generate these fairly simple "base" stored procedures.
So, can anyone point me to a tool that I can use to generate the bulk of my required procedures? Preferably one that allows some customization of the process, such as wrapping the statements in a basic BEGIN/END TRY construct.
Thanks.
SSMS Tools Pack from sounds like it might fit the bill. You can customise the templates it uses.
It's well worth trying anyway for its other handy features.
ssms tools pack claims to do this: http://www.ssmstoolspack.com/ . Example code:
USE [AdventureWorks]; GO IF OBJECT_ID('[Person].[usp_AddressSelect]') IS NOT NULL BEGIN DROP PROC [Person].[usp_AddressSelect] END GO CREATE PROC [Person].[usp_AddressSelect] @AddressID INT AS SET NOCOUNT ON SET XACT_ABORT ON BEGIN TRAN SELECT [AddressID], [AddressLine1], [AddressLine2], [City], [StateProvinceID], [PostalCode], [rowguid], [ModifiedDate] FROM [Person].[Address] WHERE ([AddressID] = @AddressID OR @AddressID IS NULL) COMMIT GO IF OBJECT_ID('[Person].[usp_AddressInsert]') IS NOT NULL BEGIN DROP PROC [Person].[usp_AddressInsert] END GO CREATE PROC [Person].[usp_AddressInsert] @AddressLine1 nvarchar(60), @AddressLine2 nvarchar(60), @City nvarchar(30), @StateProvinceID int, @PostalCode nvarchar(15), @rowguid uniqueidentifier, @ModifiedDate datetime AS SET NOCOUNT ON SET XACT_ABORT ON BEGIN TRAN INSERT INTO [Person].[Address] ([AddressLine1], [AddressLine2], [City], [StateProvinceID], [PostalCode], [rowguid], [ModifiedDate]) SELECT @AddressLine1, @AddressLine2, @City, @StateProvinceID, @PostalCode, @rowguid, @ModifiedDate -- Begin Return Select <- do not remove SELECT [AddressID], [AddressLine1], [AddressLine2], [City], [StateProvinceID], [PostalCode], [rowguid], [ModifiedDate] FROM [Person].[Address] WHERE [AddressID] = SCOPE_IDENTITY() -- End Return Select <- do not remove COMMIT GO IF OBJECT_ID('[Person].[usp_AddressUpdate]') IS NOT NULL BEGIN DROP PROC [Person].[usp_AddressUpdate] END GO CREATE PROC [Person].[usp_AddressUpdate] @AddressID int, @AddressLine1 nvarchar(60), @AddressLine2 nvarchar(60), @City nvarchar(30), @StateProvinceID int, @PostalCode nvarchar(15), @rowguid uniqueidentifier, @ModifiedDate datetime AS SET NOCOUNT ON SET XACT_ABORT ON BEGIN TRAN UPDATE [Person].[Address] SET [AddressLine1] = @AddressLine1, [AddressLine2] = @AddressLine2, [City] = @City, [StateProvinceID] = @StateProvinceID, [PostalCode] = @PostalCode, [rowguid] = @rowguid, [ModifiedDate] = @ModifiedDate WHERE [AddressID] = @AddressID -- Begin Return Select <- do not remove SELECT [AddressID], [AddressLine1], [AddressLine2], [City], [StateProvinceID], [PostalCode], [rowguid], [ModifiedDate] FROM [Person].[Address] WHERE [AddressID] = @AddressID -- End Return Select <- do not remove COMMIT TRAN GO IF OBJECT_ID('[Person].[usp_AddressDelete]') IS NOT NULL BEGIN DROP PROC [Person].[usp_AddressDelete] END GO CREATE PROC [Person].[usp_AddressDelete] @AddressID int AS SET NOCOUNT ON SET XACT_ABORT ON BEGIN TRAN DELETE FROM [Person].[Address] WHERE [AddressID] = @AddressID COMMIT GO ---------------------------------------------------------------------------------------- ----------------------------------------------------------------------------------------