Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 663075
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T23:26:59+00:00 2026-05-13T23:26:59+00:00

SQL Server XML Schema Collection is an interesting concept and I find it very

  • 0

SQL Server XML Schema Collection is an interesting concept and I find it very useful when designing dynamic data content. However as I work my way through implementing Schema Collections, I find it very difficult to maintain them.

Schema Collection DDL allows only CREATE and ALTER/ADD nodes to existing schemes.

CREATE XML SCHEMA COLLECTION [ <relational_schema>. ]sql_identifier AS 'XSD Content'
ALTER XML SCHEMA COLLECTION [ <relational_schema>. ]sql_identifier ADD 'Schema Component'

When you want to remove any node from a schema you have to issue following DDL’s.

  1. If that schema collection assigned to a table column, you have to alter table to remove schema collection association from that column
  2. Drop the schema collection object
  3. Re-Create schema collection
  4. Alter table column to re-associate schema collection to that column.

This is pain when it comes to 100+ of schemes in a collection. Also you have to re-create XML indexes all over again, if any.

Any solutions, suggestions, tricks to make this schema collection object editing process easier?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T23:26:59+00:00Added an answer on May 13, 2026 at 11:26 pm

    I agree with David that XML is not the panacea we were told it would be, but there are some situations where it is either unavoidable or the best tool for the job. Schema maintenance is painful though. I only have a couple to deal with and still lose hours.

    This script might help. It generates the table drops and adds you’ll need. It would need to mdified to include UDFs or other objects that might reference the XML schema. To generate the Add schema statements, I suggest you use the “Generate Scripts…” function in the tasks menu in Mgt Studio and save them off for Step 2 of the script.

    SET NOCOUNT ON
    
    /* 
        1) Save cols to table var
    */
    DECLARE @xmlCols TABLE (
    numID INTEGER IDENTITY(1,1),
    TBL nvarchar(1024),
    COL nvarchar(1024),
    SCH nvarchar(1024)
    );
    
    insert into @xmlCols (TBL,COL,SCH)
    SELECT DISTINCT OBJECT_NAME(colm.object_id) AS 'TABLE', colm.name AS 'COLUMN', coll.name AS 'Schema' 
    FROM  sys.columns colm
       inner JOIN     sys.xml_schema_collections coll
            ON colm.xml_collection_id = coll.xml_collection_id
    ORDER BY OBJECT_NAME(colm.object_id), colm.name   
    
    DECLARE @lastRow as int
    DECLARE @currentRow as int
    DECLARE @dbName as varchar(1024)
    DECLARE @tableName as varchar(1024)
    DECLARE @colName as varchar(1024)
    DECLARE @schemaName as varchar(1024)
    SET @lastRow = @@ROWCOUNT
    SET @currentRow = @lastRow
    SET @dbName = 'dbNAme'
    
    print ''
    print '--!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!'
    print '--!!!!! Scipt Schemas and Save in Mgt Studio !!!!'
    print '--!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!'
    print ''
    
    
    print ''
    print '--!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!'
    print '--!!!!! Omit Schemas from COls !!!!'
    print '--!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!'
    print ''
    --omit the Schema for each column
    WHILE @currentRow <> 0
    BEGIN
        SELECT @tableName=TBL, @colName=COL, @schemaName=SCH from @xmlCols WHERE numID = @currentRow
    
        print N'ALTER TABLE [' + @tableName + N'] ALTER COLUMN ['+ @colName + N'] XML'
    
        set @currentRow = @currentRow -1
    END
    
    print ''
    print '--!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!'
    print '--!!!!! drop your xml schema(s)  !!!!'
    print '--!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!'
    print ''
    SET @currentRow = @lastRow
    WHILE @currentRow <> 0
    BEGIN
        SELECT @tableName=TBL, @colName=COL, @schemaName=SCH from @xmlCols WHERE numID = @currentRow
    
        print N'DROP XML SCHEMA COLLECTION [dbo].['+@schemaName+']'
    
        set @currentRow = @currentRow -1
    END
    
    print ''
    print '--!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!'
    print '--!!!!! CLean your Tables      !!!!'
    print '--!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!'
    print ''
    
    --clean up the tables
    SET @currentRow = @lastRow
    WHILE @currentRow <> 0
    BEGIN
        SELECT @tableName=TBL, @colName=COL, @schemaName=SCH from @xmlCols WHERE numID = @currentRow
    
        print N'DBCC CleanTable (''' + @dbName + N''', ''' + @tableName + N''', 0)'
    
        set @currentRow = @currentRow -1
    END
    
    print ''
    print '--!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!'
    print '--!!!!! Run XML Schema Scripts !!!!'
    print '--!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!'
    print ''
    SET @currentRow = @lastRow
    WHILE @currentRow <> 0
    BEGIN
        SELECT @tableName=TBL, @colName=COL, @schemaName=SCH from @xmlCols WHERE numID = @currentRow
    
        print N'ALTER TABLE [' + @tableName + N'] ALTER COLUMN ['+ @colName + N'] XML('+ @schemaName + N')'''
    
        set @currentRow = @currentRow -1
    END
    

    Hope it helps.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 426k
  • Answers 426k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Nice question. I never really thought twice about it. I… May 15, 2026 at 12:46 pm
  • Editorial Team
    Editorial Team added an answer That error message says you have not installed the async-http… May 15, 2026 at 12:46 pm
  • Editorial Team
    Editorial Team added an answer Is serialization safe in this case? No. As @Tom Hawtin… May 15, 2026 at 12:46 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.