34,838
社区成员




select
[约束名]=a.Name,
[默认值]=b.text
from
sysobjects a
join
syscomments b on a.ID=b.ID
where parent_obj=object_id('abc') and xtype='D'
create table abc
(
name varchar(3) not null,
id int not null,
age int not null,
dt datetime not null CONSTRAINT AddDateDflt default(getdate())
)
go
insert abc(name,id,age) select 'asd',1,10
select * from abc
ALTER TABLE abc drop constraint AddDateDflt
insert abc(name,id,age,dt) select 'asf',1,10,'2007-12-22'
select * from abc
drop table abc
/*
(所影响的行数为 1 行)
name id age dt
---- ----------- ----------- ------------------------------------------------------
asd 1 10 2007-12-23 22:31:01.237
(所影响的行数为 1 行)
(所影响的行数为 1 行)
name id age dt
---- ----------- ----------- ------------------------------------------------------
asd 1 10 2007-12-23 22:31:01.237
asf 1 10 2007-12-22 00:00:00.000
(所影响的行数为 2 行)
*/
create table T(ID int default (1))
--
select
[约束名]=a.Name
[默认值]=b.text
from
sysobjects a
join
syscomments b on a.ID=b.ID
where parent_obj=object_id('T') and xtype='D'
--
alter table T drop constraint 约束名