我创建了一个表:用默认约束删除列
create table userTable
(
userId int identity(1,1) not null,
userName nvarchar(20) not null,
joinDate datetime not null default getdate()
constraint pk_userTable primary key(userId) on [primary]
)
然后我试图删除列joinDate:
alter table userTable drop column joinDate
但我得到的错误:
Msg 5074, Level 16, State 1, Line 1
The object 'DF_userTable_joinD_31EC6D26' is dependent on column 'joinDate'.
Msg 4922, Level 16, State 9, Line 1
ALTER TABLE DROP COLUMN joinDate failed because one or more objects access this column.
这是为什么呢?
另外,我想插入新行时,只输入用户名列中指定的值,但是当我尝试这样做:
INSERT userTable SELECT 'name1';
我得到的错误信息:
Msg 213, Level 16, State 1, Line 1
Column name or number of supplied values does not match table definition.
为什么我得到这个错误?
你想删除joinDate,但你仍然想使用它?这没有意义。另外,如果只插入一个userName,那么你有一个默认值getdata(),它将填充joinDate字段。 –