Managing stored procedures in SQL Server over time - sql-server

Imagine I am creating a Winforms app, using WCF I connect the same to SQL Server. I would be creating stored procedures in SQL Server.
My scenario here is as I release updates for my app over time...like ver 1.0, ver 2.0...v.n...
I might then need to modify my stored procedures. But I can't do that as it might affect users using the earlier version of the app. Hence I might need to create new stored procedures for the newer versions over time.
So I would want to know what is the best naming convention for my stored procedures? Can I name them something like sp_name_1_0, sp_name_2_0 and so on? It would have been much easier if there was some kind of grouping possible for stored procedures in SQL Server like folders...
Let me know what the best way is!
Thanks,
Sarin Gopalan

Related

How can I use same EF entities for SQL Server Compact and SQL Server?

I have a project to create a program that can operate in two modes:
internal users access a centralized database (SQL Server) and can view/edit each others items, or
external customers create all their own data locally (SQL Server Compact) and package it up in XML over e-mail to request a quote.
The question is, what's the best way to do this to minimize maintenance and maximize EF functionality? I'd also like to use stored procedures in SQL Server for write operations, but this isn't a top priority if too much trouble.
I could hand-create a separate SSDL before deployment, but this is extra work and error-prone. I could go Model First, but I think it would complicate database updates for both providers. I could go the Code First direction using the DbContext Generator T4 templates, but then I lose a lot of EF benefits like change tracking and stored procedure mapping. And with CF, I'd have to greatly enhance the T4 templates or I still have to create a separate SSDL.
Is there an article or any tools to make this easier?
Edit: I decided the best way to accomplish this was to use Code First to create my model and use the new code first migrations. With migrations I can generate a change script for the full server instance and I can just apply the full changes on the local CE database. The other advantage is that I have full control over my connection string and can really point it at any provider.
It's a little extra work to create the POCO classes by hand, to create the configuration classes (I prefer defining by Fluent API), and to add the extras (like unique indexes) to the first migration class, but in the end its the least work overall.
I'll have to figure out how to shunt in the stored procedures usage at a later date, but EF 5 might be available by then and have solved my problem.
I'd also like to use stored procedures in SQL Server for write
operations, but this isn't a top priority if too much trouble.
SQL Compact doesn't support stored procedures so if you mean this seriously you will not be able to reuse your mapping any way.
I could go the Code First direction using the DbContext Generator T4 templates, but then I lose a lot of EF benefits like change tracking and stored procedure mapping.
You will lose just stored procedure mapping . Change tracking will work in the same way. You will also be able to use same mapping code for both database server but you will have to figh with some minor differences between SQL server and SQL Server compact.
I could hand-create a separate SSDL before deployment, but this is extra work and error-prone.
You will have to do that if you want to use EDMX and both big SQL Server and SQL Server Compact with the same code base. Moreover you will have to limit features of your big SQL Server implementation to only features supported by SQL Server Compact.

Organize stored procedures, views, functions etc with sql management studio

I'm using Microsoft SQL Server Management Studio to work with a database. I'm only a .Net developer with limited experience in managing sql server, I'm far from a real DBA. In next few days, the number of stored procedures are going to increase very much. Also more views and functions will be created.
Are there any way to organize this elements in folders? I don't want to have dozens of SP under the same folder. It will be a pain to maintain.
Of course, I know that using a name convention will help me, but are there anything more that I can do?
Thanks.
As far as I know, SSMS doesn't allow you to group schema objects in folders. Your best bet would be to use SQL Server Schema's to organize your objects. Each schema would represent an area of functionality such as 'Customer', 'Security', 'Master' etc. This is a great way to organize your objects, and implement security.
Take a look at this SO thread on Schema's:
What good are SQL Server schemas?

Thoughts On Extended Stored Procedures

I am looking to insert and update records in a database using functions and logic that are not available in SQL Server or any other RDBMS for that matter. After Googling around a bit this morning, I have come across the concept of Extended Stored Procedures. As far as I can tell, I should be able to compile my desired functionality into a dll, make a stored proc utilizing that dll to do the inserting/updating.
However, most of the articles and examples I have come across are somewhat dated (~2000). Are extended stored procedures still an acceptable practice? I am far from an expert in this area, so any other suggestions or comments would be greatly appreciated.
If you're using SQL Server 2005 or later, SQL CLR is the area to look at. You can call .NET code from within SQL Server.
This article on MSDN is a good place to start.
Are extended stored procedures still
an acceptable practice?
No, they are officialy deprecated and will be dicontinued in a future release. See Deprecated Database Engine Features in SQL Server 2008 , in the Features Not Supported in a Future Version of SQL Server table:
Extended stored procedure programming: Use CLR Integration instead.
I usually recommend against using CLR procedures, in most cases you can refactor the problem you are facing, into something that Transact Sql can handle.
Of most concern is the procedural approach that often accompanies the use of CLR procedures, when a relation database performs best when performing set based operations.
So the first question I always ask, is there anyway to refactor the problem into a set based operation.
If not, then I ask why would you want to execute the code inside of the database server, instead of in an application layer? Think about the performance impact you might have by placing the logic inside the database. (This might not be an issue if your db server has plenty of extra processing time).
If you do go head with CLR procedures, I think they are best applied to intensive calculations and complex logic.

How to use Stored Procedure in SqlCE

I have just installed Sql Server Compact Edition. To my surprise, we can't use stored procedure in sql server CE. Do I have any alternative of Stored Procedure in Sql Server CE.
I am strongly obsessed with stored procedure, I can'nt think of an application without stored procedures.
Please help, Thanks in advance.
Edit: Can I use Managed Stored Procedures.
SqlCe is a local database for use by an application. There is no need for stored procedures since the database is just a local data store, and the business logic is in the application. It is not an engine. If you need an engine then use SqlExpress or its big brother. See Steve Lasker's Comparing SQL Server Express and Compact Editions Whitepaper at http://download.microsoft.com/download/A/4/7/A47B7B0E-976D-4F49-B15D-F02ADE638EBE/Compact_Express_Comparison.doc. It explains everything you need to know.
No, you cannot use managed stored procedures. SqlCe is in-process.
Also, you might find Data Storage Architecture with SQL Server 2005 Compact Edition at http://msdn.microsoft.com/en-us/library/bb380177(SQL.90).aspx helpful.
This blog from Steve Lasker describes how you can implement something similar to sprocs on SQL Server Compact: http://blogs.msdn.com/stevelasker/archive/2008/02/11/stored-procedures-and-sql-server-compact-the-great-debate.aspx
You will have to use inline sql in your application. Use SqlCeCommand.CommandText Property to specify sql text.
I don't really know what is supported by SQL Server CE, but UDFs can often be substituted for stored procedures. If that doesn't help, try calculated columns and/or indexed views. If those are not available as options, then I think you are stuck with putting the logic in your application.

SQL Server stored procedure question

I have a SQL Server stored procedure which has been in use for years. This stored procedure calls lots of other procedures. I would like to extract each inside procedure one at a time and implement its business logic to a .NET Class project.
In order to do that, I have to call .NET assembly from parent stored procedure and the returned result will be used by parent procedure. Since SQL Server 2005 and higher has CLR integration, so I think, executing .NET assembly inside stored procedure [or any Database objects] should not be a big deal, can you please point me some references where i can find examples or article to implement it?
Thank you very much for your help .
I really feel that this would be an inappropriate use of SQL CLR. The purpose of CLR integration is to support complex data types and operations that are normally very hard to do in pure SQL (such as sequences, regular expressions, hierarchy, geospatial, etc.) Not to implement a domain model in your database.
Domain models and business logic are separate from relational/data models. They should be in a proper business tier of some sort. Don't hack them into a database using the CLR.
(Note: I use SQLCLR a fair bit. I am not railing on CLR integration. I just don't think that this question reflects a wise design decision.)
MSDN
Building my First SQL Server 2005 CLR
An Intro to CLR Integration in SQL Server 2005
For loads more ;)
I think you should use SQL Server Integration Services (SSIS). As far as I understand, it solves this case, to orchestrate the procedure calls and gives you much more too..
I'm not too sure if moving this decision outside the db layer is a good decision.
Hope it helps..

Resources