修改属性成功却不能删除COLUMN
我对market数据库做如下动作新建3个表分别是customers,goods,orders:
use market;
create table Customers(CustomerID int IDENTITY (1,1) PRIMARY KEY ,FirstName varchar(20) NOT NULL ,LastName varchar
(20) NOT NULL , Address varchar(100) , City varchar(20) ,Tel varchar(20) UNIQUE , Company varchar(50), Birthday
datetime ,Type tinyint DEFAULT 1 );
CREATE TABLE Goods(Name varchar(20) CONSTRAINT PK_GOODSNAME PRIMARY KEY , Description varchar(200), Storage int,
Supplier varchar(50) , Status tinyint DEFAULT(0) , Price money)
CREATE TABLE Orders(OrderID int identity(1,1) constraint PK_ORDERID PRIMARY KEY , GoodName varchar(20) not null
references Goods(Name) on delete cascade , CustomerID int not null foreign key (CustomerID) references Customers
(CustomerID) on delete no action , quantity int not null constraint CK_QUANTITY CHECK(QUANTITY > 0), OrderSum money
not null , OrderDate datetime default (GetDate())); 提示成功!
然后再对Customers表添加一个EmailAddress列
alter table customers add EmailAddress varchar(50) null constraint CK_EA CHECK (EmailAddress like '%@% ') 提示成功!
我再取消它的检查约束
alter table customers nocheck constraint CK_EA; 提示成功!
最后我来删除EmailAddress列:
alter table customers drop column EmailAddress;
却提示:
服务器: 消息 5074,级别 16,状态 6,行 1
对象 'CK_EA ' 依赖于 列 'EmailAddress '。
服务器: 消息 4922,级别 16,状态 1,行 1
ALTER TABLE DROP COLUMN EmailAddress 失败,因为有一个或多个对象访问此列。
这要怎么才能删除column啊?帮帮我这个菜鸟吧!
------解决方案--------------------alter table customers nocheck constraint CK_EA
====改为
alter table customers drop constraint CK_EA
------解决方案--------------------alter table customers drop constraint CK_EA 再删除