|
|
|
Old Hand
      
Group: General Forum Members
Last Login: Today @ 9:15 AM
Points: 316,
Visits: 1,185
|
|
|
|
|
|
SSC Rookie
      
Group: General Forum Members
Last Login: Wednesday, September 12, 2012 8:44 PM
Points: 30,
Visits: 145
|
|
Just a small suggestion - please consider EXTENDED properties for DB objects (including Stored Procedures), by using them in a key-value fashion you could avoid a lot of text processing.
Regards from DownUnder.
|
|
|
|
|
Forum Newbie
      
Group: General Forum Members
Last Login: Thursday, December 13, 2012 9:44 AM
Points: 4,
Visits: 30
|
|
Just a small concern...
As far as experience and memory serves, sp_helptext is not a reliable source for recreating SQL server objects. SQL management objects are the preferred source.
Changes to an object and/or metadata may render sp_helptext outdated - the script used to create the original object may not reflect the object in its current state. I seem to remember a case where the sp_helptext record was blatantly incorrect after a (?) designer edit.
Does anyone have a concise view of when this may occur, and whether stored procedures are for practical purposes immune to these cases?
|
|
|
|
|
Mr or Mrs. 500
      
Group: General Forum Members
Last Login: Sunday, May 19, 2013 4:00 AM
Points: 533,
Visits: 2,285
|
|
I really enjoy seeing scripts like this, since the whole topic of scripting is fascinating. What I really like about this is that someone has gone ahead and brewed a solution that fits their requirements like a glove. It is neat, because it will work with any version of SQL Server 2000+.
I wouldn't like anyone to think that this is a recommended general solution, though. SMO is the way to go! (I still occasionally use DMO)
Best wishes,
Phil Factor Simple Talk
|
|
|
|
|
SSC-Enthusiastic
      
Group: General Forum Members
Last Login: Thursday, February 21, 2013 5:18 AM
Points: 110,
Visits: 162
|
|
I also had similar issues with sp_helptext and eventually found a way of scripting objects using Microsoft.SqlServer.Management.Smo.Scripter in Powershell.. this has the advantage that it handles all types of objects including everything from logins to linked-servers, mail profiles, etc, and can take advantage of easy iteration possible in powershell.
I've written a skeleton (and, disclaimer; is not warranted in any way) ps script that captures relevant source/schema stuff in SQL Server, if anyone's interested. Obviously it can be adjusted to taste for extended properties etc (which I turn off by default) and should be tweaked to expose specific properties relevant to only certain objects.
Link here http://wp.me/pje2P-l
I also have a wrapper script that iteratively runs it for each database on the server, and a server-objects script that captures mail profiles, accounts etc, for anyone interested.
Regards, Mike
|
|
|
|
|
SSChampion
        
Group: General Forum Members
Last Login: Today @ 3:40 PM
Points: 13,380,
Visits: 25,164
|
|
|
|
|
|
Hall of Fame
       
Group: General Forum Members
Last Login: Today @ 6:54 PM
Points: 3,578,
Visits: 5,120
|
|
Or you can simply use ApexSQL Edit, which has some very spiffy built-in source code control functionalilty - among many other features.
Disclaimer: I have a close relationship with Apex, use their products and recommend them to my clients. Also, if you care to you can mention TheSQLGuru sent you you will get a discount and my daughter will get a few coins for her college fund.
Best,
Kevin G. Boles SQL Server Consultant SQL MVP 2007-2012 TheSQLGuru at GMail
|
|
|
|
|
SSC Rookie
      
Group: General Forum Members
Last Login: 2 days ago @ 2:13 PM
Points: 43,
Visits: 205
|
|
Good article. I always like to see/hear how others are using version control on their databases. Currently, we version all objects not just stored procedures, functions and triggers. There are inherent issues with this obviously, but we have tried to figure out ways around them that fit our particular needs. We are even working on a way to create automatic builds of our database changes to a testing environment without using compare tools. I'd love to hear if others have successfully used a version control solution to maintain database updates as well.
Thanks again for the article
J. Baxter
|
|
|
|
|
SSC-Enthusiastic
      
Group: General Forum Members
Last Login: Thursday, February 21, 2013 5:18 AM
Points: 110,
Visits: 162
|
|
Automated deployments of stored-procs is relatively easy, but anything that involves a table schema change for example kind of makes the whole approach a bit complex and prone to problems. Also, it becomes much harder if you are building routines that need to be created in a specific order- we've toyed with creating dependencies but never got it working satisfactorily.
More useful for us in our small shop was detecting unauthorised/unexpected changes to our database objects, and providing a good audit of objects altered to tie into our change control process.
Using SMO we've been able to version most objects quite easily and build a daily source copy and an associated job to compare the output to a VC'd baseline, noting differences.
It's also made capturing changes between a development environment and production environment a lot easier- script both to two folders and run a winmerge or similar comparison tool to see what ammendments have been made- although as noted above, syncing the changes almost always is easier to handle the "long" way for our relatively simple db.
|
|
|
|
|
SSC-Enthusiastic
      
Group: General Forum Members
Last Login: Today @ 12:33 PM
Points: 124,
Visits: 204
|
|
I have to agree with some of the comments here particularly on the principal on version control however and at the risk or creating some controversy, I would question the value of the solution provided other than it fitted exactly what one person required and it managed to generate some discussion.
Phil was spot on with recommending that SMO was the way to go and while I agree with that for this particular problem my underlying point is that the solution to a problem should really be based on sound technical knowledge of the tool set and the most appropriate elements of that tool set to be used to provide the solution.
Powershell was also mentioned and this in conjunction with SMO/SQLPSX can give you a scripter in one line of code. You cant get much simpler than that and while not very useful as it stands it does serve as an example of the value in knowing what is available.
-- Script all tables in the adventureworks database on the default instance on the local server Get-SqlDatabase "(localserver)" "adventureworks" | Get-SqlTable | Get-SqlScripter
Articles like this just make me question just how much knowledge the writer has with the tool set we all use on a day to day basis.
|
|
|
|