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:
-
- Script out the definition of the User-Defined data type with SQL Server
Enterprise Manager (SEM ).
- Expand your SQL Server, expandDatabases, Expand your database, and
Then expandUser Defined Data Types.
-
- In the right pane, right-click the data type you want, and then clickAll
Tasks.
-
- ClickGenerate SQL script, And then clickOK.
-
- 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
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.
- 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
-
- Drop the user-defined data type.
-
- Re-create the user-defined data type by using the script you saved in Step 4
Under the context of the owner you want.
-
- Change all the columns you want back to the user-defined data type by using
An alter table statement as in Step 7.