|
Introduction

Microsoft SQL Server 2000 has a feature that allows you to generate diagrams of your schema. These diagrams are saved in a custom, binary format by the Enterprise Manager in the [dtproperties] table - they are backed-up with the rest of your data, but they are not easy to transfer between databases or add to source control (like Visual SourceSafe).
In order to move a diagram to another database (or get it into a 'text' format for source control), you need to extract the binary data from [dtproperties] and get it into a more usable format - Clay Beatty wrote a tool to do just that for SQL Server 2000.
The code for this article contains a similar tool, re-written for SQL Server 2005. It consists of a stored procedure and function that work together to generate a set of INSERT/UPDATE statements which you apply to a database in order to restore the source diagram.
Background: Scripting diagrams in SQL Server 2000

I originally came across Clay Beatty's usp_ScriptDatabaseDiagrams stored procedure to script diagrams on Google groups, along with the two other objects required for it to work: ufn_VarbinaryToVarcharHex and usp_dtpropertiesTextToRowset.
I've been using usp_ScriptDatabaseDiagrams for the past two years - since our ("agile") development methodology calls for the database to be rebuilt from script as part of the continuous integration process, we would 'lose' database diagrams if we couldn't persist them in some way.
Being able to script the diagrams means it also makes sense to do some 'database documentation' directly in the diagram tool. Documentation done this way is conveniently stored with the database itself (so it's easy for other developers to discover during maintenance).
SQL Server 2005
One of the first upgrading issues with SQL Server 2005 in our continuous integration process was the failure of the diagram scripts... Turns out there are a number of changes in SQL Server 2005 which break the code from 2000:
- The diagram data is now stored in [sysdiagrams] and not [dtproperties]
- [sysdiagrams] has only one row per diagram, whereas [dtproperties] has seven rows
- SQL Server 2005 introduces the
VARBINARY(MAX) data type
There is a lot of code in the SQL Server 2000 script to manage the [dtproperties] rows (DtgSchemaOBJECT, DtgSchemaGUID, DtgSchemaNAME, DtgDSRefBYTES, DtgDSRefDATA, DtgSchemaBYTES, DtgSchemaDATA), which in turn are probably there because of the clumsy support for binary data in SQL Server 2000. For this reason, it's almost 600 lines of Transact-SQL!
The new [sysdiagrams] table schema, addition of VARBINARY(max) and UPDATE statement enhancements, meant that the old script was not really applicable to SQL 2005, and had to be re-written from scratch.
About the new 2005 code
| Tool_VarbinaryToVarcharHex |
This User Defined Function takes some binary data as a parameter, and outputs a hexadecimal string representation. It is a helper function for the diagram scripting procedure. |
| Tool_ScriptDiagram2005 |
This Stored Procedure requires a diagram name, which it parses from [sysdiagrams]. It creates a set of INSERT statements that re-create the diagram when applied to a database with the same schema. |
How it works
The differences in SQL Server 2005 are so great that the diagram script was re-written from scratch - in around 120 lines (with lots of PRINT statements). Much less than the 600 lines required in SQL Server 2000! It performs three main steps:
1) Get the source diagram ID and the size of the binary data
Uses the new SQL Server 2005 DATALENGTH to determine how much data we need to process (important for step #3). We also generate a variable @DiagramSuffix which is used to ensure diagram names are unique (not shown). SELECT
@diagram_id=diagram_id
, @size = DATALENGTH(definition)
FROM sysdiagrams
WHERE [name] = @name
2) Generate an INSERT statement that creates a new row in [sysdiagrams]
This script is basically selecting the values from the current [sysdiagrams] row, and building an INSERT statement which is output via the PRINT command. Notice the [definition] column (which contains the binary data for the diagram) is set to Ox - an empty hexadecimal. This is important when Using Large-Value Data Types and UPDATE.Write because you cannot .Write to a column with a NULL value. SELECT @line =
'INSERT INTO sysdiagrams ([name],
[principal_id], [version], [definition])'
+ ' VALUES (''' + [name] + '''+@DiagramSuffix, '
+ CAST (principal_id AS VARCHAR(100)) + ', '
+ CAST (version AS VARCHAR(100)) + ', 0x)'
FROM sysdiagrams
WHERE diagram_id = @diagram_id
PRINT @line
3) Create UPDATE statements grabbing chunks of [definition]
In a WHILE loop from 1 to DATALENGTH([definition]), use the helper function Tool_VarbinaryToVarcharHex to convert chunks of binary data into hexadecimal strings that can be PRINTed out and saved as text. WHILE @index < @size
BEGIN
SELECT @line =
'UPDATE sysdiagrams SET [definition] .Write ('
+ ' 0x' + UPPER(dbo.Tool_VarbinaryToVarcharHex (
SUBSTRING (definition, @index, @chunk)))
+ ', null, 0) WHERE diagram_id = @newid '
FROM sysdiagrams
WHERE diagram_id = @diagram_id
PRINT @line
SET @index = @index + @chunk
END
TRY/CATCH error handling
There's a great deal of IF @@ERROR <> 0 error handling in the original script. By contrast, the new 2005 error handling is a lot simpler - the syntax will be familiar to .NET language developers: BEGIN TRY
INSERT INTO sysdiagrams ([name], [principal_id],
[version], [definition])
VALUES ('All'+@DiagramSuffix, 1, 0, 0x)
SET @newid = SCOPE_IDENTITY()
END TRY
BEGIN CATCH
RETURN
END CATCH
This isn't exactly the perfect example of TRY/CATCH usage in SQL - no TRANSACTION usage (so it doesn't show COMMIT/ROLLBACK) - but you get the idea.
To see how Tool_VarbinaryToVarcharHex works, read through the comments in the code - this is predominantly unchanged (except for the addition of code comments) from the SQL Server 2000 version which was freely posted by Clay.
Running the 'code'
Once you've executed the two scripts in your database, use them to generate INSERT/UPDATE statements for your diagrams like this: exec Tool_ScriptDiagram2005 'All Tables'
Which will create a script that looks like this (notice the new SQL Server 2005 UPDATE.Write command): PRINT 'Create row for new diagram'
INSERT INTO sysdiagrams ([name], [principal_id], [version], [definition])
VALUES ('All'+@DiagramSuffix, 1, 0, 0x)
SET @newid = SCOPE_IDENTITY()
PRINT 'Write diagram id ' + CAST(@newid AS VARCHAR(100)) + ' into new row '
PRINT 'Now add all the binary data...'
UPDATE sysdiagrams
SET [definition] .Write ( 0xD0CF11E0A1B11AE1, null, 0)
WHERE diagram_id
UPDATE sysdiagrams
SET [definition] .Write ( 0x0600000000000000, null, 0)
WHERE diagram_id
Each UPDATE adds a little more binary data to the [sysdiagram] row until you can save the UPDATEs to disk, add them to source control, whatever... When you wish to retrieve the diagram (to another copy/version/backup of the database), just run the UPDATE script. The output will look like this: === Tool_ScriptDiagram2005 restore diagram [all] ===
Suffix diagram name with date, to ensure uniqueness
Create row for new diagram
Write diagram all into new row (and get [diagram_id])
Now add all the binary data...
=== Finished writing diagram id 75 ===
=== Refresh your Databases-[DbName]-Database Diagrams
to see the new diagram ===</CODE>

Right-click the Database Diagrams folder in the SQL Server Management Studio, and choose 'Refresh'. Your restored diagram should be ready to view!
Conclusion
Hopefully, people find this script as useful as I found Clay Beatty's original for SQL Server 2000.
History
- 2006-08-07: posted on CodeProject.
| You must Sign In to use this message board. |
|
| | Msgs 1 to 25 of 38 (Total in Forum: 38) (Refresh) | FirstPrevNext |
|
|
 |
|
|
I read through the article, downloaded the scripts and ran them. I have no idea what you are talking about when you say that update and insert scripts get created. Where? Are you referring to some stored procedures? Only a single stored procedure was created. If I am suppose to run this sp, with what paramter value? You mention "All Tables". Or do I use the name of my schema diagram? What am I suppose to run to save the schema and what do I run to restore it? I want to transfer my schema diagram from the current database to another.
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
After just posting this message, I did another Google search for a way to copy the schema diagram from one SQL Server 2005 database to another. Here is the most simple an elegant solution I found and makes the solution presented in this article totally unnecessary:
use NameOfSourceDatabaseHere
go
--this will copy your database diagrams into a temporary table
select * into dbo.#tempsysdiagrams from sysdiagrams
use NameOfDestinationDatabaseHere
go
insert into sysdiagrams ([name],principal_id,version,definition)
select [name],principal_id,version,definition from dbo.#tempsysdiagrams where [name]='NameOfYourSchemaHere'
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
Yes, you can transfer sysdiagrams rows across two currently mounted databases. If that is all you need, just use your method and don't criticise mine.
>>solution presented in this article totally unnecessary You've TOTALLY missed the point of the article, which is to get the diagram into a "text" format so it can be added to Visual SourceSafe and 'reapplied' to the database as part of a Continuous Integration setup.
What is Continuous Integration you are probably asking? Well do a quick Google, but basically our Build Server recreates our entire application from 'source', compiles, seeds data, runs unit tests, reports results and code coverage -- on "every" check-in. Because the database schema lives in SourceSafe along with the code, we can re-create the entire application (including database schema, AND DIAGRAMS) from any date/time or version label. Red-Gate's SQL Compare (or Microsoft's Team System for Database) both have tools to then 'sync' that schema to a production backup and we get an extremely flexible version control system with quite powerful branching & merging of both code AND schema; and we can load up the relevant database diagrams as well.
You CANNOT do that just transferring from one running instance to another.
Assuming you now "get it", I will try and explain how to use it.
1) apply the SQL to your database to create the Tool_VarbinaryToVarcharHex.udf and Tool_ScriptDiagram2005.prc. Be sure to apply to your application database and not master or one of the other system DBs (common mistake).
2) pick a diagram that you wish to persist to disk as text. I used a diagram called All Tables in my example above, but since that confused you let's say there is a diagram called CustomerSchemaDiag in our database
3) run the stored procedure like this:
exec Tool_ScriptDiagram2005 'CustomerSchemaDiag'
4) in the OUTPUT window of Management Studio (ie. the bottom part), you will see generated SQL commands (which is the output from Tool_ScriptDiagram2005). These SQL commands, if you examine them closely, do the job of re-creating a database diagram in sysdiagrams. It is this text output that you SAVE TO DISK for later use.
To be clear - you save the result of the ScriptDiagram stored procedure for later use. You can put it in SourceSafe or whatever you like. It is a complete snapshot of that database diagram for that schema.
5) to RELOAD that diagram (to a backup, another copy, wherever), you simply open those SQL commands into Management Studio and RUN THEM AS A QUERY (ie. in the top part of Mgmt Studio). All the binary data that was saved as 'text' is reloaded into sysdiagrams and can then be opened and viewed as a diagram.
Hope that helps.
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
Thanks it really help me, i have to pass my diagrams 2005 like 30 to 5 diferent databases, thanks a lot!!!, very handy. 
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
This is one of those great things that is missing in all the SQL server releases. Unfortunately I am having some problems with it.
I am using SQL Server 2005, had a diagram on my database and added the function and stored procedure as shown in this article.
Since the diagram was already present a week ago, at that time SQL Server had already added the necessary objects to support diagrams.
There are a few problems:
1. The tool XmL document says the name parameter is DatabaseName when it is actually DiagramName 2. The tool apparently recreates the diagram using a date suffix appended to the original name of the diagram. 3. Ran the tool to generate the diagram script. 4. Ran the diagram creation script generated by running the Tool (in #3)
Here I noticed two anomalies:
a) Even though the database already has a diagram and therefore the necessary objects to support diagrams, the tools says "Created sysdiagrams table because it did not exist" ?! that is wrong because SQL Server 2005 had ALREADY done that when I had created the diagram in that same database.
b) I did a refresh and the diagrams folder was still only showing the original diagram. There was no new diagram with a suffix.
http://www.PanamaSights.com/ http://www.coralys.com/ http://www.virtual-aviation.info/
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
Firstly, 1. Yes, other posters have noted that the article is misleading, sorry about that but most people usually figure it out pretty quickly.
As for your other questions, as with all CodeProject articles the code is included, so feel free to have a look at how it works. I would also take the time to read through the other comments, as some readers have offered improved code.
To answer:
a) Regarding your first 'anomoly' - the code is very simple in this respect, it does
IF NOT EXISTS ( SELECT * FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'sysdiagrams' ) before creating the table again, so I would encourage you to run that SELECT and see the result. I would advise double-checking which database you are running the code in: for example check you are not using master (which definitely won't have sysdiagrams). You said "is wrong because SQL Server 2005 had ALREADY done that" which suggests to me that you're pointing to a different database to what you think. Perhaps you can post the result if you find that this line of T-SQL doesn't work on your system.
b) To check the script will work to insert a new diagram, verify: - you are running it against the correct database (ie. not master,msdb,tempdb,etc) - the generated script has lots of UPDATE sysdiagrams SET [definition] .Write ( 0xD0CF11E0A1...0, null, 0) WHERE diagram_id = @newid rows in it. If these are not present, there has been an error generating the script in the first place. - Run SELECT * FROM sysdiagrams in your database before and after applying the diagram to ensure a new row has been inserted. - Post a copy of all the output messages if you need further assistance: the code does its best to provide meaningful errors to help debug it.
If you work in IT at all you would be aware that when reporting a bug, providing as much technical detail as possible usually helps to fix it. By posting a message with no specific information titled [Does not work] you are merely confusing other potential readers/users of this code. Many people are using it successfully for very large SQL 2005 (and 2008) databases, so I'm confident that with a bit more information about your situation it will be possible to get it working.
Look forward to reading more information about the problem.
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
As I was refreshing the dev / test database from Prod, I kept losing the diagrams & comments. So created a new database (<dbname_diagrams),>
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
Hi,
First of all thank you Craig. I just prepared stored procedure for scripting multiple diagrams. The procedure uses your procedures. If somebody needs it here it is:
IF EXISTS (SELECT * FROM INFORMATION_SCHEMA.ROUTINES WHERE ROUTINE_NAME = 'Tool_ScriptDiagrams2005') BEGIN DROP PROCEDURE dbo.Tool_ScriptDiagrams2005 END GO create procedure dbo.Tool_ScriptDiagrams2005 as begin declare @CurrentPosition int; declare @DiagramName nvarchar(128); select @CurrentPosition = min(diagram_id) from dbo.sysdiagrams; while (@CurrentPosition is not null) begin select @DiagramName = name from dbo.sysdiagrams where diagram_id = @CurrentPosition; exec Tool_ScriptDiagram2005 @DiagramName; print 'GO' select @CurrentPosition = min(diagram_id) from dbo.sysdiagrams where diagram_id > @CurrentPosition; end end GO
Voislav
modified on Tuesday, April 22, 2008 6:01 PM
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
 |
|
|
Thanks for the tool - it's great. To significantly improve performance when installing the diagrams, we set the chunk size to 1024 (so that there's a lot fewer UPDATE statements). (Prior to this change we also wrapped the UPDATE statements within a transaction, but with the new chunk size in place, the performance benefits of using a transaction is minimal.) ~10 diagrams now install in ~1 second instead of ~30 seconds. I would be interested to hear of any confirmations or issues with this change.
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
Good point briancoll,
I originally set the 'chunk size' very small simply for ease of build/testing - made the output easier to read. It also made it possible to show complete statements in the article, eg. 0xD0CF11E0A1B11AE1 was preferable to a very long hex string.
Never really thought much about performance though - the way I use these scripts is mostly via automated NAnt builds and therefore I don't really notice any speed issues.
Something I'd be interested in testing, although may not get to it straight away (busy with geoquery[^]!). Can't think why it would cause any problems...
Thanks Craig
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
Seems like a neet tool but I got some strange results after using the tool to script and restore a diagram from one database to another.
When running the restore diagram script it seems to work fine - no errors or anything. But when I try to look at the new diagram it displays the diagram of one of my old ones. And now all diagrams in the target database displays only that diagram.
If I do a select from the sysdiagrams table I get the following result:
name principal_id diagram_id version definition --------------------------- ------------ ----------- ----------- ---------------------------------- Import_tables 5 1 1 0xD0CF11E0A1B11AE10000000000000...[same string as TSWD] TSWD 5 1 1 0xD0CF11E0A1B11AE10000000000000...[same string as Import_tables] Freeze 2008-01-25 10:19 5 1 1 0x
Seems a bit strange that all diagrams got the same id.
The imported diagram was the "Freeze 2008-01-25 10:19". The diagram showing up on all entries are the "TSWD" diagram.
Any ideas on what might have went wrong here?
Thankyou /Henrik
modified on Friday, January 25, 2008 4:45:28 AM
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
Hi Henrik,
Since the diagramming script always creates it's entries with the DATETIME appended, I assume "Freeze 2008-01-25 10:19" is the only 'scripted' diagram and the other two were drawn.
Since the [definition] of "Freeze 2008-01-25 10:19" appears to be HEX NULL (ie 0x) I'm guessing that the script itself didn't insert any data. When you generated the script, which diagram was the 'source'?
exec Tool_ScriptDiagram2005 '[what was here?]'
You could also check to confirm that there were lots of update statements in the script, like this (HEX will differ, of course)
UPDATE sysdiagrams SET [definition] .Write ( 0xD0CF11E0A1B11AE1, null, 0) WHERE diagram_id
It's difficult to do any diagnosis beyond that without further info. I've been using this script for a number of years now on quite large corporate databases without any problems (which isn't to say I'm missing an error case, just that I'm not aware of it yet).
Regards Craig
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
Hi Craig,
thanks for your answer. Your assumptions are correct but there are a lot of update-rows. I dont know if this is of any help but here is how the script looks like (see below). (I cut out a lot of the update rows but you cant run the script anyhow right since you would need all tables and relations in place in the database to be able to run it.
I havent had time to test it again but I will in the comming week so maybe it will work better next time.
Thankyou Henrik
--How I created the script: exec Tool_ScriptDiagram2005 'Freeze'
--The constructed script: /** <summary> Restore diagram 'Freeze' </summary> <remarks> Generated by Tool_ScriptDiagram2005/Tool_VarbinaryToVarcharHex Will attempt to create [sysdiagrams] table if it doesn't already exist </remarks> <generated>2008-01-25 10:19</generated> */ PRINT '=== Tool_ScriptDiagram2005 restore diagram [Freeze] ===' -- If the sysdiagrams table has not been created in this database, create it! IF NOT EXISTS (SELECT * FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'sysdiagrams') BEGIN -- Create table script generated by Sql Server Management Studio -- _Assume_ this is roughly equivalent to what Sql Server/Management Studio -- creates the first time you add a diagram to a 2005 database CREATE TABLE [dbo].[sysdiagrams]( [name] [sysname] NOT NULL, [principal_id] [int] NOT NULL, [diagram_id] [int] IDENTITY(1,1) NOT NULL, [version] [int] NULL, [definition] [varbinary](max) NULL, PRIMARY KEY CLUSTERED ( [diagram_id] ASC )WITH (PAD_INDEX = OFF, IGNORE_DUP_KEY = OFF) , CONSTRAINT [UK_principal_name] UNIQUE NONCLUSTERED ( [principal_id] ASC, [name] ASC )WITH (PAD_INDEX = OFF, IGNORE_DUP_KEY = OFF) ) EXEC sys.sp_addextendedproperty @name=N'microsoft_database_tools_support', @value=1 , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'sysdiagrams' PRINT '[sysdiagrams] table was created as it did not already exist' END -- Target table will now exist, if it didn't before SET NOCOUNT ON -- Hide (1 row affected) messages DECLARE @newid INT DECLARE @DiagramSuffix varchar (50) PRINT 'Suffix diagram name with date, to ensure uniqueness' SET @DiagramSuffix = ' ' + LEFT(CONVERT(VARCHAR(23), GETDATE(), 121), 16) PRINT 'Create row for new diagram' BEGIN TRY PRINT 'Write diagram Freeze into new row (and get [diagram_id])' INSERT INTO sysdiagrams ([name], [principal_id], [version], [definition]) VALUES ('Freeze'+@DiagramSuffix, 5, 1, 0x) SET @newid = SCOPE_IDENTITY() END TRY BEGIN CATCH PRINT 'XxXxX ' + Error_Message() + ' XxXxX' PRINT 'XxXxX END Tool_ScriptDiagram2005 - fix the error before running again XxXxX' RETURN END CATCH PRINT 'Now add all the binary data...' BEGIN TRY UPDATE sysdiagrams SET [definition] .Write ( 0xD0CF11E0A1B11AE1000000000000000000000000000000003E000300FEFF0900, null, 0) WHERE diagram_id = @newid -- index:1 UPDATE sysdiagrams SET [definition] .Write ( 0x060000000000000000000000010000000100000000000000001000002E000000, null, 0) WHERE diagram_id = @newid -- index:33 UPDATE sysdiagrams SET [definition] .Write ( 0x01000000FEFFFFFF0000000000000000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF, null, 0) WHERE diagram_id = @newid -- index:65 UPDATE sysdiagrams SET [definition] .Write ( 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF, null, 0) WHERE diagram_id =
...
@newid -- index:449 UPDATE sysdiagrams SET [definition] .Write ( 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF, null, 0) WHERE diagram_id = @newid -- index:481 UPDATE sysdiagrams SET [definition] .Write ( 0xFDFFFFFF30000000030000000400000005000000060000000700000008000000, null, 0) WHERE diagram_id = @newid -- index:513 UPDATE sysdiagrams SET [definition] .Write ( 0x090000000A0000000B0000000C0000000D000000FEFFFFFF0F00000010000000, null, 0) WHERE diagram_id =
...
@newid -- index:2945 UPDATE sysdiagrams SET [definition] .Write ( 0x726F64756374436F6E6365707450726F63657373270000002800B50100000700, null, 0) WHERE diagram_id = @newid -- index:2977 UPDATE sysdiagrams SET [definition] .Write ( 0x008012000000310000007D00000002800000436F6E74726F6C65AD3B0000A5A0, null, 0) WHERE diagram_id = @newid -- index:3009 UPDATE sysdiagrams SET [definition] .Write ( 0x00000000A000A509000007000080130000006A0000000180000077000080436F, null, 0) WHERE diagram_id =
...
@newid -- index:39809 UPDATE sysdiagrams SET [definition] .Write ( 0xF310000008070000000000009E070000F31000009E0700000000000034080000, null, 0) WHERE diagram_id = @newid -- index:39841 UPDATE sysdiagrams SET [definition] .Write ( 0xF31000003408000000000000CA080000F3100000CA0800000000000060090000, null, 0) WHERE diagram_id = @newid -- index:39873 UPDATE sysdiagrams SET [definition] .Write ( 0xF31000006009000000000000F6090000F3100000F6090000000000008C0A0000, null, 0) WHERE diagram_id = @newid -- index:39905 UPDATE sysdiagrams SET [definition] .Write ( 0x62885214, null, 0) WHERE diagram_id = @newid -- index:39937 PRINT '=== Finished writing diagram id ' + CAST(@newid AS VARCHAR(100)) + ' ===' PRINT '=== Refresh your Databases-[DbName]-Database Diagrams to see the new diagram ===' END TRY BEGIN CATCH -- If we got here, the [definition] updates didn't complete, so delete the diagram row -- (and hope it doesn't fail!) DELETE FROM sysdiagrams WHERE diagram_id = @newid PRINT 'XxXxX ' + Error_Message() + ' XxXxX' PRINT 'XxXxX END Tool_ScriptDiagram2005 - fix the error before running again XxXxX' RETURN END CATCH
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
Just tested it in SQL Server 2008 (Katmai) November 2007 CTP, and seems to work just fine. Haven't tested 'applying' 2005 diagrams to 2008 (or vice versa) yet, but I expect it should work just fine...
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
Hi,
I have carried out the instructions, although this is giving me:
/** Diagram name [All Tables] could not be found. */
Any thoughts on what I am not doing right?
THANK YOU
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
For anyone who's interested, I've just been able to test this script in a beta of SQL Server 2008 (codename "katmai"). Seems to work without any problems: * Generating and then applying diagram scripts within Sql2008 works fine; and * I was able to 'apply' a diagram script generated in Sql2005 to a Sql2008 database, and vice versa.
My guess is the diagramming 'bit' of SQL Server hasn't been updated at all between 2005 and 2008... unless there's something else in the beta that I haven't seen yet.
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
 |
|
|
 |
|
|
 |
|
|
Thank you so much for making the changes for SQL 2005. I still get emails asking for the code, and often they want a 2005 version... but I don't have a 2005 environment( ), so I haven't yet been able to port it.
Thank you very much for citing me as the original source!

-Clay
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
Hi Clay,
It's amazing there is nothing else on the web to solve this problem. I have evangelized your code at a number of places that I've worked since I discovered it on the web. It definitely makes continuous integration of databases easier, I can't believe MS didn't put something in Visual Studio for Database Professionals!
Although the SQL 2005 T-SQL I wrote is quite different to yours -- due to the much simpler diagram table and new varbinary(max) datatype -- there is no way I would have tackled it at all without the work you already did, so thanks again!
Glad that you found it and said 'hi'.
Best regards Craig
p.s. I'm still trying to figure out how to upgrade diagrams from 2000 to 2005... I can successfully get the binary data into the new INSERT format, but SQL 2005 reports the diagram is 'corrupted'. If you have any thoughts I'd love to hear them.
|
| Sign In·View Thread·PermaLink | 2.00/5 (1 vote) |
|
|
|
 |
|
|
I want to thank both of you for the work you put into this. I found it quickly when searching for a way to do this and it worked flawlessly the first time. There is no telling how much time this saved me.
Thanks, Brian
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
| | |