sql - Find all ERDs containing table with specified name -
is possible can query names of erds (entity relationship diagram) contain table name
like '%mytable%'
something this:
select * <erd objects> tablename '%%'
actually, have large database
lots of erds
. so, understand scope of table want browse erds
of specific table.
as understand need list of tables contained in database diagrams. there can article. add part of here:
the diagram stored in binary field. , can not convert readable form without difficulties. deserializing field (called definition
) need 2 functions:
create function [dbo].[tool_varbinarytovarchar_text] ( @varbinaryvalue varbinary(max), @bitasciionly bit = 0 ) returns varchar(max) begin declare @numberofbytes int set @numberofbytes = datalength(@varbinaryvalue) -- part 1 -- if (@numberofbytes > 4) begin declare @firsthalfnumberofbytes int declare @secondhalfnumberofbytes int set @firsthalfnumberofbytes = @numberofbytes/2 set @secondhalfnumberofbytes = @numberofbytes - @firsthalfnumberofbytes -- call function recursively 2 parts of input split in half return dbo.tool_varbinarytovarchar_text(cast(substring(@varbinaryvalue, 1 , @firsthalfnumberofbytes) varbinary(max)),@bitasciionly) + dbo.tool_varbinarytovarchar_text(cast(substring(@varbinaryvalue, @firsthalfnumberofbytes+1 , @secondhalfnumberofbytes) varbinary(max)),@bitasciionly) end if (@numberofbytes = 0) begin return '' -- no bytes found, therefore no 'hex string' returned end -- part 2 -- declare @highbyte int -- @numberofbytes <= 4 (four or less characters/8 hex digits input) -- eg. 88887777 66665555 44443333 22221111 -- we'll process right-most (least-significant) byte, consists -- of 8 bits -- 2. carve off rightmost 8 bits/single hex digit (ie 22221111) -- divide 16 shift-left (now processing 2222) set @highbyte = cast(@varbinaryvalue int) & 255 if @bitasciionly = 1 , (@highbyte < 32 or @highbyte > 126) set @highbyte=13; -- 3. trim byte (two hex values) right (least significant) input binary -- in preparation further parsing set @varbinaryvalue = substring(@varbinaryvalue, 1, (@numberofbytes-1)) -- 4. recursively call method on remaining binary data, concatenating text -- 'value' decoded ascii character representation -- ie. pass 88887777 66665555 44443333 function, adding x result string return dbo.tool_varbinarytovarchar_text(@varbinaryvalue,@bitasciionly) + char(@highbyte) end
and:
create function [dbo].[fntool_scriptdiagram2005_text]() returns @tblout table ( -- add column definitions table variable here diagramname nvarchar(128), diagram_id int primary key, diagram_text varchar(max), diagram_ascii varchar(max) ) begin declare @name nvarchar(128); declare @diagram_id int; declare @index int; declare @size int; declare @chunk int; declare @line varchar(max); declare @lineasc varchar(max); declare @currentpos int; select @currentpos = min(diagram_id) dbo.sysdiagrams; while (@currentpos not null) begin -- set start index, , chunk 'constant' value set @index = 1; -- set @chunk = 32; -- values work: 2, 6 -- values fail: 15,16, 64 select @diagram_id = diagram_id, @size = datalength(definition), @name = name dbo.sysdiagrams diagram_id = @currentpos; -- diagram_id, work set @line = ''; set @lineasc = ''; while @index < @size begin -- output many update statements required append diagram binary -- data, represented hexadecimal strings select @line = @line + dbo.tool_varbinarytovarchar_text(substring (definition, @index, @chunk),0), @lineasc = @lineasc + dbo.tool_varbinarytovarchar_text(substring (definition, @index, @chunk),1) dbo.sysdiagrams diagram_id = @currentpos; set @index = @index + @chunk; end insert @tblout (diagramname, diagram_id, diagram_text, diagram_ascii) values (@name, @diagram_id, @line, replace(@lineasc,char(13),'')); select @currentpos = min(diagram_id) dbo.sysdiagrams diagram_id > @currentpos; end return; end
after can run:
select * [dbo].[fntool_scriptdiagram2005_text] () diagram_ascii '%tabletofind%'
for example have created diagram testdiagram
2 tables named whatever
, ie_stat
. in return query:
root entrypfobcompobj_ !"#$%&'()*+,-.123456789:(}5n]4o[\0v?[?i???v?[?i??t,,,4") -bh''uu94941#xv4xdboie_statmicrosoft dds form 2.0embedded object9q&sch_labels_visibled(activetableviewmode1 tableviewmode:0:4,0,28ddsstreamschema udv default&/dsref-schema-contents,0schema udv default post v66;4,0,2310,1,1890,5,1260 tableviewmode:12,0,284,0,2805 tableviewmode:22,0,284,0,2310 tableviewmode:32,0,284,0,2310 tableviewmode:4>4,0,284,0,2310,12,2730,11,1680(activetableviewmode1 tableviewmode:0:4,0,284,0,2310,1,1890,5,1260 tableviewmode:12,0,284,0,2805 tableviewmode:22,0,284,0,2310 tableviewmode:32,0,284,0,2310 tableviewmode:4>4,0,284,0,2310,12,2730,11,1680naqw9 lhedata source=********;initial catalog=test;integrated security=true;multipleactiveresultsets=false;trustservercertificate=true;packet size=4096;application name="microsoft sql server management studio"testdiagram&whateverdbo$ie_statdboke7d2pn{1634cdd7-0888-42e3-9fa2-b6d32563b91d}br
you can see both table names.
Comments
Post a Comment