求一个SQL字段默认值
编号 日期 总分
1 100
2 100
3 100
求日期字段默认值为 系统日期时间 格式是 2005-1-1
不需要 具体时间只要2005-1-1着样的格式
日期字段数据类型是 datetime
谢谢啦。
问题点数:20、回复次数:5Top
1 楼jxufewbt(我的目标是5星)回复于 2005-11-16 18:02:11 得分 0
getdate()Top
2 楼bitliuyang(昊天)回复于 2005-11-16 18:08:39 得分 10
把下面的放在默认值里面就是你要的效果:
(convert(datetime,(datename(year,getdate()) + '-' + datename(month,getdate()) + '-' + datename(day,getdate()))))Top
3 楼zlp321002(Life Is Good,Let's Shine)回复于 2005-11-16 18:17:18 得分 5
Update
表
set
日期=convert(varchar(10),Getdate(),120)Top
4 楼yclin2005(ychao)回复于 2005-11-16 18:20:16 得分 5
convert(smalldatetime,convert(varchar(10),getdate(),100))Top
5 楼zlp321002(Life Is Good,Let's Shine)回复于 2005-11-16 18:22:12 得分 0
--或者
Create table #
(
编号 int identity(1,1),
日期 varchar(10) default(Convert(varchar(10),Getdate(),120)),
总分 int
)
--插入语句
insert into #(总分) select 200
--查看结果
select * from #
编号 日期 总分
----------- ---------- -----------
1 2005-11-16 200
(所影响的行数为 1 行)
Top




