use tsql to detect XML dependency
i have a XML schema bound to a table. however, sometimes testers piggyback and bind to this schema too. when there is this "ninja" XML table 开发者_开发百科reference, any alteration to this schema is painful.
i'd like to run a query before schema altering and raise exception if the XML schema is bound to more than one table. i've looked at sys.sql_dependencies and few of the other sys.xml_XXXX tables, but it's not clear how to do this in tsql. is something like this possible?
Something like this might be helpful
select object_name(object_id) as TableName,
col_name(object_id, column_id) as ColumnName
from sys.column_xml_schema_collection_usages as U
inner join sys.xml_schema_collections as S
on U.xml_collection_id = S.xml_collection_id
where S.name = 'YourXMLSchemaCollectionName'
This one is to find where the schema is used in a XML parameter.
select object_name(object_id)
from sys.parameter_xml_schema_collection_usages as P
inner join sys.xml_schema_collections as S
on P.xml_collection_id = S.xml_collection_id
where S.name = 'YourXMLSchemaCollectionName'
精彩评论