为什么修改不了数据类型啊
我创建了一个表,但是ponum 定义的长度太短,想给他改长点,用以以下语句,可一直提示错误
ALTER TABLE purchase_order4 ALTER COLUMN ponum CHARACTER(10);
CREATE TABLE purchase_order4
(
ponum character(5) NOT NULL,
qty character(10),
orderdate date,
duedate date,
receiveddate date,
CONSTRAINT purchase_order4_pkey PRIMARY KEY (ponum)
)
[解决办法]
--查询约束
sp_helpconstraint purchase_order4
--删除约束
ALTER TABLE purchase_order4
drop constraint purchase_order4_pkey
ALTER TABLE purchase_order4 add constraint purchase_order4_pkey PRIMARY KEY(ponum)
CREATE TABLE purchase_order4
(
ponum character(5) NOT NULL,
qty character(10),
orderdate datetime,
duedate datetime,
receiveddate datetime,
CONSTRAINT purchase_order4_pkey PRIMARY KEY (ponum)
)
--改变前字符长度为5
/*
Column_name Type Computed Length Prec Scale Nullable TrimTrailingBlanks FixedLenNullInSource Collation
-------------------------------------------------------- -------------------------------------------------------- ----------------------------------- ----------- ----- ----- ----------------------------------- ----------------------------------- ----------------------------------- --------------------------------------------------------
ponum char no 5 no no no Chinese_PRC_CI_AS
qty char no 10 yes no yes Chinese_PRC_CI_AS
orderdate datetime no 8 yes (n/a) (n/a) NULL
duedate datetime no 8 yes (n/a) (n/a) NULL
receiveddate datetime no 8 yes (n/a) (n/a) NULL
*/
alter table purchase_order4
drop constraint purchase_order4_pkey
go
alter table purchase_order4
alter column ponum character(10) not null
go
alter table purchase_order4
add constraint purchase_order4_pkey primary key clustered (ponum)
--改变后字符长度为10
/*
Column_name Type Computed Length Prec Scale Nullable TrimTrailingBlanks FixedLenNullInSource Collation
-------------------------------------------------------- -------------------------------------------------------- ----------------------------------- ----------- ----- ----- ----------------------------------- ----------------------------------- ----------------------------------- --------------------------------------------------------
ponum char no 10 no no no Chinese_PRC_CI_AS
qty char no 10 yes no yes Chinese_PRC_CI_AS
orderdate datetime no 8 yes (n/a) (n/a) NULL
duedate datetime no 8 yes (n/a) (n/a) NULL
receiveddate datetime
*/
ALTER TABLE purchase_order4 DROP CONSTRAINT purchase_order4_pkey
GO
ALTER TABLE purchase_order4 ALTER COLUMN ponum character(10) not null
GO
ALTER TABLE purchase_order4 ADD CONSTRAINT purchase_order4_pkey PRIMARY KEY( ponum )