Crud Stored Procedure Generator Sql Server

Posted on
  • In this Tutorial I will teach how to perform CRUD Operations in SQL Server using both Query and Stored Procedure. I will create a Students Table into which CRUD operations will be done.
  • Dec 29, 2006 - SPGen) to generate CRUD stored procedures and business entities supporting SQL Server, Oracle, MySQL, PostgreSQL and DB2.
  1. C# Sql Crud
  2. Ssrs Crud
  3. Crud Stored Procedure Generator Sql Server Tutorial

UPDATE: This is now a part of a larger SSMS Add-In called SSMS Tools Pack

Crud Stored Procedure Generator Sql Server

I thought I'd post something special as the last post of this year and i was thinking about what it would be.

Fellow SqlTeamer Rockmoose said he'd like to have an add-in for SSMS that would genereate basic

Sql

C# Sql Crud

CRUD (Create - Insert, Read - Select, Update, Delete) stored procedures for a table.

And he'd like to have it on the context (right-mouse-click) menu of the table in Object Explorer in SSMS.

CRUD Stored Procedure Code/Scripts Generator For SQL SERVER 2005 Apr 19, 2007. I need a simple anf functionally CRUD Stored Procedure Code/Scripts Generator. Anyone have a solution? Thanks in Advance. View 4 Replies.

It sounded like a very cool little project and with the help of this excellent post about SSMS add-ins

Ssrs Crud

I've decided to make one.

You can download it here.

Sql

Unzip the MSI and run it.

Tell me what you think and how it works for you.

If you find any bugs or have any future functionality wishes mail them to me via contact page.

Happy New Year everyone!

Crud Stored Procedure Generator Sql Server Tutorial

Mladen
2006-12-29
re: CRUD stored procedures generating SSMS Add-in
Great! :)
thanx for sharing.
Daren Kovacevic
2007-01-03
re: CRUD stored procedures generating SSMS Add-in
Thanks Mladen. Nice utility.
the MyGeneration software sounds interesting but unfortunately the website appears to be down, so I'll be sticking to your CRUD tool for now.
I guess one suggestion would be to have an option to choose which CRUD-type operation you would like to create. Sometimes I don't want to create all of them and I am too lazy to remove the others from the code.
Perhaps also an option to name the proc/s so that they can fit custom naming conventions. Once again I know it can be done through the generated code but I thought the more autonomous the better.
keep up the good work
Tomas Kouba
2007-01-10
re: CRUD stored procedures generating SSMS Add-in
Good work.
It would be nice to have an option to generate 'optimistic' concurency lockin as Visual Studio 2003/2005.
May be also option to generate (or not) SELECT statement after INSERT and/or UPDATE.
And option to generate SELECT by indexes.
Mladen
2007-01-10
re: CRUD stored procedures generating SSMS Add-in
what exatly do you mean by: 'generate SELECT by indexes.' Tomas?
Rick
2007-01-24
re: CRUD stored procedures generating SSMS Add-in
For your select statements, give the parameter a default value of null and change your where statement to
WHERE ID = @ID OR @ID is null
That way you can use the procedure to select all record or a single one
Tadd Stuart
2007-03-30
re: CRUD stored procedures generating SSMS Add-in
Any chance of including Try/Catch blocks around the generated code?
The Error stuff works like this:
DECLARE @Error nVarChar(4000)
BEGIN TRY
Statements...
BEGIN TRY
Statements...
END TRY
BEGIN CATCH
SET @Error = ERROR_MESSAGE()
RAISERROR('This Error Occurred: %s', 16, 1, @Error)
END CATCH
END TRY
BEGIN CATCH
SET @Error = ERROR_MESSAGE()
RAISERROR('This Error Occurred: %s', 16, 1, @Error)
END CATCH
The nested Try...Catch will raise the error to the outer Try...Catch, ERROR_MESSAGE() is a built in function that will return the Error causing the Catch. Others, like ERROR_NUMBER(), also exist. The 2nd parameter of RAISERROR is the Error level, level 10 can be used for information only, no error is actually thrown, but the message will be sent to output. Any level higher then 10 will cause the Catch to run. 16 is known as a standard, 'something is wrong' level.
Mladen
2007-03-30
re: CRUD stored procedures generating SSMS Add-in
It's in the works...
but sinnce i'm playing with this in my free time it'll be a couple of weeks before i put something out...
WebZero
2007-04-18
re: CRUD stored procedures generating SSMS Add-in
When i try to launch Create CRUD Stored Procedures with the right click on table i retrive the following error:
Object Reference not set on istance of object.
Why?
Thx
Mladen
2007-04-18
re: CRUD stored procedures generating SSMS Add-in
I have no idea.
Can you mail me the stack trace? there should be one in the message box you're getting.
I'll be putting out a new version of this in a week or two, if that helps....
WebZero
2007-04-19
re: CRUD stored procedures generating SSMS Add-in
Message not display a stack trace.
I use another schema less than dbo, that can help you?
i have table like
[Schama1].[Table1]
[Schama1].[Table2]
[Schama2].[Table3]
[Schama2].[Table4]
I have tried also with AdventureWorks...
but :-(
here is the error:
http://img295.imageshack.us/img295/1961/errorgi8.jpg
Mladen
2007-04-19
re: CRUD stored procedures generating SSMS Add-in
this is after the new window has been atuomatically opened or before?
as i haven't tested this with a SSMS version other than English, i don't know if this is an
issue.
do you have an english version of SSMS that you can try this on?
WebZero
2007-04-21
re: CRUD stored procedures generating SSMS Add-in
before the new new window has been atuomatically ..
I use Italian version of SQL SERVER Developer edition.
thx
win32nipuh
2007-04-27
re: CRUD stored procedures generating SSMS Add-in
Hi,
nice work!
How can I use it for SSMS Expess Edition?
Thanx.
Regards.
Mladen
2007-04-27
re: CRUD stored procedures generating SSMS Add-in
haven't tried it on SSMSE. but i don't see why it shouldn't
ErickG
2007-05-09
re: CRUD stored procedures generating SSMS Add-in
just a suggestion...
why donĀ“t you add 'templates' for each operation..., in my case i use another namming convention... anyway its a good add-in.
sreedharTR
2007-05-23
re: CRUD stored procedures generating SSMS Add-in
Its Cool !!!!.
A good suggestion would be an interface to add templates .... as posted by ErickG.
It would be a wonderful option and save time
Roni Peterson Xavier Carvalho
2007-05-29
re: CRUD stored procedures generating SSMS Add-in
Hello, thanks for sharring.
I'm using the SSMS Express, but I can't find the option in the context menu.
The Add-in don't work with Express version ?
Thanks again!
Mladen
2007-05-29
re: CRUD stored procedures generating SSMS Add-in
don't know... haven't tried SSMSE.
Andrey
2007-06-07
re: CRUD stored procedures generating SSMS Add-in
I tried this nice add-in in SQL Server 2005 and it gave me the following exception. It would be really nice to fix it for 2005. Are there any alternative tools?
I get the following exception:
Must declare the scalar variable '@TableName'.
Must declare the scalar variable '@TableName'.
Incorrect syntax near ')'.
at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection)
at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection)
at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj)
at System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj)
at System.Data.SqlClient.SqlDataReader.ConsumeMetaData()
at System.Data.SqlClient.SqlDataReader.get_MetaData()
at System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString)
at System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async)
at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, DbAsyncResult result)
at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method)
at System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior, String method)
at System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior)
at a.a(String A_0, String A_1, String A_2)
Chris Wedgwood
2007-06-14
re: CRUD stored procedures generating SSMS Add-in
The generated stored procedure code is making the length of the fields twice that specified in the table. ie if my field is nvarchar(50) it gets written as nvarchar(100) in the CRUD procedures.
Mladen
2007-06-14
re: CRUD stored procedures generating SSMS Add-in
thanx andrey and chris..
both of these are fixed for the next release.
jhoojhar
2007-06-29
re: CRUD stored procedures generating SSMS Add-in
does this tool works with ssmse and if yes how to install this add into to sql server express edition .
Mladen
2007-06-29
re: CRUD stored procedures generating SSMS Add-in
no it doesn't work with ssmse
Franklin Rau
2007-09-14
re: CRUD stored procedures generating SSMS Add-in
I have developed a similar tool which generates CRUD stored procedures and also generates>
Mladen
2007-09-14
re: CRUD stored procedures generating SSMS Add-in
thanx for the link. nice!
Franklin Rau
2007-09-18
re: CRUD stored procedures generating SSMS Add-in
I have released the BETA version of my>
Mladen
2007-09-18
re: CRUD stored procedures generating SSMS Add-in
Awsome!
Li Xin
2007-11-03
re: CRUD stored procedures generating SSMS Add-in
I have developed a template driven code generator (Lattice.SPGen) to generate CRUD stored procedures and business entities supporting SQL Server, Oracle, MySQL, PostgreSQL and DB2.
http://www.latticesoft.com
Joe Zen
2008-11-08
re: CRUD stored procedures generating SSMS Add-in
This is the shit. Thanks!
Richard Slade
2009-02-18
re: CRUD stored procedures generating SSMS Add-in
This has saved me weeks of work, which was all done in one day thanks to your add-in.
Excellent project... many thanks!
Richard Slade
Mladen
2009-02-18
re: CRUD stored procedures generating SSMS Add-in
what did you do with it? it sounds great!
for these kinds of productivity boosts there's a special button on the add-in homepage titled Donate :))
Kurt
2009-05-09
re: CRUD stored procedures generating SSMS Add-in
Generates .Net Error on SQL Management Studio 2005 startup, then does not exist in the menu when clicking on a table. Had to uninstall to get rid of the error message. Would have loved to be able to use this. The search continues....
Mladen
2009-05-11
re: CRUD stored procedures generating SSMS Add-in
@Kurt
you have to install SP2 for SSMS. i've stopped supporting pre SP2 SSMS versions with SSMS Tools Pack 1.1
ermoas
2010-01-11
re: CRUD stored procedures generating SSMS Add-in
thanks for this wonderful SSMS addon!
Gonzalo.
2010-06-18
re: CRUD stored procedures generating SSMS Add-in
Cool! Thanks!
Michael Moore
2010-06-27
re: CRUD stored procedures generating SSMS Add-in
This does not show up in SSMS 2008 after installation. Worked great in 2005
Microsoft SQL Server Management Studio 10.50.1600.1
Microsoft Analysis Services Client Tools 10.50.1600.1
Microsoft Data Access Components (MDAC) 6.0.6000.16386
Microsoft MSXML 3.0 4.0 5.0 6.0
Microsoft Internet Explorer 7.0.6000.17037
Microsoft .NET Framework 2.0.50727.3603
Operating System 6.0.6000
will s
2010-07-13
re: CRUD stored procedures generating SSMS Add-in
I LOVE this add-in. I install it on all my new machines. I have used MyGeneration for some things, it's very nice, but I LOVE the way this is just baked in and just works, no fluff, no '20 billion configuration options'. Thank you so much!
Hi All I have recently written a CRUD Generator that uses Microsoft.ApplicationBlocks.Data so if anyone is interested please let me know. The generated Classes and Stored procedures support ACID principles. The CRUD generator essentially encapsulates all my working knowledge into one neat little package to save myself considerable development time. (WinForms app) I basically followed the KISS and 80/20 rules when writing this little app so it is by no means perfect. In my case the tool creates 70-90 percent of the data access code I will ever need for a given database in a matter of seconds. The CRUD generator addresses the following issues: Transactions - updates, inserts and delete methods are overloaded to support optional passing of transaction objects. In that way you could manually create a composite class that utilizes two or more CRUD generated classes and pass a transaction to all the participating objects. Either all the changes commit or everything is rolled back. Optimistic concurrency - All a DBA needs to do is add CreatedDate (datetime) column to table and CRUD generator will create all the necessary logic to check for optimistic concurrency violation. Only stipulation is that the developer passes original Datetime value back to procedure so valid comparison can be made. I leave cascading deletes and restricted deletes up to SQL server as it should be. In all delete stored procs the CRUD generator simply traps error 547 (foreign key violation) if user attempts to delete primary key that is referenced in another table. I then throw a friendly error message using RAISEERROR. CRUD Generator Limitations: <-- I would not characterize these issues as limiatations but others may. ie C# developer - Every table must use a single column to represent tables primary key. The column must utilize IDENTITY attribute and appear as first column in table. - Binary data types are currently not supported. - Only supports SQL Server - Only VB code is generated Some additional features of CRUD generator: - User can point to new database by simply changing connection string in applications config file - User can select one or more tables they wish to generate classes or stored procedures for - User can specify namespace that all classes will utilize - User can specify which methods and stored procedures are generated (i.e. insert, delete, update and so on) - User can specify if they want datareaders or datasets returned to client applications. - All the stored procedures are written to a single file for convenience - Each table has its own class generated. The naming conventions is table name followed by DB suffix. For example, Employees table would have generated class called EmployeesDB. - For CRUD generated select procedures the user may optionally define additional columns that are included from related tables - The CRUD generator will generate select procedures for all foreign keys found in a table. By foreign keys I mean columns with a suffix of ID. ID is simply the convention I use. For example, imagine Employees table had a field called ManagerID. The CRUD generator would generate a stored procedure called EmployeesGetByManagerID that could be used to retrieve all the employees that fall under a given manager. I took a look at LLBGEN as well and I thought it generated a lot of unnecessary code. Regards, Kevin Weir kevinweir382@hotmail.com