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

來源:互聯網
上載者: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, 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 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 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.
相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.