4

I have a number of identical SQL Azure databases for like clients that need to have their versions tracked. SQL Azure in November of 2014 does not support extended properties as far as I know, if it did I could do something with extended properties for tracking versioning changes as was done here:

http://wateroxconsulting.com/archives/versioning-in-your-sql-database#

I was thinking of adapting that concept by making a DDL trigger that altered a stored procedure that held nothing but versioning comments.

So my question is about strategy - is a stored procedure the best place to keep this kind of info, or is there a better place to store textual versioning info in a SQL Azure container? I do not necessarily want to add a table to each database because that will dilute the purpose of the DB and leaves room for antics and it will need its own care and feeding of its table structure and etc.

And my follow-up question is about tactics - what is the best way to alter a procedure completely in TSQL doing string manipulation to append comment text?

Thanks.

2
  • Did I get this right that you want to use the procedure text to store data? What do you want to store there? A date of modification? Commented Nov 19, 2014 at 15:01
  • @usr, I was thinking of storing a date and in YYYYMMDD-HHMM and a version number and 40 chars of text. Commented Nov 20, 2014 at 2:43

2 Answers 2

1

You seem to be asking how to store some some data in a stored procedure, which is odd, because SQL server is a fantastic tool for storing data, but not in stored procedures.

I'd say a much better strategy would be to create a very simple table to store the information you mentioned in your comment i.e.

CREATE TABLE dbo.DatabaseVersion
(
    Date datetime,
    VersionNumber decimal(5,2),
    Description narchar(40)
);

And simply write an additional row to that database on each DDL trigger.

I'd say the reasons you have against it are pretty slim, but perhaps you could create a database schema just for this metadata i.e.

CREATE SCHEMA Metadata;

To make the purpose of the table clear and change the "dbo." in the DDL above to "Metadata." Some permissions can prevent antics, and if you need to care for the table structure it is far better to do this as a first class data table than as some unstructured comments in a stored procedure.

Sign up to request clarification or add additional context in comments.

Comments

0

This seems very similar to "Create a global static variable in SQL Server?" in a sense of storing some data in obscure way.

I think function would be shorter both in definition:

CREATE FUNCTION [dbo].[fn_GetVersion]()
RETURNS NVARCHAR(100)
BEGIN
  RETURN N'YYYYMMDD-HHMM and a version number and 40 chars of text'
END

... and in data retrieval:

Select [dbo].[fn_GetVersion]();

And it can be updated through dynamic DDL in triggers:

Exec ('ALTER FUNCTION [dbo].[fn_GetVersion]()
RETURNS NVARCHAR(100)
BEGIN
  RETURN N''YYYYMMDD-HHMM and version number and other 40 chars of text''
END')

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.