How to: Change the owner of a user-defined data type that is in use in SQL Server 2000

Source: Internet
Author: User

This article describes how to change the owner of a user-defined data type that
Is in use.

To change the owner of a user-defined data type, you must drop
And then re-create the data type in the context of the owner you want. However,
If the user-defined data type is in use, you will receive the following error
Message when you try to drop the Data Type:

Server: MSG 15180, level 16, state 1, procedure sp_droptype,
Line 32 cannot drop. The data type is being used. Steps to change the owner of a user-defined data type that is
In use

To change the owner of a user-defined data type that is in use, follow these
Steps:

  1. Script out the definition of the User-Defined data type with SQL Server
    Enterprise Manager (SEM ).
  2. Expand your SQL Server, expandDatabases, Expand your database, and
    Then expandUser Defined Data Types.
  3. In the right pane, right-click the data type you want, and then clickAll
    Tasks
    .
  4. ClickGenerate SQL script, And then clickOK.
  5. Select the file name and location in which you will store the script.
  6. Determine all the tables or columns that are using the user-defined data
    Type by using the following code (replace the Database Name and data type
    Your Database Name and data type ):

    Use Database nameselect table_catalog, table_name, column_name, domain_namefrom information_schema.columnswhere domain_name = 'data type'

    Note: In this context, domain_name
    Represents the user-defined data type.

  7. For each table that is using the user-defined data type, change the column
    Data type to the base data type by using an alter table statement. For example
    To changeMytable... mycolumnToDatetimeBase data type, use:

    Alter table mytable alter column mycolumn datetime
  8. Drop the user-defined data type.
  9. Re-create the user-defined data type by using the script you saved in Step 4
    Under the context of the owner you want.
  10. Change all the columns you want back to the user-defined data type by using
    An alter table statement as in Step 7.
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.