2.ms_sql数据库表默认值使用

use test002

go

--判断是否存在表和默认值对象 如果存在删除

if object_id('table_6_4') is not null drop table table_6_4

if object_id('abc_const') is not null drop default abc_const go

--创建表

create table table_6_4

 ( keycol int primary key,

process_id smallint default @@spid,

date_ins datetime default getdate(),

 mathcol smallint default 10*2,

 char1 char(3),

 char2 char(3) default 'xyz' )

 go

--创建默认值对象

create default abc_const as 'abc'

go

--绑定默认值

sp_bindefault abc_const ,'table_6_4.char1';

go

--插入数据

insert into table_6_4(keycol)values(2);

go

select *from table_6_4

posted @ 2012-01-09 15:38  superkook  阅读(196)  评论(0)    收藏  举报