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

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, expand Databases, expand your database, and then expand User defined data types.
  3. In the right pane, right-click the data type you want, and then click All Tasks.
  4. Click Generate SQL Script, and then click OK.
  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 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.

  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 change mytable..mycolumn to the datetimebase 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.

转载于:https://www.cnblogs.com/MaxWoods/archive/2011/08/31/2160722.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值