Microsoft KB Archive/327123

= HOW TO: Change the Owner of a User-Defined Data Type That Is in Use in SQL Server 2000 =

Article ID: 327123

Article Last Modified on 12/26/2003

-

APPLIES TO


 * Microsoft SQL Server 2000 Standard Edition
 * Microsoft SQL Server 2000 64-bit Edition

-



This article was previously published under Q327123



IN THIS TASK

 * SUMMARY
 * Steps to Change the Owner of a User-Defined Data Type That Is in Use
 * REFERENCES



SUMMARY
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.

back to the top

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:  Script out the definition of the user-defined data type with SQL Server Enterprise Manager (SEM). Expand your SQL Server, expand Databases, expand your database, and then expand User defined data types. In the right pane, right-click the data type you want, and then click All Tasks. Click Generate SQL Script, and then click OK. Select the file name and location in which you will store the script.  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 with your database name and data type): USE database name SELECT TABLE_CATALOG, TABLE_NAME, COLUMN_NAME, DOMAIN_NAME FROM INFORMATION_SCHEMA.COLUMNS WHERE DOMAIN_NAME = 'data type' NOTE: In this context, DOMAIN_NAME represents the user-defined data type.

  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 change mytable..mycolumn to the datetime base data type, use: ALTER TABLE mytable ALTER COLUMN mycolumn datetime </li> Drop the user-defined data type.</li> Re-create the user-defined data type by using the script you saved in step 4 under the context of the owner you want.</li> Change all the columns you want back to the user-defined data type by using an ALTER TABLE statement as in step 7.</li></ol>

back to the top

<div class="references_section">