ALTER TABLE ALTER COLUMN“Present _Address”失败,因为一个或多个对象访问此列

时间:2014-02-21 06:26:26

标签: sql-server

我有一个数据库,我必须将所有varchar数据类型列转换为nvarchar类型。我已经能够转换除一个表之外的所有表。在转换为nvarchar数据类型之前,我将删除所有约束,如外键,主键,唯一键,检查约束,默认约束和索引。在更改为nvarchar之前,我也删除了所有数据。

问题是我收到了错误

  

ALTER TABLE ALTER COLUMN“永久地址”失败,因为一个或多个对象访问此列。

当我执行drop和create table语句时,它正在那里工作但是在用nvarchar命令转换为ALTER时我收到了错误

我有以下脚本

- 实际的表格定义

USE [Customer]
GO
--Permanent_Address is a computed column
CREATE TABLE [dbo].[Customer_Contact](
    [Customer_id] int NOT NULL,
    [Present_Address] [varchar](250) NOT NULL,
    [Permanent_Address]  AS ([Present_Address]))

    --Alter statement to convert from varchar to nvarchar

ALTER TABLE [Customer_Contact] ALTER COLUMN [Present Address] NVARCHAR(250) NOT NULL
ALTER TABLE [Customer_Contact] ALTER COLUMN [Permanent_Address] NVARCHAR(250) NOT NULL

结果 - :ALTER TABLE ALTER COLUMN“永久地址”失败,因为一个或多个对象访问此列。

--Drop and Create the table script


IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[Customer_Contact]') AND type in (N'U'))
DROP TABLE [dbo].[Customer_Contact]
GO

SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

CREATE TABLE [dbo].[Customer_Contact](
    [Customer_id] int NOT NULL,
    [Present_Address] [Nvarchar](250) NOT NULL,
    [Permanent_Address]  AS ([Present_Address]))

--The table is created successfully with Nvarchar Datatype

0 个答案:

没有答案
相关问题