1.如果是create 表的时候则可以直接给这字段加一缺省值,如 create table test(a varchar(20) default '1900年1月1日') 2.如果是表添加字段也可以为这个字段加一缺省值,并且如果表中存在记录时用with values强制加这个值 create table test(a int) insert test select 1 go alter table test add b varchar(20) default '1900年1月1日' with values 3.如果表存在,还可以创建一个缺省create default ,用sp_bindefault绑定到这个字段上 create table test(a varchar(20)) go create default d_test as '1900年1月1日' go sp_bindefault 'd_test','test.a'
--建表时自己添加一个缺省值。 -------------------------------- create table test ( a datetime constraint jfsd default '1900-01-01', b int constraint jfs default 1 ) --插入语句------------------------------ insert into test(b) values(2) --数据结果------------------------------- a b ----------------- ----------- 1900-01-01 00:00:00.000 2
create table test(a varchar(20) default '1900年1月1日')
2.如果是表添加字段也可以为这个字段加一缺省值,并且如果表中存在记录时用with values强制加这个值
create table test(a int)
insert test select 1
go
alter table test add b varchar(20) default '1900年1月1日' with values
3.如果表存在,还可以创建一个缺省create default ,用sp_bindefault绑定到这个字段上
create table test(a varchar(20))
go
create default d_test as '1900年1月1日'
go
sp_bindefault 'd_test','test.a'
--建表时自己添加一个缺省值。
--------------------------------
create table test
(
a datetime constraint jfsd default '1900-01-01',
b int constraint jfs default 1
)
--插入语句------------------------------
insert into test(b) values(2)
--数据结果-------------------------------
a b
----------------- -----------
1900-01-01 00:00:00.000 2
DateTime.MinValue => 0001/01/01 00:00:00
SqlDateTime.MinValue.Value => 1753/01/01 00:00:00
SQL Server 2005 中,
DateTime 最小值 => 1753/01/01 00:00:00
SmallDateTime 最小值 => 1900/01/01 00:00:00
.Net Framewrok 中,
DateTime.MaxValue => 9999/12/31 23:59:59.999
SqlDateTime.MaxValue.Value => 9999/12/31 23:59:59.997
SQL Server 2005 中,
DateTime 最大值 => 9999/12/31 23:59:59.997